Easy JNI Question

Hi,

I am new to using the JNI, and am in the process of implementing it for my C++ app... I can't find any information, however, on what to do with the jint, jfloat, etc. variables.

For example, if I receive a jint with a value of 56, and I want to save that in a regular c++ int in my program - do I have to do anything special, or can I just pass the value straight into it... What about the other way round? How do I convert a c++ int into a jint for return to Java?

Thanks a lot!

Crispin

[524 byte] By [ddanooa] at [2007-11-26 18:28:26]
# 1

Please read chapter 3 and 4 at http://java.sun.com/docs/books/jni/download/jni.pdf

jint can be used as int in C. However, if you have C++ aplications, you need to write C codes as bridage between your java classes and C++ apps based on my understanding.

Message was edited by:

CIIT_JAVA_Application

CIIT_JAVA_Applicationa at 2007-7-9 6:02:38 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Thanks for the reply... by the way, as far as the 1 or 2 functions I have looked at, c++ versions exist (though the syntax is slightly different).

Another, slightly more technical question:

If I call a method in C++ from Java, how does the threading situation work? Does it open up a new thread in c++? In other words, if I call main() from a JNI function, is it opening it in a standard c++ thread? If I then call another JNI function does it block the thread that main is now running in?

Cheers,

Crispin

ddanooa at 2007-7-9 6:02:38 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3
If your java is multyi threaded, and makes calls to the netive library, then you are responsible for dealing with any synchronization requirements.
bschauwejavaa at 2007-7-9 6:02:38 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4

Thanks for the reply bschauwejava

I read the pdf on the JNI, but it doesn't tell me much about casting variables... Would I be right to assume that you turn a c++ int into to a jint like this:

int a = 6;

jint b = (jint)a;

and a jint into a c++ int like this:

jint a = 6;

int b = (int)a;

Thanks!

Crispin

ddanooa at 2007-7-9 6:02:38 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5
In order to compile your C code, you need to incclude JNI.h. Look in there for how jint is defined.
bschauwejavaa at 2007-7-9 6:02:38 > top of Java-index,Java HotSpot Virtual Machine,Specifications...