2

What data types can be passed between c++ and java/java to c++? Also, are the data types equivalent in terms of size?

3 Answers 3

4

Using Java Native Interface you can pass just about anything between C++ and Java.

Sign up to request clarification or add additional context in comments.

3 Comments

and what about from java to c++?
JNI Supports both directions. It can be tricky and there may be better solutions for you but reading a little about JNI will answer many of your questions and is generally useful knowledge to have.
JNA seems to be the popular slightly higher-level Java-native interface at the moment.
2

I prefer Swig myself. It does the JNI wrapping for you allowing calls in any direction you'd like, multithreading, etc. It also works with multiple languages including Java, Python, Perl etc...

Swig is also portable as your C++ code is - I use it myself on Linux and Windows to bridge our C++ code to Java and Python.

Comments

1

Also check out CNI if using g++. Don't know if JNI is the same way, but you're basically just using C++ to write within a JVM. That is, you can't pass pure C++ objects to Java. Instead, everything must derive from Object.

1 Comment

What do you mean by "derive from Object"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.