Table of Contents |
by Beth Stearns
The lessons in this trail show you how to integrate native code with your Java programs. You will learn how to write Java 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.
Note: This trail replaces Integrating Native Methods into Java Programs which describes native methods for the 1.0.2 release of the JDK.
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 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. So applets may not be able to use native methods depending on the browser or viewer they are running in. See Understanding Applet Capabilities and Restrictionsfor information about the security restrictions placed on applets.
Note to MacOS programmers: You can't extend the Java runtime on a 68K Macintosh. Thus you can't load shared libraries and you can't use native methods.
Table of Contents |