Table of Contents |
A native method is a Java method (either an instance method or a class method) whose implementation is written in another programming language such as C. The lessons in this trail show you how to integrate native methods into your Java code.Only experienced programmers should attempt to use native methods!
Note to C++ programmers: Note that currently the Java environment generates C header and source files, which provide the glue for integrating C code into Java programs. You can integrate C++ code into your Java programs using these C header and source files. See Using C++ in Native Method Implementations for information (this will make more sense after you've read both lessons in this trail).
WARNING! The programming interface for implementing native methods in Java is under construction. Use these interfaces at your own risk and in full knowledge that they will change in future releases of Java. The examples and information contained here reflect the JDK 1.0 release.
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.
Implementing Native Methods 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, 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 |