Learn Java

JNI Process

This section follow below process step by step.

  • Begin by writing the Java program.

    Create a Java class that declares the native method; this class contains the declaration or signature for the native method. It also includes a main method which calls the native method.

  • Compile the Java class declaring the native and the main method.
  • Generate a header file for the native method

    Using javah with the native interface flag -jni. Once you've generated the header file you have the formal signature for your native method.

  • Write the implementation of the native method in C or C++.
  • Compile the header and implementation files into a shared library.
  • Run the Java program.

Reference:

Writing a Java Program with Native Methods