How to use JNI in java? and what are Struts and jini?and how to apply native code in java?

Pl. explain with the e.g.

Showing Answers 1 - 1 of 1 Answers

Anadi Misra

  • Nov 13th, 2005
 

to use jni we need three things one a native library , usually a ".DLL" which is complied in C or C++. a header file for the native library and the java code whre native aPI implementation is called.

 a method that calls the native librbary will also be requiered to have "native" keyword  in its signature.

eg. public native void nHello(){.............}

we can then call the native method in this method of java

i.e. public native void nHello(){hello();}

the source file is then compiled as usual and the classfile is used with javah command to generate a header file which will have the name same as the class file

javah <Class Name>

the method when implemented for example in c must include jni.h file

found in %java_home%\include\win32 folder

i.e.

#include "jni.h"

# include "<CLass Name>.h"

void hello(){

printf("Hello World !");

}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions