Whole document tree
3 - JNI Types and Data StructuresThis chapter discusses how the JNI maps Java types to native C types. Primitive TypesTable 3-1 describes Java primitive types and their machine-dependent native equivalents.The following definition is provided for convenience. #define JNI_FALSE 0 #define JNI_TRUE 1The jsize integer type is used to describe cardinal indices and sizes:
typedef jint jsize; Reference TypesThe JNI includes a number of reference types that correspond to different kinds of Java objects. JNI reference types are organized in the hierarchy shown in Figure 3-1.Figure 3-1 Reference Type Hierarchytypedef jobject jclass;In C++, JNI introduces a set of dummy classes to enforce the subtyping relationship. For example: class _jobject {}; class _jclass : public _jobject {}; ... typedef _jobject *jobject; typedef _jclass *jclass; Field and Method IDsMethod and field IDs are regular C pointer types:struct _jfieldID; /* opaque structure */ typedef struct _jfieldID *jfieldID; /* field IDs */ struct _jmethodID; /* opaque structure */ typedef struct _jmethodID *jmethodID; /* method IDs */ The Value TypeThejvalue union type is used as the element type in argument arrays. It is
declared as follows:
typedef union jvalue { jboolean z; jbyte b; jchar c; jshort s; jint i; jlong j; jfloat f; jdouble d; jobject l; } jvalue; Type SignaturesThe JNI uses the Java VM's representation of type signatures. Table 3-2 shows these type signatures.long f (int n, String s, int[] arr);has the following type signature: (ILjava/lang/String;[I)J UTF-8 StringsThe JNI uses UTF-8 strings to represent various string types. UTF-8 strings are the same as those used by the Java VM. UTF-8 strings are encoded so that character sequences that contain only nonnull ASCII characters can be represented using only one byte per character, but characters of up to 16 bits can be represented. All characters in the range\u0001 to \u007F are
represented by a single byte, as follows:
The seven bits of data in the byte give the value of the character that is
represented. The null character (
The bytes represent the character with the value
Characters in the range
The character with the value
There are two differences between this format and the "standard" UTF-8
format. First, the null byte
Java Native Interface Specification (HTML generated by dkramer on March 15, 1997) |