What is Java Native Interface(JNI)




Contents of page >
  • 1) What is Java Native Interface(JNI)?
  • 2) Examples of using JNI (Java Native Interface).
  • 3) By using JNI (Java Native Interface), you can make Native methods to -
  • 4) Objectives of JNI (Java Native Interface).

  • 5) JNI (Java Native Interface) method interface must satisfy the following requirements >
  • 6) Should we program to JNI (Java Native Interface) >


1) What is Java Native Interface(JNI)?
You may write your application purely in java but there are certain situations where java code might need meet your requirement.
Programmers uses the JNI (Java Native Interface) to write the Java native methods when an application cannot be written purely in Java.

2) Examples of using JNI (Java Native Interface).
When classes in java library doesn’t support the platform-dependent features needed by the application.
When you want your java code to access the library already written in any other language using JNI.

3) By using JNI (Java Native Interface), you can make Native methods to -

  • Call the Java methods.
  • Create, and update Java objects like arrays, Integer, String and many more.
  • Catch and throw exceptions in java.
  • Load java classes and obtain class information.


4) Objectives of JNI (Java Native Interface).

  • With JNI (Java Native Interface) each JVM vendor can support a larger body of native code.
  • Application programmers will be able to write one version of their native code and this version will run on different VMs..


5) JNI (Java Native Interface) method interface must satisfy the following requirements >

  1. Binary compatibility - Binary compatibility of native method libraries across all JVM implementations on different platforms. Developers must maintain only one version of their native method libraries for a given platform.

  1. Efficiency - We must ensure JVM-independence.

  1. Functionality - The JNI must expose enough JVM internals to allow native methods to accomplish the useful tasks.



6) Should we program to JNI (Java Native Interface) >
  • If you are looking to implement your own JVM, you should look to implement the JNI (Java Native Interface) .
  • JNI (Java Native Interface) does not impose any overhead or restrictions on your JVM implementation.
  • By using JNI (Java Native Interface) your java code can access the library already written in any other language.
  • JNI (Java Native Interface) does not impact object creation or object cleaning process like garbage collection.


Having any doubt? or you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.



RELATED LINKS>



JVM in detail - Garbage collection & heap structure >

>JVM Heap memory (Hotspot heap structure) with diagram in java


eEdit
Must read for you :