The standard Java class library may not support the platform-dependent features needed by your application.
You may already have a library or application written in another programming language and you wish to make it accessible to Java applications
You may want to implement a small portion of time-critical code in a lower-level programming language, such as assembly, and then have your Java application call these functions
2.JNI的书写步骤
编写带有native声明的方法的java类
使用javac命令编译所编写的java类
使用javah ?jni java类名生成扩展名为h的头文件
使用C/C 实现本地方法
将C/C 编写的文件生成动态连接库
ok
1) 编写java程序:
这里以HelloWorld为例。
代码1:
class HelloWorld { public native void displayHelloWorld().
static { System.loadLibrary("hello"). }
public static void main(String[] args) { new HelloWorld().displayHelloWorld(). } }