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 ......
ÎÄÕÂÓÃʵÀý´úÂëչʾÁËJavaÖжàÏ̷߳ÃÎʹ²Ïí×ÊÔ´
ʱÏß³Ìͬ²½
µÄÖØÒªÐÔ¡£
·Ö±ðͨ¹ýÔÚÁ½¸öÏß³ÌÖÐͬʱ·ÃÎÊ(µ÷ÓÃget_id*·½·¨)¾¹ýͬ²½´¦Àí(lock¼°Synchronized)µÄ¹²Ïí×ÊÔ´(tmp)¼°Î´¾¹ýͬ²½´¦ÀíµÄ¹²Ïí×ÊÔ´(tmp)À´ËµÃ÷ͬ²½´¦ÀíµÄµÄ×÷Óá£
mainÖзÖÁ½²¿·Ö:
1£©Ç°°ë²¿·Ö£¬non-synchronization²¿·ÖÓÃÀ´²âÊÔûÓÐ×öͬ²½´¦ÀíµÄ´úÂë ......
1.Java ¼¯ºÏ¿ò¼Üͼ
¡¡¡¡-¼¯ºÏ½Ó¿Ú£º6¸ö½Ó¿Ú£¨¶ÌÐéÏß±íʾ£©£¬±íʾ²»Í¬¼¯ºÏÀàÐÍ£¬ÊǼ¯ºÏ¿ò¼ÜµÄ»ù´¡¡£
¡¡¡¡-³éÏóÀࣺ5¸ö³éÏóÀࣨ³¤ÐéÏß±íʾ£©£¬¶Ô¼¯ºÏ½Ó¿ÚµÄ²¿·ÖʵÏÖ¡£¿ÉÀ©Õ¹Îª×Ô¶¨Ò弯ºÏÀà¡£
¡¡¡¡-ʵÏÖÀࣺ8¸öʵÏÖÀࣨʵÏß±íʾ£©£¬¶Ô½Ó¿ÚµÄ¾ßÌåʵÏÖ¡£
¡¡¡¡2.JavaÈÝÆ÷Àà½éÉÜ
¡¡¡¡¢Ù JavaÈÝÆ÷À඼¿ÉÒÔ×Ô¶¯µØµ÷Õû×Ô¼ºµÄ³ß´ ......
Ò»¡¢²»±äģʽ£º
Ò»¸ö×Ö·û´®¶ÔÏó´´½¨ºóËüµÄÖµ²»Äܸı䡣
String str1="hello";//´´½¨Ò»¸ö¶ÔÏóhello£¬²»»á±ä£»
System.out.println(str1);
str1+=" world!";//Á½¸ö×Ö·û´®¶ÔÏóÕ³Õ³£¬ÏµÍ³Æäʵ´´½¨ÁËÒ»¸öеĶÔÏ󣬰ÑStr1µÄÖ¸Ïò¸ÄÁË£¬Ö¸ÏòеĶÔÏó£»hello¾Í & ......