Java Native Interface Program

By | June 5, 2016

Java Native Interface Program with C Code

Learn How To Build Java Native Interface Program with C Programming Language. This JNI Tutorial will help you to execute Java and C Programs together on Linux Terminal. Also, you will get to know how to configure your system to execute JNI Codes in Linux Ubuntu. We have mentioned complete and detailed steps to write a Java Native Interface Code.

Remember

This JNI Tutorial should be executed in Oracle Java 8. Other Java versions have certain incompatibilities that will hamper program execution. To Download Open JDK 8, type the following command in the Linux Ubuntu Terminal:

If you have multiple versions of Java installed in your machine, you will have to point the default java version. For this, you will have to switch the version and point it as the default version.

To view all the Java versions installed in your Linux Operating System, follow the commands:

The output would be something of this sort:

Now, you need to select the openJDK 8 and set it as the default version. Type the following commands sequentially to set Java 8 as the default version.

Also Read: Difference Between C++ and Java

Java Code For Native Interface Program To Print Hello World

 

Java Header File Code

C Program For Java Native Interface To Print Hello World

Also Read: Print System Date and Time in Java

Linux Ubuntu Terminal Commands for JNI Program Execution

The chances of getting compilation errors are high in JNI due to invalid configuration settings. Follow the steps to run Java Native Interface Programs in Linux Terminal.

Java Compilation

Java Header File

 

C Program Compilation with Object Creation

Linker Command

Final Execution Statement

Also Read: Java Program To Check Public IP Address

Output

Java Native Interface Program with C Language

We hope that you could successfully execute the Java Native Interface Program. In case you have any compilation error or doubt about this JNI Tutorial, let us know about it in the comment section below.

Let's Discuss