Click here to Skip to main content
15,913,316 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
May i ask if anyone know how to compile a java file with a C++ file?
Thanks alot.
Posted

NO!

C++ and Java are DIFFERENT languages! DO NOT MIX IT!
It's like a vegetarian meal with bacon on top.
A nice piece of chocolate cake with ketchup or
a white shirt that got pink while washing.

DO NOT TRY THIS!
 
Share this answer
 
Comments
Richard MacCutchan 5-Aug-11 6:20am    
I like vegetarian meals with bacon!
Sergey Alexandrovich Kryukov 5-Aug-11 7:02am    
So you can try to compile it :-)
--SA
CPallini 5-Aug-11 9:27am    
You are a cheater.
Richard MacCutchan 5-Aug-11 9:33am    
No, I'm an eater. :)
Sergey Alexandrovich Kryukov 5-Aug-11 7:04am    
Questionable comparisons -- a course of poetry recommended. My 5 for the advice itself. However, something tells be OP might have trouble using this advice, if you understand what do I mean... :-)
--SA
"compile with" is virtually impossible because the compiled executables address incompatible targets (Java runs on a virtual machine to be platform independent, C++ not).

Some interoperability is possible via the Java Native Interface that will allow you to invoke DLLs written in C++ or conversely. http://download.oracle.com/javase/1.5.0/docs/guide/jni/index.html[^]. Be ready to swallow technicalities, though.

Another option could be to mix C++.NET code with J#.NET code (both running on the .NET framework), even though J# is not pure Java.

If one of your source file is not too big, consider rewriting in the other language, this may be a faster solution.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Aug-11 7:09am    
I like the very last advice (:-) and the advice about C++ and J#. My 5. However, there is not such thing as C++.NET. There is C++/CLI. By the way, a good additional idea could be using mixed mode project: managed+unmanaged, C++/CLI + C++ in one project.
--SA
Of course you can't compile together Java and C++, however, you may call C++ code from Java and the opposite, using JNI, see, for instance, here[^].
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 5-Aug-11 7:02am    
Sure, a 5. What kind of questions can we see sometimes...
--SA
CPallini 5-Aug-11 9:26am    
Thank you.
Let us know ...what are you doing exactly.
 
Share this answer
 
Comments
bearbear91 5-Aug-11 3:38am    
I'm actually doing on a program for face recognition.
but for the face detection part i'm using java for the coding while the rest of the portion is on c++. so is there any way to do that?
TorstenH. 5-Aug-11 5:25am    
why do you use c++ "for the rest" ? wasn't complicated enough to do it all in java? change it. Use C++ OR Java. not both.
Sergey Alexandrovich Kryukov 5-Aug-11 7:06am    
Well, this is a sound advice, I kind of agree. However, as CPallini pointed out JNI can help. I would advise to use it as a last resort though.
--SA
TorstenH. 5-Aug-11 7:11am    
no, that can't be true.
What is this C++ Java mixing thing? Are the C++ people bored of their stuff? is it a new "I can do both" thing?
From a developers point of view it's total bullsh*t! Stuff that one not just goes to hell for but also has to do VB for eternity.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900