2

Jvm figure 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?

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
eatSleepCode
  • 4,427
  • 7
  • 44
  • 93
  • 1
    There's no way to implement some things using only Java (because there's no way to make kernel calls from Java directly), so you write functions for such actions in another programming language (like C), and then call these native methods from Java. The Java library has native methods for `print`, and other low-level methods. OpenGL libraries such as LWJGL also need to use native methods to communicate to the GPU. –  Aug 20 '15 at 04:36
  • @Runemoro So these are just the libraries written in some low level language and present inside JVM? – eatSleepCode Aug 20 '15 at 04:40
  • _... just libraries written in some low level language and present inside JVM?_ It's more than just that: Native methods don't have to be built-in to the JVM. The Java `native` keyword allows you to declare your own classes with _native methods_---methods that are implemented by _shared library_ functions. The _Java Native Interface (JNI) Specification_ (see the link in geekprogrammer's answer) documents what the shared library functions have to look like, and what they have to do in order to interact with Java objects and methods in your program. – Solomon Slow Sep 10 '15 at 19:48

4 Answers4

3

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.

geekprogrammer
  • 1,108
  • 1
  • 13
  • 39
1

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.

IraMay
  • 11
  • 2
0

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.

Loga C
  • 1
  • 1
0

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.

milanbalazs
  • 4,811
  • 4
  • 23
  • 45