JAVA·´Éä»úÖÆ
JAVA·´Éä»úÖÆ
¸ÅÊö
¡¡¡¡ÓÐʱºòÎÒÃÇ˵ij¸öÓïÑÔ¾ßÓкÜÇ¿µÄ¶¯Ì¬ÐÔ£¬ÓÐʱºòÎÒÃÇ»áÇø·Ö¶¯Ì¬ºÍ¾²Ì¬µÄ²»Í¬¼¼ÊõÓë×÷·¨¡£ÎÒÃÇÀÊÀÊÉÏ¿Ú¶¯Ì¬°ó¶¨£¨dynamic binding£©¡¢¶¯Ì¬Á´½Ó£¨dynamic linking£©¡¢¶¯Ì¬¼ÓÔØ£¨dynamic loading£©µÈ¡£È»¶ø“¶¯Ì¬”Ò»´ÊÆäʵûÓоø¶Ô¶øÆÕ±éÊÊÓõÄÑϸñ¶¨Ò壬ÓÐʱºòÉõÖÁÏñ¶ÔÏóµ¼Ïòµ±³õ±»µ¼Èë±à³ÌÁìÓòÒ»Ñù£¬Ò»ÈËÒ»°ÑºÅ£¬¸÷´µ¸÷µÄµ÷¡£
¡¡¡¡Ò»°ã¶øÑÔ£¬¿ª·¢ÕßÉçȺ˵µ½¶¯Ì¬ÓïÑÔ£¬´óÖÂÈÏͬµÄÒ»¸ö¶¨ÒåÊÇ£º“³ÌÐòÔËÐÐʱ£¬ÔÊÐí¸Ä±ä³ÌÐò½á¹¹»ò±äÁ¿ÀàÐÍ£¬ÕâÖÖÓïÑÔ³ÆΪ¶¯Ì¬ÓïÑÔ”¡£´ÓÕâ¸ö¹Ûµã¿´£¬Perl£¬Python£¬RubyÊǶ¯Ì¬ÓïÑÔ£¬C++£¬Java£¬C#²»ÊǶ¯Ì¬ÓïÑÔ¡£
¡¡¡¡¾¡¹ÜÔÚÕâÑùµÄ¶¨ÒåÓë·ÖÀàÏÂJava²»ÊǶ¯Ì¬ÓïÑÔ£¬ËüÈ´ÓÐ×ÅÒ»¸ö·Ç³£Í»³öµÄ¶¯Ì¬Ïà¹Ø»úÖÆ£ºReflection¡£Õâ¸ö×ÖµÄÒâ˼ÊÇ“·´Éä¡¢Ó³Ïó¡¢µ¹Ó°”£¬ÓÃÔÚJavaÉíÉÏÖ¸µÄÊÇÎÒÃÇ¿ÉÒÔÓÚÔËÐÐʱ¼ÓÔØ¡¢Ì½Öª¡¢Ê¹ÓñàÒëÆÚ¼äÍêȫδ֪µÄclasses¡£»»¾ä»°Ëµ£¬Java³ÌÐò¿ÉÒÔ¼ÓÔØÒ»¸öÔËÐÐʱ²ÅµÃÖªÃû³ÆµÄclass£¬»ñϤÆäÍêÕû¹¹Ô죨µ«²»°üÀ¨methods¶¨Ò壩£¬²¢Éú³ÉÆä¶ÔÏóʵÌå¡¢»ò¶ÔÆäfieldsÉèÖµ¡¢»ò»½ÆðÆämethods1¡£ÕâÖÖ“¿´Í¸class”µÄÄÜÁ¦£¨the ability of the program to examine itself£©±»³ÆΪintrospection£¨ÄÚÊ¡¡¢ÄÚ¹Û¡¢·´Ê¡£©¡£ReflectionºÍintrospectionÊdz£±»²¢ÌáµÄÁ½¸öÊõÓï¡£
¡¡¡¡JavaÈçºÎÄܹ»×ö³öÉÏÊöµÄ¶¯Ì¬ÌØÐÔÄØ£¿ÕâÊÇÒ»¸öÉîÔ¶»°Ì⣬±¾ÎĶԴËÖ»¼òµ¥½éÉÜһЩ¸ÅÄî¡£Õû¸öƪ·ù×îÖ÷Òª»¹ÊǽéÉÜReflection APIs£¬Ò²¾ÍÊÇÈöÁÕßÖªµÀÈçºÎ̽Ë÷classµÄ½á¹¹¡¢ÈçºÎ¶Ôij¸ö“ÔËÐÐʱ²Å»ñÖªÃû³ÆµÄclass”Éú³ÉÒ»·ÝʵÌ塢ΪÆäfieldsÉèÖµ¡¢µ÷ÓÃÆämethods¡£±¾ÎĽ«Ì¸µ½java.lang.Class£¬ÒÔ¼°java.lang.reflectÖеÄMethod¡¢Field¡¢ConstructorµÈµÈclasses¡£
“Class”class
¡¡¡¡ÖÚËùÖÜÖªJavaÓиöObject class£¬ÊÇËùÓÐJava classesµÄ¼Ì³Ð¸ùÔ´£¬ÆäÄÚÉùÃ÷ÁËÊý¸öÓ¦¸ÃÔÚËùÓÐJava classÖб»¸ÄдµÄmethods£ºhashCode()¡¢equals()¡¢clone()¡¢toString()¡¢getClass()µÈ¡£ÆäÖÐgetClass()·µ»ØÒ»¸öClass object¡£
¡¡¡¡Class classÊ®·ÖÌØÊâ¡£ËüºÍÒ»°ãclassesÒ»Ñù¼Ì³Ð×ÔObject£¬ÆäʵÌåÓÃÒÔ±í´ïJava³ÌÐòÔËÐÐʱµÄclassesºÍinterfaces£¬Ò²ÓÃÀ´±í´ïenum¡¢array¡¢primitive Java types£¨boolean, byte, char, short, int, long, float, double£©ÒÔ¼°¹Ø¼ü´Êvoid¡£µ±Ò»¸öclass±»¼ÓÔØ£¬»òµ±¼ÓÔØÆ÷£¨class loader£©µÄdefineClass()±»JVMµ÷Óã¬JVM ±ã×Ô¶¯²úÉúÒ»¸öClass object¡£Èç¹ûÄúÏë
Ïà¹ØÎĵµ£º
ÌâÄ¿¶¼ºÜ¼òµ¥,µ«ÓÐʱºòÈÃÄãÓñÊÍêÕûµÄд³öÀ´È´²»ÄÇôÈÝÒ×ÁË.
1.±éÀúÎļþ¼Ð(±»Õâ¸öÌâÄ¿¿¼ÁËÁ½´Î)
import java.io.File;
public class ListFile {
public static void main(String[] args) {
// TODO Auto-generated method stub
String path = "C:/Inetpub";
File f = new File(path);
list(f);
}
publ ......
ÀûÓÃJNI¼¼Êõ£¬¿ÉÒÔ×öµ½C/C++ÓëJavaÖ®¼äµÄÏ໥µ÷Óá£
1¡¢Javaµ÷ÓÃC/C++½Ó¿Ú
Õâ¸öÊÇJNI×î»ù±¾µÄÓ¦Óã¬JNIÓкܶàÕâ·½ÃæµÄÀý×Ó´úÂë¡£Ò»°ã°ÑC/C++д³É¶¯Ì¬Á´½Ó¿â£»ÔÚJava³ÌÐòÔÚLoadLibrary£¬ÀûÓÃnative½Ó¿Ú£¬¼´¿ÉÍê³Éµ÷Óá£
2¡¢C/C++»Øµ÷Java½Ó¿Ú
ÕâÖÖÓ÷¨£¬JNIµÄÀý×ӱȽÏÉÙ¡£Æäʵ£¬Ò²±È½Ï¼òµ¥£¬JNIÒ²ÌṩÁËÕâÑùµÄ½Ó¿Ú¡ ......
Ò»¡¢²»±äģʽ£º
Ò»¸ö×Ö·û´®¶ÔÏó´´½¨ºóËüµÄÖµ²»Äܸı䡣
String str1="hello";//´´½¨Ò»¸ö¶ÔÏóhello£¬²»»á±ä£»
System.out.println(str1);
str1+=" world!";//Á½¸ö×Ö·û´®¶ÔÏóÕ³Õ³£¬ÏµÍ³Æäʵ´´½¨ÁËÒ»¸öеĶÔÏ󣬰ÑStr1µÄÖ¸Ïò¸ÄÁË£¬Ö¸ÏòеĶÔÏó£»hello¾Í & ......
JAVA_HOME:
C:\Java\jdk1.6.0_17
Path:
%JAVA_HOME%\bin
ClassPath:
.;%JAVA_HOME%\lib\tools.jar;%JAVA_HOME%\lib\dt.jar
ÎÒÃÇÐèÒªÉèÖÃÈý¸ö»·¾³±äÁ¿£ºJAVA_HOME¡¢PATH ºÍ CLASSPATH¡£
JAVA_HOME£º¸Ã»·¾³±äÁ¿µÄÖµ¾ÍÊÇ Java ËùÔÚµÄĿ¼£¬Ò»Ð© Java °æµÄÈí¼þºÍÒ»
Щ Java µÄ¹¤¾ßÐèÒªÓõ½¸Ã±äÁ¿£¬ÉèÖà PATH ºÍ CLASSP ......
Java³£ÓÃ×Ö·û¼¯±àÂëÏê½â
Web¿ª·¢µÄʱºò¾³£»áÓöµ½Ò»Ð©×Ö·û±àÂëµÄ´íÎó£¬ÈçÒ³ÃæÂÒÂëµÈÎÊÌ⣬ËùÒÔÓбØÒªÐè¶Ô×Ö·û±àÂëÓÐËùÁ˽⣬ÒÔÏÂÊÇRickiÊÕ¼¯µÄһЩ×ÊÁÏ£¨¿ÉÄܲ»ÊǺÜÈ«£¬µ«Ï£Íû¶ÔÄãÓÐËù°ïÖú£©
Java±ê×¼×Ö·û¼¯£ºËùνJava±ê×¼×Ö·û¼¯£¬¾ÍÊÇJavaƽ̨֧³ÖµÄ×Ö·û ......