简体   繁体   中英

What are native libraries and native methods interface in JVM?

JVM图 I came across this figure while studying JVM. I understood all the components except "Native method interface" and "native method libraries". What are those exactly?

Native method interface: Native method interface is an interface that connects native method libraries (implemented in C, C++ etc.) with JVM for executing native methods.

Native method library: Implementation in native code.

Please refer this link for more information.

Native Method Interface (JNI) is part of JDK that connects Java code with native applications and libraries that are written in other programming languages, such as C, C++, and assembly.

Why use JNI?

  • Use features that are platform-dependent and are not supported in the Java class library.
  • Increase performance by implementing a time-critical code in a lower-level language.
  • Access libraries that already written in another programming language.

Native Method Libraries are libraries that are written in other programming languages, such as C, C++, and assembly. These libraries can be loaded through JNI.

So, the picture you posted is saying that JNI allows access to Native Method Libraries.

Java Native Interface: The above diagram you could come across when you are studying about java virtual machine functionality. There is nothing like Native library when you are installing and working with java at first time. Those are all added when we are developing our own library , but it should be in other languages.

When you are developing functionality in other languages Java Virtual machine will include those libraries at the execution level(Third level) of the java application.

To add to this, there are also native libraries in jvm $JAVA_HOME/jre/lib/amd64/ and these are core libraries which are loaded by reflection( null/boot classloader ) which is why they are available at run-time while compiling and we're able to use native methods of Object class like getClass() . So, not only for custom development using JNI but also, some of the core functionalities of java are written into native.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM