Show Mobile Navigation

Webring

Powered by WebRing.

Java Native Interface: a short and useful notes in JNI.

Sachin R Kukale - 02:24
Java native interface is very important concept in Java using which you can implement the features in other programming languages which are platform independent like C or C++. It gives additional strength to the Java language.

Steps to install Borland C++ on your computer:
        i.            Install Borland C++.
      ii.            Provide the path for ‘bin’ directory of C++ in the path environment variable as you set path for JDK.
    iii.            Create two configuration files ‘bcc32.cfg’ and ‘ilink.cfg’ in the ‘bin’ directory of Borland C++.
     iv.            Write following content in ‘bcc32.cfg’:
-I “C:\Borland\Bcc5\include”
-L “C:\Borland\bcc\lib”
       v.            Write following content in ‘ilink32.cfg’ file:
-L “C:\Borland\Bcc5.5\lib”
     vi.            Write sample ‘C’ programs and try to compile and execute to check the you have done configuration correctly or not.
   vii.            Copy all the header files present in JDK include directory to include directory of Borland C++ 5.5 (including the files present inside the folder present in include directory.)
 viii.            Write Java class with native method and compile the java source file to generate ‘.class’  file.
     ix.            Use ‘javah’ command to generate header file corresponding to native implementation.
Syntax:
javah
Ex:
javah Service
       x.            Copy generated header file to the include directory of Borland C++.
     xi.            Write C implementation with include statements i.e.
#include
#include
Where Service.h is header file generated by the javah command.
   xii.            Method name written in C implementation must be same as specified in generated header file.
 xiii.            Compile the C implementation and generate the ‘.dll’ file. To generate the ‘.dll’ file you must use –WD option as:
bcc32 –WD ServiceImple.c
 xiv.            Write java class and load all file in static block as:
static{
System.loadLibrary(“ServiceImple”);
}
   xv.            Write implementation to call the native method.
 xvi.            Compile and execute java class.


0 comments:

Post a Comment