Previous | Next | Trail Map | Using the JNI | Contents

Using the JNI

by Beth Stearns

The lessons in this trail show you how to integrate native code with programs written in the Java programming language. You will also learn how to write Java programming language native methods. Native methods are implemented in another programming language such as C. In addition, the Invocation API allows you to embed the Java Virtual Machine into your native applications.

Only experienced programmers should attempt to write native methods or use the Invocation API!

Step By Step 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 with native methods.

Java Native Interface Programming shows you how to implement both the Java programming language side and the native language side of a native method. 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. This lesson also describes many useful functions that your native language code can use to access Java objects and their members, create Java objects, throw exceptions, invoke the Java Virtual Machine, and more.


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 the browser or viewer they are running in restricts the ability to load dynamic libraries. See Security Restrictions(in the Writing Applets trail) 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.


Previous | Next | Trail Map | Using the JNI | Contents