The JavaTM Tutorial
Trail: Java Native Interface
Lesson: Summary of the JNI
Congratulations! You have learned a great deal about the JNI. To help you remember everything you have learned, this section summarizes the JNI functions and mapping types.
Mapping Between JNI and Native Types
The following two tables summarize how Java types map to native types and the rules for encoding Java types in native signatures.
Primitive Types and Native Equivalents
Java Type | Native Type | Size in bits |
boolean | jboolean | 8, unsigned |
byte | jbyte | 8 |
char | jchar | 16, unsigned |
short | jshort | 16 |
int | jint | 32 |
long | jlong | 64 |
float | jfloat | 32 |
double | jdouble | 64 |
void | void | n/a |
Encoding for Java Type Signatures
Signature | Java Programming Language Type |
Z | boolean |
B | byte |
C | char |
S | short |
I | int |
J | long |
F | float |
D | double |
L fully-qualified-class ; | fully-qualified-class |
[ type | type[] |
( arg-types ) ret-type | method type |
JNI String Handling Functions
GetStringChars
- GetStringLength
- GetStringUTFChars
- GetStringUTFLength
- NewString
- NewStringUTF
- ReleaseStringChars
- ReleaseStringUTFChars
JNI Array Handling Functions
GetArrayLength
- Get<type>ArrayElements
- GetBooleanArrayElements
- GetByteArrayElements
- GetCharArrayElements
- GetDoubleArrayElements
- GetFloatArrayElements
- GetIntArrayElements
- GetLongArrayElements
- GetShortArrayElements
- Release<type>ArrayElements
- Get<type>ArrayRegion
- Set<type>ArrayRegion
- GetObjectArrayElement
- SetObjectArrayElement
JNI Method Handling Functions
GetObjectClass
- GetMethodID
- GetStaticMethodID
- Call<returntype>Method
- CallBooleanMethod
- CallByteMethod
- CallCharMethod
- CallDoubleMethod
- CallFloatMethod
- CallIntMethod
- CallLongMethod
- CallObjectMethod
- CallShortMethod
- CallVoidMethod
- CallStatic<returntype>Method
- CallNonvirtual<returntype>Method
- Call<returntype>MethodV
- Call<returntype>MethodA
JNI Member Variable Handling Functions
GetFieldID
- GetStaticFieldID
- Get<type>Field
- GetBooleanField
- GetByteField
- GetCharField
- GetDoubleField
- GetFloatField
- GetIntField
- GetLongField
- GetObjectField
- GetShortField
- Set<type>Field
- GetStatic<type>Field
- SetStatic<type>Field
JNI Exception Handling Functions
ExceptionClear
- ExceptionDescribe
- ExceptionOccurred
JNI Local and Global Reference Handling Functions
NewGlobalRef
- DeleteGlobalRef
- DeleteLocalRef
JNI Thread Synchronization Functions