Sobes.tech
Middle

What does the native modifier mean in a Java class method?

sobes.tech AI

Answer from AI

The native modifier indicates that the method implementation is written in another programming language (e.g., C, C++), rather than Java. These methods are loaded from a shared library (.so or .dll) at runtime.

Used for:

  • Interacting with low-level operating system functions.
  • Integrating with existing code written in other languages.
  • Improving performance in critical sections of code.

Example declaration:

public native void printHelloFromC();

The standard JNI (Java Native Interface) framework is used for working with native methods.