Start of Tutorial > Start of Trail |
Search
Feedback Form |
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.
On the Java side, you declare a native method with thenative
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. Thejavah
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.
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 asint
anddouble
, and Java objects, including strings and arrays.
Start of Tutorial > Start of Trail |
Search
Feedback Form |
Copyright 1995-2001 Sun Microsystems, Inc. All rights reserved.