This post explain different methods to call the operating system commands or native code from a Java application.
Methods to call a native function
Method 1. Use Runtime class
Runtime class contains the exec method that allows the application to run an operating system command.
An example of how to use this method:
String command = "echo \"Hello World!\"";
Method 2. Use JNI
Java Native Inteface (JNI) is a foreign function interface that allows code running on JVM to call (or be called by) native applications. Using JNI, one can call methods written in C/C++ or even access assembly language.
Method 3. Use JNA
Java Native Access (JNA) is an open source project that makes it possible for you to use native libraries using only Java code, with little to no C programming experience.
- Yiğit PIRILDAK; “Java Native Access: a cleaner alternative to JNI“