Java Reference
In-Depth Information
This command produces a file named
javatech
-
jni22
-
JNIHelloWorld.h
in the
build/headers
directory. Notice the naming scheme in which the pack-
age name (
javatech.jni22
) and class name (
JNIHelloWorld
) are used
with underscore characters replacing the dots.
Let's examine the generated header file (the formatting has been modified
slightly from the actual generated source to better fit the page):
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class javatech
-
jni22
-
JNIHelloWorld */
#ifndef
-
Included
-
javatech
-
jni22
-
JNIHelloWorld
#define
-
Included
-
javatech
-
jni22
-
JNIHelloWorld
#ifdef
-
cplusplus
extern "C"{
#endif
/*
* Class: javatech
-
jni22
-
JNIHelloWorld
* Method: nativeHelloWorld
* Signature: ()V
*/
JNIEXPORT void JNICALL
Java
-
javatech
-
jni22
-
JNIHelloWorld
-
nativeHelloWorld (
JNIEnv *, jobject);
/*
* Class: javatech
-
jni22
-
JNIHelloWorld
* Method: nativeHelloWorldStatic
* Signature: ()V
*/
JNIEXPORT void JNICALL
Java
-
javatech
-
jni22
-
JNIHelloWorld
-
nativeHelloWorldStatic (
JNIEnv *, jclass);
#ifdef
-
cplusplus
}
#endif
#endif
This may look unwieldy at first (like we said, JNI code is “ugly”), but there are two
important lines here - the two that begin with
JNIEXPORT void JNICALL
.
These give the signatures of the two native C functions that must be used in
the implementation source. We see that each method name declared in the Java
source code (
nativeHelloWorld
and
nativeHelloWorldStatic
) gets
converted into a long function name beginning with
Java
-
followed by the fully-
qualified method name, again with dots replaced by underscores. This lengthy
Search WWH ::
Custom Search