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.
the two side by side as a reminder:
public native static int getDoubled(int n);
JNIEXPORT jint JNICALL Java_test_Test_getDoubled(JNIEnv *,
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 type||Corresponding C type with JNI||Bytes|
If you enjoy this Java programming article, please share with friends and colleagues. Follow the author on Twitter for the latest news and rants.
Editorial page content written by Neil Coffey. Copyright © Javamex UK 2021. All rights reserved.