Java Native Access (JNA) is an open-source library that simplifies using the Java Native Interface (JNI) to call native code from Java. JNA allows Java programs to integrate with operating system features, architecture features, and native libraries without needing to write JNI code. JNA maps Java types like int and String to native C types and provides interfaces to call native functions. Developers can write Java code to call native functions without needing to generate header files or write JNI wrapper code. JNA uses JNI and libffi to dispatch calls to native code.
2. Motivation
• JNI (Java Native Interface) allows Java
programs to call native code
• JNA is an open-source library that simpli es
using JNI (Java Native Interface)
2
3. Reasons for “going native”
•
•
•
•
Integration
Using operating system features (e.g: SWT)
Using architecture features (e.g: SSE, RdRand)
Performance (e.g: tomcat-native)
3
4. Hello World with Windows API
int WINAPI MessageBoxA(
HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption,
UINT uType
);
4
5. JNI Example (1/3)
public class HelloJni {
public native int msgBox(String s);
public static void main(String[] args) {
System.loadLibrary(”HelloJni”);
new HelloJni().msgBox(”Hello␣World!”);
}
}
5