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

¹ØÓÚJavaµÄsingletonģʽµÄ½éÉÜ,±È½ÏÓÐÓÃ

JavaÉè¼Æģʽ֮Singletonµ¥Àýģʽƪ
java µ¥ÀýģʽµÄʵÏÖ·½Ê½
ʵÏÖ1£º
public class Singleton {    
     private static Singleton instance;
      private Singleton (){ //Ê×ÏÈÓÐÒ»¸ö˽ÓеĹ¹ÔìÆ÷
       }
     public static Singleton getInstance() {
     if(instance==null){
         instance=new Singleton ();
      }
      return instance;
     }
}
ÕâÖÖ·½Ê½ÊÇÏ̲߳»°²È«µÄ£¬Èç¹û¶à¸öÏß³Ìͬʱ·ÃÎʵĻ°¾Í¿ÉÄÜÓжà¸ö¶ÔÏó²úÉú£¬Èç¹ûÔÚget·½·¨ÖмÓͬ²½¿éµÄ»°»áÓ°ÏìÐÔÄÜ¡£
ʵÏÖ2£º
public class Singleton {
private Singleton(){
}
private static Singleton instance =new Singleton();
public static Singleton getInstance(){
return instance;
}
}
ÕâÖÖ·½Ê½ËäÈ»²»´æÔÚ°²È«ÐÔÎÊÌ⣬µ«ÊÇÔÚ³ÌÐòÆô¶¯µÄʱºò¾Í»á³õʼ»¯¡£
ʵÏÖ3£º
public class Singleton {
private static class SingletonHolder {
static Singleton instance = new Singleton();
}
public static Singleton getInstance() {
return SingletonHolder.instance;
}
}
3ÖÖ·½Ê½ÖÐÕâÊÇ×îºÃµÄ½â¾ö·½°¸£¬¼È½â¾öÁËÏß³Ìͬ²½µÄÎÊÌ⣬ÓÐÔÚµ÷ÓõÄʱºò²Å³õʼ»¯¡£
µ¥ÀýģʽÖ÷ÒªÓÐ3¸öÌص㣬£º
1¡¢µ¥ÀýÀàÈ·±£×Ô¼ºÖ»ÓÐÒ»¸öʵÀý¡£
2¡¢µ¥ÀýÀà±ØÐë×Ô¼º´´½¨×Ô¼ºµÄʵÀý¡£
3¡¢µ¥ÀýÀà±ØÐëΪÆäËû¶ÔÏóÌṩΨһµÄʵÀý¡£
ʲôʱºòʹÓõ¥Àýģʽ£¿
µ¥ÀýģʽҲÊÇÒ»ÖֱȽϳ£¼ûµÄÉè¼Æģʽ£¬Ëüµ½µ×ÄÜ´ø¸øÎÒÃÇʲôºÃ´¦ÄØ£¿ÆäʵÎÞ·ÇÊÇÈý¸ö·½ÃæµÄ×÷Óãº
µÚÒ»¡¢¿ØÖÆ×ÊÔ´µÄʹÓã¬Í¨¹ýÏß³Ìͬ²½À´¿ØÖÆ×ÊÔ´µÄ²¢·¢·ÃÎÊ£»
µÚ¶þ¡¢¿ØÖÆʵÀý²úÉúµÄÊýÁ¿£¬´ïµ½½ÚÔ¼×ÊÔ´µÄÄ¿µÄ¡£
µÚÈý¡¢×÷ΪͨÐÅý½éʹÓã¬Ò²¾ÍÊÇÊý¾Ý¹²Ïí£¬Ëü¿ÉÒÔÔÚ²»½¨Á¢Ö±½Ó¹ØÁªµÄÌõ¼þÏ£¬Èöà¸ö²»Ïà¹ØµÄÁ½¸öÏ̻߳òÕß½ø³ÌÖ®¼äʵÏÖͨÐÅ¡£
±È È磬Êý¾Ý¿âÁ¬½Ó³ØµÄÉè¼ÆÒ»°ã²ÉÓõ¥Àýģʽ£¬Êý¾Ý¿âÁ¬½ÓÊÇÒ»ÖÖÊý¾Ý¿â×ÊÔ´¡£Èí¼þϵͳÖÐʹÓÃÊý¾Ý¿âÁ¬½Ó³Ø£¬Ö÷ÒªÊǽÚÊ¡´ò¿ª»òÕ߹رÕÊý¾Ý¿âÁ¬½ÓËùÒýÆðµÄЧÂÊËð ºÄ£¬ÕâÖÖЧÂÊÉϵÄËðºÄ»¹ÊǷdz£°º¹óµÄ¡£µ±È»£¬Ê¹ÓÃÊý¾Ý¿âÁ¬½Ó³Ø»¹ÓкܶàÆäËüµÄºÃ´¦£¬¿ÉÒÔÆÁ±Î²»Í¬Êý¾ÝÊý¾Ý¿âÖ®¼äµÄ²îÒ죬ʵÏÖϵͳ¶ÔÊý¾Ý¿âµÄµÍ¶ÈñîºÏ£


Ïà¹ØÎĵµ£º

×ö3G¿ª·¢ÊÇѧJava»¹ÊÇC++

ÓкܶàѧÉúÎÊÎÒ,ÏÖÔÚ 3GÒƶ¯»¥ÁªÍø·¢Õ¹Ö®ÊÆÍ·±Ø½«ÊÇITÁìÓò·¢Õ¹Ê®ÄêÒ»ÓöµÄÄѵûúÓö£¬ÏëͶÉíµ½¸ÃÐÐÒµÖУ¬²»ÖªµÀÊÇÓ¦¸ÃѧÍøÂç¡¢»¹ÊÇѧǶÈëʽÉ豸¿ª·¢¡¢»¹ÊÇѧϰһÏÂJava,C++Ó¦Óÿª·¢£¬»¹ÊÇѧϰһÏ¿ªÔ´¿ò¼ÜAndroid?
 
´ÓÎÒ¸öÈ˶ÔÐÐÒµµÄÀí½âÀ´½²£¬Òƶ¯»¥ÁªÍøµÄ·¢Õ¹Ò»¶¨ÊÇÏÈ´ÓÍøÂ翪ʼ£¬ÍøÂçÉ豸ÌṩÉÌ¡¢Ð­ÒéµÄ¿ª·¢»ú¹¹£¨ ......

»ªÎªJava±ÊÊÔÌâ

Ò»¡¢ µ¥ÏîÑ¡ÔñÌâ
¡¡¡¡1£®JavaÊÇ´Ó£¨ £©ÓïÑԸĽøÖØÐÂÉè¼Æ¡£
¡¡¡¡A£®Ada B£®C++ C£®Pasacal D£®BASIC
¡¡¡¡´ð°¸£ºB
¡¡¡¡
¡¡¡¡2£®ÏÂÁÐÓï¾äÄÄÒ»¸öÕýÈ·£¨ £©
¡¡¡¡A£® Java³ÌÐò¾­±àÒëºó»á²úÉúmachine code
¡¡¡¡B£® Java³ÌÐò¾­±àÒëºó»á²úÉúbyte code
¡¡¡¡C£® Java³ÌÐò¾­±àÒëºó»á²úÉúDLL
¡¡¡¡D£® ÒÔÉ϶¼²»ÕýÈ·
¡¡¡¡´ð°¸£ºB ......

javaÖеĴúÂë¿éÀí½â

´úÂë¿é£º¾ÍÊÇÓÃ{}À¨ÆðÀ´µ½²¿·Ö¡£¸ù¾ÝÓ¦ÓõIJ»Í¬·ÖΪ4Àà:ÆÕͨ´úÂë¿é¡¢¹¹Ôì¿é¡¢¾²Ì¬´úÂë¿é¡¢Í¬²½´úÂë¿é¡£
1.ÆÕͨ´úÂë¿é£º¶¨ÒåÔÚ·½·¨ÖеĴúÂë¿é¡£
È磺
public class Ex22 {
public static void main(String[] args){
// ÆÕͨ´úÂë¿é
{
int i = 3;
System.out.println("¾Ö²¿±äÁ¿Îª " + i);
}
int i = 5 ......

JAVA annotationÈëÃÅ

JAVA annotationÈëÃÅ 
        ×î½ü¶ÔspringÔ´Âë¸ÐÐËȤ£¬½ñÌì¿´µ½annotation²¿·Ö£¬ÂÔ¼ÇÖ®¡£
Ò». ×î³£¼ûµÄannotation
@Override:ÓÃÔÚ·½·¨Ö®ÉÏ£¬ÓÃÀ´¸æËß±ðÈËÕâÒ»¸ö·½·¨ÊǸÄд¸¸ÀàµÄ
@Deprecated:½¨Òé±ðÈ˲»ÒªÊ¹ÓþɵÄAPIµÄʱºòÓõÄ,±àÒëµÄʱºò»áÓòúÉú¾¯¸æÐÅÏ¢,¿ÉÒÔÉ趨ÔÚ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ