 | Level: Intermediate Scott Stricker (sstricke@us.ibm.com), Developer, IBM
26 Mar 2002 The Java™ Native Interface (JNI) is a native programming interface that is part of the Java SDK. JNI lets Java code use code and code libraries written in other languages, such as C and C++, and allows you to call Java code from within native code. In this tutorial, IBM enterprise developer Scott Stricker deals with the two most common applications of JNI: calling C/C++ code from Java programs, and calling Java code from C/C++ programs. We'll cover both the essentials of the Java Native Interface and some of the more advanced programming challenges that can arise. Prerequisites
All the examples use Java, C, and C++ code, and are written to be portable to both Windows and UNIX-based platforms. To follow the examples, you must have some experience programming in the Java language. In addition, you will also need some experience programming in C or C++. Strictly speaking, a JNI solution could be broken down between Java programming tasks and C/C++ programming tasks, with separate programmers doing each task. However, to fully understand how JNI works in both programming environments, you'll need to be able to understand both the Java and C/C++ code. We'll also cover a number of advanced topics, including exception handling and multithreading with native methods. To get the most out of this part of the tutorial, you should be familiar with the Java platform's security model and have some experience in multithreaded application development.
System requirements
You will need JavaScript enabled on your browser. To run the examples in this tutorial, you will need the following tools and components:
-
Java compiler:
javac.exe ships with the SDK.
-
Java virtual machine (JVM):
java.exe ships with the SDK.
-
Native method C file generator:
javah.exe ships with the SDK.
-
Library files and native header files that define JNI. The jni.h C header file, jvm.lib, and jvm.dll or jvm.so files all ship with the SDK.
-
C and C++ compiler that can create a shared library. The two most common C compilers are Visual C++ for Windows and
cc for UNIX-based systems.
Although you may use any development environment you like, the examples we'll work with in this tutorial were written using the standard tools and components that ship with the SDK.
Duration
Under one hour
Formats html, pdf
|  | |  |