JNI Part 5: JNI Arrays

Arrays have dimension. An array’s dimension determines the number of indexes needed to access an element. The standard convention for declaring arrays is: String[] s; // one-dimensional array String s[]; // one-dimensional array String[][] s; // two-dimensional array Declaring the size of the array with the following notation is illegal: String[5] s; // illegal declaration […]

No Comments

JNI Part 3: Passing Arguments and Mapping Types

The implemented JNI native methods have two standard parameters, in addition to the arguments declared in their Java-side declaration. The first parameter, the JNIEnv interface pointer, points to a location that contains a pointer to a function table. Each entry in the function table points to a JNI function. Native methods always access data structures […]

No Comments

How to convert a jstring to a C-style string or vice versa?

The jstring type represents strings in the Java virtual machine, and is different from the regular C string type (a pointer to characters, char *).  So we cannot use a jstring as a normal C string. We must use the appropriate JNI functions to convert jstring objects to C/C++ strings.  The JNI supports conversion both […]