Previous | Next | Trail Map | Java Native Interface | Contents

Integrating Java and Native Programs

The Java Native Interface defines a standard naming and calling convention so that the Java Virtual Machine (VM) can locate and invoke your native methods. This section shows you how to follow the JNI naming and calling conventions so that you can use JNI functions from a native method. It also teaches you how to declare types so that they can be correctly recognized by both the Java program and the native method.

Declaring Native Methods

On the Java side, you declare a native method with the native keyword and an empty method body. On the native side, you provide an implementation for the native method. You must be careful when writing native methods to "match" the native function implementation with the method signature in the Java header file. The javah tool, which is explained in Step 3: Create the .h file, helps you to generate native function prototypes that match the Java-side native method declaration.

Mapping between Java and Native Types

The JNI defines a mapping of Java types and native language (C/C++) types. This section introduces the native types corresponding to both primitive Java types, such as int and double, and Java objects, including strings and arrays.


Previous | Next | Trail Map | Java Native Interface | Contents