Click here to Skip to main content
15,891,687 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Dear Sir,

I have collection c++ files. I want to call/use them in java code.
How can we do it?
Please give a suggestion to do it.

regards
sankar
Posted

I already answered this question here[^]. For future reference, please post your question in one forum only.
 
Share this answer
 
You should read about the Java Native Interface, JNI[^].
 
Share this answer
 
Comments
sankardunga 22-Mar-11 5:23am    
can we call any c++ files by using JNI.
Niklas L 22-Mar-11 5:38am    
I have done it for C files, but I suggest you look at the wiki here http://en.wikipedia.org/wiki/Java_Native_Interface
You will need to write some wrapper functions.
Richard MacCutchan 22-Mar-11 7:05am    
Yes you can use it to call C or C++ language code.
sankardunga 22-Mar-11 6:46am    
okay thank you,
i will try in this way.
Hi,
C++ and Java have so different underlying concepts that it's not possible directly.
You may try to translate the C++ code to Java, which is sometimes near to impossible. You will find some free or paid translator programs if googling for them.
My personal experience is that they are almost useless.
For handwritten translation have a look at Quick conversion and reference to the most
common commands used in C/C++ and Java
[^].

Eventually the quickest and best way is to write in Java from scratch, using the C++ code base as reference.
cheers,
AR
 
Share this answer
 
Comments
Richard MacCutchan 22-Mar-11 7:02am    
Not quite true, using the JNI it's fairly easy to call C/C++ libraries from Java and vice versa.
You can create a wrapper class that interfaces with the c++ library (yes you have to build a library)
 
Share this answer
 
Comments
sankardunga 22-Mar-11 5:21am    
can you elaborate your answer.
I didn't get.
Kurt Degiorgio 22-Mar-11 7:20am    
take a look at this article:
http://home.pacifier.com/~mmead/cs510jip/jni/

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