Java Native Interface

Java Native Interface (JNI ) is a standard application programming interface ( API) that provides the ability to invoke platform - specific functions or methods of the Java programming language out.

Unlike ordinary Java programs is a Java program that uses JNI calls, only platform- independent if the native library program is available on all platforms.

Purpose

JNI allows native methods to write for situations where it is not possible to exclusively use Java as a programming language. This is the case if, for example, does not support the standard Java class library, certain platform dependent features or other program libraries. It is also possible via JNI to make a more programmed in another programming language for Java application accessible. Many classes of the Java standard library are based on JNI to allow, for example, the file input and output or sound reproduction. The fact that Java this kind of performance and platform -dependent implementations integrated into the standard library, the Java and Program the user is enabled to use these features in a safe and platform - independent manner.

Occasionally JNI is an escape door ( "escape hatch " ) for Java developers called because it allows them to access functionality of the standard Java API would otherwise be impossible. It provides the interface to other programming languages ​​such as C or C dar.

With JNI, it is possible to call functions of a Windows DLL or a shared library on Linux or Mac OS X, which are programmed in C or C from Java. Conversely, it is also possible that "native" programs can call or execute a JVM Java methods via JNI.

Java native method calls on

To call Java from a native method, it must first be declared as "native". In addition, the object's native program library by calling " System.loadLibrary ( " name> library> " ) " itself must load before the native method can be called even.

The Java program is compiled and then created with the software tool javah a header file, which defines the function declaration. This header file can then be created, the native program library.

One of the most popular applications of JNI is the program library Standard Widget Toolkit (SWT ), which allows the use of elements of the graphical user interface of the operating system via JNI.

Native Java program calls on

From a native program can be called Java code. This is necessary, for example to allow a tight integration between Java and the native program.

432183
de