Java and C Data Type Mapping
As already mentioned, Java and C/C++ are very different in their variable types. In order to make the two match, JNI provides a mechanism to complete the mapping between Java and C/C++. The correspondence relationship between the main types is shown in Table 1.
JAVA TYPE |
NATIVE TYPE |
DESCRIPTIONS |
|
|
C/C++ 8-bit integer |
|
|
C/C++ unsigned 8-bit integer |
|
|
C/C+ unsigned 16-bit integer |
|
|
C/C++ signed 16-bit integer |
|
|
C/C++ signed 32-bit integer |
|
|
C/C++ unsigned 64-bit integer |
|
|
C/C++ 32-bit floating point |
|
|
C/C++ 64-bit floating point |
|
|
N/A |
|
|
Any Java object, or does not correspond to an object of |
|
|
Class object |
|
|
String objects |
|
|
The array of any object |
|
|
Boolean array |
|
|
Array of bits |
|
|
Character array |
|
|
Short integer array |
|
|
Integer array |
|
|
Long integer array |
|
|
Floating-point array |
|
|
Double floating-point array |
Table 1: Java to C type mapping.
When a Java parameter is passed, the idea of using C code is that basic types can be used directly; for example, double
and jdouble
can be interoperable. Basic types are the types listed from the line boolean through void in Table 1. That is, in such a type, if the user passes a boolean
parameter into the method, then there is a local method jboolean
corresponding to the boolean
type. Similarly, if the local methods return a jint
, then an int
is returned in Java.