JAVA JNI ʹÓÃʵÀý
JAVA¿ÉÒÔͨ¹ýJNI½Ó¿Ú·ÃÎʱ¾µØµÄ¶¯Ì¬Á¬½Ó¿â£¬´Ó¶øÀ©Õ¹JAVAµÄ¹¦ÄÜ¡£Ê¹ÓÃJAVA JNI½Ó¿ÚÖ÷Òª°üÀ¨ÒÔϲ½Ö裺
(1)±àдJAVA´úÂ룬עÃ÷Òª·ÃÎʵı¾µØ¶¯Ì¬Á¬½Ó¿âºÍ±¾µØ·½·¨£»
(2)±àÒëJAVA´úÂëµÃµ½.classÎļþ£»
(3)ʹÓÃjavah -jni Éú³É¸ÃÀà¶ÔÓ¦µÄCÓïÑÔ.hÎļþ£»
(4)ʹÓÃC/C++ʵÏÖ£¨3£©Éú³ÉµÄ.hÎļþÖÐÉùÃ÷µÄ¸÷º¯Êý£»
(5)±àÒëC/C++ʵÏÖ´úÂëÉú³É¶¯Ì¬Á¬½Ó¿â¡£
±¾ÎÄʹÓÃÒ»¸ö¼òµ¥µÄhelloWorldʾÀýÑÝʾJNIµÄʹÓá£
£¨1£©±àдJAVA´úÂë
public class helloWorld
{
public native void SayHello(String name);
static
{
System.loadLibrary("examdll");
}
public static void main(String [] argv)
{
helloWorld hello = new helloWorld();
hello.SayHello("myName");
}
}
£¨2£©±àÒëJAVA´úÂë
javac helloWorld.java
£¨3£©Éú³ÉʵÏÖº¯ÊýÍ·Îļþ
javah -classpath . helloWorld
µÃµ½µÄÎļþÄÚÈÝÈçÏ£º
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class helloWorld */
#ifndef _Included_helloWorld
#define _Included_helloWorld
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: helloWorld
* Method: SayHello
* Signature: (Ljava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_helloWorld_SayHello
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
£¨4£©ÔÚVCÖÐʵÏÖÉÏÊöº¯Êý
#include "helloWorld.h"
#include <stdio.h>
#include <string.h>
void JNICALL Java_helloWorld_SayHello(JNIEnv * env, jobject obj, jstring str)
{
jboolean b = true;
char s[80];
memset(s, 0, sizeof(s));
strcpy_s(s ,(char*)env->GetStringUTFChars(str, &b));
printf("Hello, %s", s);
env->ReleaseStringUTFChars(str , NULL);
}
**** ÕâÊ
Ïà¹ØÎĵµ£º
java exception ½â¾ö·½°¸ - ÎÒµÄÒì³£Íø|Òì³£|exception 730 - org.hibernate.LazyInitializationException:could not initialize proxy 731 - ¾¯¸æ: Error setting value 732 - override and commit 733 - Building workspace has encountered a problem. Errors during build 734 - Could not open the editor: An ......
ʵÑé1 Java¿ª·¢¹¤¾ß¼°³ÌÐòÉè¼Æ³õ²½
ʵÑéÄ¿µÄ
Äܹ»´î½¨JavaµÄ¿ª·¢»·¾³
ÊìϤ³£ÓõÄJDK²Ù×÷ÃüÁîµÄʹÓÃ
ÊìϤJava³ÌÐòµÄ±àдºÍ±àÒë¹ý³Ì
Á˽ⳣÓÃJava¿ª·¢¹¤¾ßµÄʹÓÃ
ʵÑéÄÚÈÝ
ʵÑéÁ·Ï°1£º´î½¨ºÍʹÓÃJDK
1£®JDKµÄÏÂÔغͰ²×°
JDKÊÇSUN¹«Ë¾Ãâ·ÑÔÚÍøÉÏ·¢²¼µÄ£¬ÎÒÃÇ¿ÉÒÔ½øÈ ......
´Ó¼Ü¹¹Éè¼Æ·½Ã濼ÂÇ£¬ºÜ¶àϵͳ²ÉÓÃÁË Java Bridge°ÑphpºÍJAVA¼¼Êõ½áºÏÆðÀ´£¬ÀûÓÃPHPµÄ¿ìËÙÏìÓ¦ºÍJAVAµÄÊý¾Ý³Ö¾Ã»¯ÄÜÁ¦£¬Äܴܺó³Ì¶ÈÉÏÄÜÌá¸ßϵͳÐÔÄÜ¡£ÕâÁ½ÆªÎÄÕ½«ÏêϸµÄ½éÉÜProject Zero¡¢WebSphere sMash ºÍ PHP µÄÕûºÏ¼¼Êõ
Project Zero¡¢WebSphere sMash ºÍ PHP ÈëÃÅ
http://www.ibm.com/developerworks/cn/web/wa- ......
import java.util.*;
public class ForeachExample {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Random r = new Random();
int[] x = new int[10];
for (int i = 0; i < x.length; i++) {
x[i] = r.nextInt(100);
}
/ ......
JAVAµÄ¿çƽ̨µÄÌØÐÔÉîÊÜjava³ÌÐòÔ±ÃǵÄϲ°®,µ«ÕýÊÇÓÉÓÚËüΪÁËʵÏÖ¿çƽ̨µÄÄ¿µÄ,ʹµÃËüºÍ±¾µØ»úÆ÷µÄ¸÷ÖÖÄÚ²¿ÁªÏµ±äµÃºÜÉÙ,´ó´óÔ¼ÊøÁËËüµÄ¹¦ÄÜ,±ÈÈçÓëһЩӲ¼þÉ豸ͨÐÅ,ÍùÍùÒª»¨·ÑºÜ´óµÄ¾«Á¦È¥Éè¼ÆÁ÷³Ì±àд´úÂëÈ¥¹ÜÀíÉ豸¶Ë¿Ú,¶øÇÒÓÐһЩÉ豸³§ÉÌÌṩµÄÓ²¼þ½Ó¿ÚÒѾ¾¹ýÒ»¶¨µÄ·â×°ºÍ´¦Àí,²»ÄÜÖ±½ÓʹÓÃjava³ÌÐòͨ¹ý¶Ë¿Úº ......