javac++eclipsejava-native-interface

Wrapping C/C++ inside Java


I develop applications/programs in C/C++. I am more versed in these two languages and love being a C++ developer. I am wondering how to create a Java program that contains all my C++ code.

I mean, I would like to wrap all my C++ code (that is already developed) inside Java class. But clueless how to do it.

Please post your responses or methods/steps on integrating C++ inside Java. (using JNI is the way, but I could not figure it out on www how to use it)

FYI, I use Eclipse IDE to develop.

How and what packages should I include in my project workspace?


Solution

  • If you want to call C++ from Java, you'll need to use JNI - Java Native Interface.

    Be warned that you lose some of the benefits of the garbage collector, since it can't deal with your C++ objects, and your code won't be portable anymore.

    Maybe you'd be better served by learning to write 100% Java and leaving C++ behind, but that's just a suggestion.