Java Native Interface
Your feedback is important to us! If you have comments about this trail, send them to: tutorial@java.sun.com. In your message, put JNI in the subject header.
The lessons in this
trail show you how to integrate native code with programs written in Java.
You will learn how to write
native methods. Native methods are methods
implemented in
another programming language such as C.
The JNI is for programmers who must take advantage of platform-specific functionality outside of the Java Virtual Machine. Because of this, it is recommended that only experienced programmers should attempt to write
native methods or use the Invocation API!
Overview of the JNI
begins with an introduction to the JNI concepts.
Writing Java Programs with Native Methods
describes how to compile and run a Java program with a native method. It walks you step by step through a simple example (the "Hello World!" of
native methods) to illustrate how to write, compile, and run a Java program
that includes native methods.
Integrating Java and Native Programs
shows you how to map Java types to native types. This lesson includes information about
passing arguments of various data types into a native method and
returning values of various data types from a native method. It also shows how to implement a native method within a Java program.
Interacting with Java from the Native Side
describes many useful functions that your native language
code can use to access Java objects and their members, create Java
objects, throw exceptions, and more.
Invoking the Java Virtual Machine
explains how to invoke the Java Virtual Machine from your native application.
Summary of the JNI
lists the JNI methods and mapping tables to remind you of what you've learned.
Security consideration:
Note that the ability to load dynamic libraries is subject to
approval by the current security manager. When working with native
methods, you must load dynamic libraries. Some applets may not be
able to use native methods because
the browser or viewer they are running in restricts the ability to load dynamic libraries. See
Security Restrictions for information about the security restrictions placed on applets.
Note: MacOS programmers should refer to
MacOS Runtime for Java (MRJ).
Programmers interested in writing native
methods in releases prior to 1.1 can
download
the old version of this trail.
It describes native methods for the 1.0.2 release of the JDK.
|