JNI – Java Native Interface

JNI is a two-way interface that allows Java applications to invoke native code and vice versa. The JNI is designed to handle situations where you need to combine Java applications with native code.

Java native methods are methods declared in your Java code (much like you declare an abstract method), but which are actually implemented in another programming language.

Here is the series of JNI articles where you can learn from basic Hello World program, JNI setup to complex programs.

15 Comments

JNI Part1: Java Native Interface Introduction and “Hello World” application

Introduction, Purpose and features JNI stands for Java Native Interface JNI specifies a communication protocol between Java code and external, native code. It enables your Java code to interface with native code written in other languages (such as C, C++) Native code typically accesses the CPU and registers directly and is thus faster than interpreted […]

4 Comments

JNI Part 2: Visual Studio setup for DLL Project

Here is the simple steps to DLL project in Visual Studio Open Visual Studio Click File->New Project, and select Empty project Write Name and select location Click ok Go to Project->Properties On the left side, select general in configuration properties Select Dynamic Library(.dll) as configuration Type Next click C/C++ Add jdk include and win32 path […]

No Comments

JNI Part 3: Passing Arguments and Mapping Types

The implemented JNI native methods have two standard parameters, in addition to the arguments declared in their Java-side declaration. The first parameter, the JNIEnv interface pointer, points to a location that contains a pointer to a function table. Each entry in the function table points to a JNI function. Native methods always access data structures […]

5 Comments

JNI Part 4: JNI Strings

The jstring type represents strings in the Java virtual machine, and is different from the regular C string type (a pointer to characters, char *). We cannot use a jstring as a normal C string. We must use the appropriate JNI functions to convert jstring objects to C/C++ strings. The JNI supports conversion both to […]

2 Comments

JNI Part 5: JNI Arrays

Arrays have dimension. An array’s dimension determines the number of indexes needed to access an element. The standard convention for declaring arrays is: String[] s; // one-dimensional array String s[]; // one-dimensional array String[][] s; // two-dimensional array Declaring the size of the array with the following notation is illegal: String[5] s; // illegal declaration […]