JNI£¨Java Native Interface£©
JNIÊÇJava Native InterfaceµÄËõд¡£´ÓJava 1.1¿ªÊ¼£¬Java Native Interface (JNI)±ê×¼³ÉΪjavaƽ̨µÄÒ»²¿·Ö£¬ËüÔÊÐíJava´úÂëºÍÆäËûÓïÑÔдµÄ´úÂë½øÐн»»¥¡£JNIÒ»¿ªÊ¼ÊÇΪÁ˱¾µØÒѱàÒëÓïÑÔ£¬ÓÈÆäÊÇCºÍC++¶øÉè¼ÆµÄ£¬µ«ÊÇËü²¢²»·Á°ÄãʹÓÃÆäËûÓïÑÔ£¬Ö»Òªµ÷ÓÃÔ¼¶¨ÊÜÖ§³Ö¾Í¿ÉÒÔÁË¡£
ʹÓÃjavaÓë±¾µØÒѱàÒëµÄ´úÂë½»»¥£¬Í¨³£»áɥʧƽ̨¿ÉÒÆÖ²ÐÔ¡£µ«ÊÇ£¬ÓÐЩÇé¿öÏÂÕâÑù×öÊÇ¿ÉÒÔ½ÓÊܵģ¬ÉõÖÁÊDZØÐëµÄ£¬±ÈÈ磬ʹÓÃһЩ¾ÉµÄ¿â£¬ÓëÓ²¼þ¡¢²Ù×÷ϵͳ½øÐн»»¥£¬»òÕßΪÁËÌá¸ß³ÌÐòµÄÐÔÄÜ¡£JNI±ê×¼ÖÁÉÙ±£Ö¤±¾µØ´úÂëÄܹ¤×÷ÔÚÈκÎJava ÐéÄâ»úʵÏÖÏ¡£
Ò»¡¢JNI£¨Java Native Interface£©µÄÉè¼ÆÄ¿µÄ
·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
¶þ¡¢JNI£¨Java Native Interface£©µÄÊéд²½Öè
·±àд´øÓÐ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();
}
}
ÉùÃ÷native·½·¨£ºÈç¹ûÄãÏ뽫һ¸ö·½·¨×öΪһ¸ö±¾µØ·½·¨µÄ»°£¬ÄÇôÄã¾Í±ØÐëÉùÃ÷¸Ä·½·¨ÎªnativeµÄ£¬²¢ÇÒ²»ÄÜʵÏÖ¡£ÆäÖз½·¨µÄ²ÎÊýºÍ·µ»ØÖµÔÚºóÃæ½²Êö¡£
Load¶¯Ì¬¿â£ºSystem.loadLibrary("hello");¼ÓÔض¯Ì
Ïà¹ØÎĵµ£º
Ò»¸öJava´°¿Ú´ø°´¼ü¼ì²â£¨ÅÜJava¿ÉÊÓС³ÌÐòʱÓã©£¬沒¼ÓÐÞÊΣ¬°³×Ô¼ºÓõΡ£
package math;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
/**
* »ù±¾µÄ»æͼ´°¿Ú£¬»Ø³µ¹Ø±Õ´°¿Ú
*/
@SuppressWarnings("s ......
ȺÄÚһλÅàѵÀÏʦ·¢³öÀ´Ò»¸öÎÊÌâ:
int[][] a = new int[10][10];
ÕâÖÖ¶àάÊý×é»áÔÚÕ»ÉÏÉú³É¼¸¸ö¶ÔÏó?
Õâ¸öÎÊÌâÐÂÏÊ,ûÈËÎʹý.
·¢³öÀ´ºó ´ó¼Ò¶¼ÈÏΪÓм¸¸öÔªËØ ¾Í»áÉú³É¼¸¸ö¶ÔÏó.
ÎÒ¿ªÊ¼Ò²
ÕâôÈÏΪ.
ÓÚÊÇд¸öÁ˳ÌÐòÊÔÁËÏÂ.·¢ÏÖûÓÐÄÇô¼òµ¥
public static void main(String[] args) {
int[][] a = new int[10][10 ......
1.¼Ì³Ð£ºÊÇÖ¸ÏÈ´´½¨Ò»¸ö¹²ÓÐÊôÐÔµÄÒ»°ãÀ࣬¸ù¾Ý¸ÃÒ»°ãÀàÔÙ´´½¨¾ßÓÐÌØÊâÊôÐÔµÄÐÂÀ࣬ÐÂÀà¼Ì³ÐÒ»°ãÀàµÄ״̬ºÍÐÐΪ£¬²¢¸ù¾ÝÐèÒªÔö¼Ó×Ô
¼ºµÄеÄ״̬ºÍÐÐΪ
Óɼ̳жøµÃµ½µÄÀà³ ......
д¸ø±ÈÎÒ»¹ÐµÄÐÂÊÖÃÇ£¬Èç¹ûÑ¡ÔñÁËÕâÐУ¬¾ÍÄÍÐĵĶÁÏÂÈ¥¡£
1£¬²»Òª×Ü˵“±à²»³öÀ´”£¬“²»»á±à”Ö®ÀàµÄ»°£¬ÄÇЩ»°ÊÇÒòΪÄã×Ô¼ºÀÁ£¬²»Ïë±à£¬²»Ïëѧ¶øÒÑ¡£
2£¬²»ÒªÄÜ¿ª·¢µãС³ÌÐò¾Í³öÈ¥ÏÔ°Ú£¬ÄãÖ»²»¹ýÊÇÓñðÈ˸øÄãдºÃµÄ¶«Î÷¶øÒÑ¡£
3£¬²»ÒªÌ«Ö´×ŵĶ¢×ÅAPI£¬JAVAµÄ¾«»ªÔÚÓÚ±à³Ì˼·¸úģʽ£¬¶ø²»ÊÇÒѾ ......