Search this site


 Home  JNI Intro  JNI data types  JNI overhead

Search this site:
Threads Database Profiling Regular expressions Random numbers Compression Exceptions C Equivalents in Java

 What do you think of this article? Did it help you? Found a mistake? Feedback and suggestions here

In our initial JNI example, we declared a Java method that took an int parameter and saw that the resulting C function generated by the javah tool took (along with a couple of other parameters) a parameter of type jint. In fact, the Java method also returned an int, and the corresponding C method a jint. Here are the two side by side as a reminder:

Java:
public native static int getDoubled(int n);
C:
JNIEXPORT jint JNICALL Java_test_Test_getDoubled(JNIEnv *,
    jclass, jint);

From this example, you'll hopefully be unsurprised to learn that for each Java primitive type, there is a corresponding C type declared in the JNI headers. So a Java boolean becomes a C jboolean, a Java char a C jchar etc:

Java primitive typeCorresponding C type with JNIBytes
booleanjboolean1
bytejbyte1
charjchar2 (unsigned)
shortjshort2 (signed)
intjint4
longjlong8
floatjfloat4
doublejdouble8

Written by Neil Coffey. Copyright © Javamex UK 2009. All rights reserved.