Monday, 24 March 2014

JAVA NATIVE INTERFACE

Posted By: Unknown - Monday, March 24, 2014


A native method is a method that is implemented in a language other than Java like C, C++, assembly language …etc. Java Native Interface ( JNI) provides feature to call native language program’s method to be called and used in java. It also provide feature to call java method in native language code.


Why JNI is needed. There can be multiple reason for the same. Sometime, we are working in very old system and java need to use same outdated system program. Some code is very well performing and well tested and do not want to spend time in rewriting in java and handles issue of performance. We may use JNI when there is no feature in java but it is available in native OS. Java IO, file chooser ….etc already uses internally JNI. Native code always runs faster in compare to Java so we want to utilize the advantage of speed.
Simple Steps for JNI ( program to call native method in Java code ):
1. Write java code and compile with declaring methods and using modifier native
public native void nativeMethod();
2. Creating header file of C which should have method declared in same.
javah -jni JavaNativeMethods
3. Writing C implementation of native method by prefixing Java_
4. Compile C code and create shared library using glib, cc ….etc
5. Execute Java Program which call jni method

0 comments:

Post a Comment

this blog is helpful or not

International

Auto News

Translate

Pages

Popular Posts

Popular Posts

Designed By Templatezy / Sb Game Hacker Apk / MyBloggerThemes