Javaµ¥Àýģʽ
×÷Ϊ¶ÔÏóµÄ´´½¨Ä£Ê½,µ¥Àýģʽȷ±£Ä³¸öÀàÖ»ÓÐÒ»¸öʵÀý£¬¶øÇÒ×ÔÐÐʵÀý»¯²¢ÏòÕû¸öϵͳÌṩÕâ¸öʵÀý¡£Õâ¸öÀà³ÆΪµ¥ÀýÀà¡£Óɶ¨Òå¿ÉÒÔ×ܽá³öµ¥ÀýģʽµÄÒªµãÓÐÈý¸ö£ºÒ»Êǵ¥ÀýÀàÖ»ÄÜÓÐÒ»¸öʵÀý£»¶þÊÇËü±ØÐë×ÔÐд´½¨Õâ¸öʵÀý£»ÈýÊÇËü±ØÐë×ÔÐÐÏòÕû¸öϵͳÌṩÕâ¸öʵÀý¡£
ÔÚ¼ÆËã»úϵͳÖУ¬Ï̳߳ء¢»º´æ¡¢ÈÕÖ¾¶ÔÏ󡢶Ի°¿ò¡¢´òÓ¡»ú¡¢ÏÔ¿¨µÄÇý¶¯³ÌÐò¶ÔÏó³£±»Éè¼Æ³Éµ¥Àý¡£ÕâЩӦÓö¼»ò¶à»òÉÙ¾ßÓÐ×ÊÔ´¹ÜÀíÆ÷µÄ¹¦ÄÜ¡£Ã¿Ì¨¼ÆËã»ú¿ÉÒÔÓÐÈô¸É¸ö´òÓ¡»ú£¬µ«Ö»ÄÜÓÐÒ»¸öPrinter Spooler£¬ÒÔ±ÜÃâÁ½¸ö´òÓ¡×÷ҵͬʱÊä³öµ½´òÓ¡»úÖС£Ã¿Ì¨¼ÆËã»ú¿ÉÒÔÓÐÈô¸ÉͨÐŶ˿ڣ¬ÏµÍ³Ó¦µ±¼¯ÖйÜÀíÕâЩͨÐŶ˿ڣ¬ÒÔ±ÜÃâÒ»¸öͨÐŶ˿Úͬʱ±»Á½¸öÇëÇóͬʱµ÷Óá£×ÜÖ®£¬Ñ¡Ôñµ¥Àýģʽ¾ÍÊÇΪÁ˱ÜÃâ²»Ò»ÖÂ״̬£¬±ÜÃâÕþ³ö¶àÍ·¡£
Ê×ÏÈ¿´Ò»¸ö¾µäµÄµ¥ÀýʵÏÖ¡£
public class Singleton {
private static Singleton uniqueInstance = null;
private Singleton() {
// Exists only to defeat instantiation.
}
public static Singleton getInstance() {
if (uniqueInstance == null) {
uniqueInstance = new Singleton();
}
return uniqueInstance;
}
// Other methods...
}
Singletonͨ¹ý½«¹¹Ôì·½·¨ÏÞ¶¨Îªprivate±ÜÃâÁËÀàÔÚÍⲿ±»ÊµÀý»¯£¬ÔÚͬһ¸öÐéÄâ»ú·¶Î§ÄÚ£¬SingletonµÄΨһʵÀýÖ»ÄÜͨ¹ýgetInstance()·½·¨·ÃÎÊ¡££¨ÊÂʵÉÏ£¬Í¨¹ýJava·´Éä»úÖÆÊÇÄܹ»ÊµÀý»¯¹¹Ôì·½·¨ÎªprivateµÄÀàµÄ£¬ÄÇ»ù±¾ÉÏ»áʹËùÓеÄJavaµ¥ÀýʵÏÖʧЧ¡£´ËÎÊÌâÔÚ´Ë´¦²»×öÌÖÂÛ£¬¹ÃÇÒÑÚ¶úµÁÁåµØÈÏΪ·´Éä»úÖƲ»´æÔÚ¡££©
µ«ÊÇÒÔÉÏʵÏÖûÓп¼ÂÇḬ̈߳²È«ÎÊÌâ¡£ËùνḬ̈߳²È«ÊÇÖ¸£ºÈç¹ûÄãµÄ´úÂëËùÔڵĽø³ÌÖÐÓжà¸öÏß³ÌÔÚͬʱÔËÐУ¬¶øÕâЩÏ߳̿ÉÄÜ»áͬʱÔËÐÐÕâ¶Î´úÂë¡£Èç¹ûÿ´ÎÔËÐнá¹ûºÍµ¥Ïß³ÌÔËÐеĽá¹ûÊÇÒ»ÑùµÄ£¬¶øÇÒÆäËûµÄ±äÁ¿µÄÖµÒ²ºÍÔ¤ÆÚµÄÊÇÒ»ÑùµÄ£¬¾ÍÊÇḬ̈߳²È«µÄ¡£»òÕß˵£ºÒ»¸öÀà»òÕß³ÌÐòËùÌṩµÄ½Ó¿Ú¶ÔÓÚÏß³ÌÀ´ËµÊÇÔ×Ó²Ù×÷»òÕ߶à¸öÏß³ÌÖ®¼äµÄÇл»²»»áµ¼Ö¸ýӿڵÄÖ´Ðнá¹û´æÔÚ¶þÒåÐÔ,Ò²¾ÍÊÇ˵ÎÒÃDz»Óÿ¼ÂÇͬ²½µÄÎÊÌâ¡£ÏÔÈ»ÒÔÉÏʵ
Ïà¹ØÎĵµ£º
ÀàµÄ³õʼ»¯ºÍ¶ÔÏó³õʼ»¯ÊÇ JVM ¹ÜÀíµÄÀàÐÍÉúÃüÖÜÆÚÖзdz£ÖØÒªµÄÁ½¸ö»·½Ú£¬Google ÁËÒ»±éÍøÂ磬ÓйØÀà×°ÔØ»úÖƵÄÎÄÕµ¹ÊDz»ÉÙ£¬È»¶øÀà³õʼ»¯ºÍ¶ÔÏó³õʼ»¯µÄÎÄÕ²¢²»¶à£¬ÌرðÊÇ´Ó×Ö½ÚÂëºÍ JVM ²ã´ÎÀ´·ÖÎöµÄÎÄÕ¸üÊÇÏÊÓÐËù¼û¡£
±¾ÎÄÖ÷Òª¶ÔÀàºÍ¶ÔÏó³õʼ»¯È«¹ý³Ì½øÐзÖÎö£¬Í¨¹ýÒ»¸öʵ¼ÊÎÊÌâÒýÈ룬½«Ô´´úÂëת»»³É JVM ×Ö½ÚÂëºó£¬ ......
package cn.test;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* Java Reflection Cookbook
*
* @author Michael Lee
* @since 2006-8-23
* ......
×Ô java ƽ̨´Ó 1995 Äê×÷Ϊһ¸öÕûÌåÒýÈë±à³ÌÉçÇø¿ªÊ¼£¬ËüµÄ·¢Õ¹ÒѾԶԶ³¬³öÁËÔçÆÚ java ר¼ÒºÍÍƽéÕßËùÉèÏëµÄ“applet ÎÞ´¦²»ÔÚ”ÕâÒ»Ô¶¾°¡£Ïà·´£¬java ÊÀ½ç³öÏÖÁË Swing¡¢Óë servlet ½áºÏ£¬´Ó¶ø·¢Õ¹Îª J2EE¡¢³öÏÖÁË EJB¡¢³¬Ô½ÁË Spring ºÍ Hibernate¡¢Ìí¼ÓÁË·ºÐÍ£¬±äµÃÔ½À´Ô½¾ßÓж¯Ì¬ÐÔ£¬È»ºóʵÏÖÁ˺¯Êý»¯£¬ÔÚ ......
ÎÊ:
È·ÈÏÒ»ÏÂc++Öв»ÄÜʹÓÃinterface£¨Èçjava£©ÄÇÑùµÄ¹¦ÄÜ°Ñ
ÎÒÈÏΪÊDz»Äܵģ¬×¢ÒâÎÒ˵µÄÊÇinterface£¨ÓÃÓÚjava¶àÖؼ̳еÄÄǸö£¬²»ÊÇÒ»°ãÒâÒåµÄ½Ó¿Ú£©
ÎÒ¾õµÃÊÇûÓеģ¬µ«ÊÇÍøÉÏËÑË÷˵ʲôµÄ¶¼ÓжøÇÒÈË»¹²»ÉÙ…… ËùÒÔÏ£Íû´ó¼ÒÄܸøÎÒÒ»¸öÃ÷È·µÄ´ð¸´ºÃô£¿×îºÃÄÜ»¹ÓÐһР......
Êý×éÊôÒýÓÃÀàÐÍ£¬Êý×éÐÍÊý¾ÝÊǶÔÏó(object)£¬Êý×éÖеÄÿ¸öÔªËØÏ൱ÓڸöÔÏóµÄ³ÉÔ±±äÁ¿
Êý×éÖеÄÔªËØ¿ÉÒÔÊÇÈκÎÊý¾ÝÀàÐÍ£¬°üÀ¨»ù±¾ÀàÐͺÍÒýÓÃÀàÐÍ
¼ÇסÊý×éÊ×ÏÈ·ÖÅä¿Õ¼äÔÙ¸³Öµ£¡
¶¯Ì¬³õʼ»¯£º¾ÍÊÇÏÈ·ÖÅä¿Õ¼äÔÙ¸³³õÖµ£»
¾²Ì¬³õʼ»¯£º¶¨ÒåÊý×éͬʱ¾ÍΪÊý×éÔªËØ·ÖÅä¿Õ¼ä²¢¸³Öµ¡£
1һάÊý×éµÄÉùÃ÷
һάÊý×éµÄÉùÃ÷£ºtype va ......