Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

ÓïÑÔ»ì±àÖ®javaµ÷ÓÃc dll jni¼¼ÊõСÊÔ

¸Õ´ÓÍøÉÏ¿´µ½cºÍjava»ì±àµÄÎÄÕ£¬¾Íؽ²»¿É´ýµÄ³¢ÊÔÁËһϡ£ºÇºÇ£¬Ð§¹û»¹ÊǺܺõġ£ÏÂÃ潫×Ô¼º³É¹ûÕ³Ìù³öÀ´
£¨×ªÔØÓÚhttp://www.zxbc.cn/html/20070518/19986.html£©¡£ÊµÑéÖ®ºó¿ÉÒÔͨ¹ý¡£
1javaÖе÷ÓÃcÓïÑÔ
Ê×ÏȱàдMain.java
public class Main 
{
 public native static int getStrNum(byte str[], int strLen);

ÔÚÃüÁîÐÐÖУ¬Ê¹ÓÃÈçÏÂÃüÁî±àÒ룺
javac Main.java 
ÏÂÃæµÄÃüÁÉú³ÉMain.hÍ·Îļþ
javah Main 
´ò¿ªvs2008£¬ н¨¹¤³ÌMakeDll£¨win32 console application£©£¬ÉèÖÃÏîÄ¿ÊôÐÔÈçÏ£º
ÔÚproject-¡·MakeDll Properties-¡·ÔÚGeneralÑ¡ÏÉÏ£¬Ñ¡ÔñÉú³ÉdllÎļþ¡£
ͬʱÐèÒªÔÚÏîÄ¿µÄc++ÏÂgeneralϵÄAdditional include directoryϼÓÔØjdk°²×°Ä¿Â¼ÏµÄincludeÎļþ¼ÐºÍ¸ÃÎļþ¼ÐϵÄwin32
×ÓĿ¼¡£
½«µÚÒ»²½Éú³ÉµÄMain.hÎļþ¼ÙÈçµ½¹¤³ÌÖУ¬Í¬Ê±Ð½¨Ò»¸ömain.cppÎļþ£¬ÔÚÆäÖмÙÈçÈçÏ´úÂ룺
#include "Main.h"
#include <string.h>
JNIEXPORT jint JNICALL Java_Main_getStrNum  (JNIEnv *env, jclass cls, jbyteArray str, jint strLen) 

 jbyte *buffer = (*env).GetByteArrayElements(str, 0); 
 buffer[strLen] = ' '; 
 jint len = strlen((char*)buffer); 
 
 return len; 

±àÒë¼´¿ÉÉú³ÉMakeDll.dllÎļþ¡£
ÔÚjavaÔ´ÎļþÖе÷ÓøÃdllÎļþ£¨×¢ÒâÐèÒª½«dllÎļþºÍ±àÒëµÄclassÎļþ·ÅÖÃÔÚͬһ¸öÎļþ¼ÐÏÂÃ棩
javaÔ´Îļþ´úÂëÈçÏ£º
public class Main
{
 static
 {
  System.loadLibrary ("MakeDll");
 }
 
 public native static int getStrNum (byte[] str, int strLen);
 
 public static void main (String[] args)
 {
  Main instance = new Main ();
  String str = new String ("haha");
  int num = instance.getStrNum (str.getBytes (), str.length ());
  System.out.println (num);
 }
}
±àÒë¸ÃjavaÔ´Îļþ£¬Í¬Ê±Ö´ÐиÃÎļþ¡£
javac Main.java
java Main
¼´¿ÉÊä³öÏàÓ¦½á¹û¡£


Ïà¹ØÎĵµ£º

java¹æÔ¼


1£® ¹ØÓÚ»ù´¡Êý¾ÝÀàÐÍ¡£
»¹¼ÇµÃÉÏһƬÎÄÕÂÖнáβ²¿·ÖµÄÄǸöÀý×Óô£¿
ÒòΪ¼ÆËã»úµÄ2½øÖƵÄÌØÐÔ£¬JavaÓïÑÔ£¨ÆäËûÓïÑÔºÃÏñÒ²Ò»Ñù£©ÎÞ·¨×¼È·µØ½øÐÐfloat,doubleÀàÐÍÊý¾ÝµÄ¼ÆË㣬ËùÒÔ£¬×÷ÕâЩ¼ÆËãµÄʱºòÐèÒª¿¼ÂÇʹÓÃBigDecimalן÷Àà¡£
 
2£® StringÀàÓëStringBufferÀà
JavaµÄStringÀàÌṩÈçϵļòµ¥µÄ×Ö·û´®Á¬½Ó·½· ......

Java URLClassLoader

Closing a URLClassLoader
By Michael McMahon
 
Complex Java programs, such as application servers, sometimes create their own class loaders using the URLClassLoader type. With URLClassLoader, applications can load classes and resources from a search path of URLs. The following URL types are ......

ÔÚjavaÖÐʹÓÃkey valueÐÍÊý¾Ý¿âBerkeley DB

³ýÁ˹ØϵÐÍÊý¾Ý¿âÍ⣬»¹ÓÐkey-valueÐÍÊý¾Ý¿â¿ÉÒÔÑ¡Ôñ£¬ÔÚ´óÐ͵IJéѯϵͳÖУ¬key-valueÐÍÊý¾Ý¿â¿ÉÒÔ³öÉ«µÄÍê³ÉijЩÈÎÎñ¡£
OracleµÄBerkeley DB¾ÍÊÇÒ»ÖÖkey-valueÐÍÊý¾Ý¿â£¬±¾ÎļòÒª½éÉÜÔÚjavaÖÐʹÓÃBerkeley DB¡£
PartKey.java:
import java.io.Serializable;
public class PartKey implements Serializable
{
priva ......

JavaºÍC++³ÌÐòÔ±´ýÓöÎÊÌâ

      ×î½ü°àÀïµÄͬѧ¶¼Ã¦×ű¨°à£¬Óиö´ïÄÚÊÇjavaÅàѵ£¬ÓиöÉîÀ¶ÊÇC++Åàѵ£¬ÍøÉÏ¿´ÁËЩÌû×Ó˵ʲôµÄ¶¼ÓУ¬×ÔÎҸоõÅàÑøÒ»¸öC++³ÌÐòÔ±µÄÖÜÆÚÒª±ÈÅàÑøÒ»¸öjAVA³ÌÐòÔ±µÄÖÜÆÚ³¤ºÜ¶à£¬µ±È»£¬C++ÒªÊÇѧµÄºÃµÄ»°¿Ï¶¨±ÈѧjavaµÄÅ££¬µ«ÊǸ¶³öµÄ´ú¼Û¸öÈËÈÏΪÊÇÓкܴó²î¾àµÄ¡£¶ÔÓÚÏÖÔÚÊг¡É϶ÔÓÚÓïÑÔµÄÐèÇóÒ² ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ