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

Effective Java ѧϰ±Ê¼Ç£¨5£©

¾¡Á¿¸´ÓöÔÏ󣬶ø²»ÊÇ´´½¨ÐµĶÔÏó£¬ÌرðÊǵ±Ò»¸ö¶ÔÏóÊÇimmutable£¨²»¿É¸Ä±ä£©µÄʱºò¡£
ÈçString¶ÔÏó£¬
String s= new String(“String”);   ǧÍò²»ÒªÕâÑù×ö£¬ÒòΪÕâÀïʵ¼ÊÉÏ´´½¨ÁËÁ½¸ö¶ÔÏó¡£
Òª±ÜÃâ³öÏÖÕâÑùµÄÇé¿ö£¬
1ÊÇ¿ÉÒÔÓþ²Ì¬¹¤³§º¯Êý£¬À´½â¾ö£¬ÈçÀà¿âÖеÄBoolean.valueOf(“true”)£¬ÕâÖÖ·½Ê½ÒªÓÅÓÚnew Boolean(“true”);
2.ÊǾ¡Á¿¸´ÓöÔÏó¡£
¿´ÊéÖеÄÀý×Ó¡£
public class Person {
          private final Date birthDate;
          public boolean isBabyBoomer() {
              Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
               gmtCal.set(1946, Calendar.JANUARY, 1, 0, 0, 0);
               Date boomStart = gmtCal.getTime();
               gmtCal.set(1965, Calendar.JANUARY, 1, 0, 0, 0);
               Date boomEnd = gmtCal.getTime();
               return birthDate.compareTo(boomStart) >= 0 && birthDate.compareTo(boomEnd) < 0;
         }
}
ÕâÀÿ´Îµ÷ÓÃisBabyBoomer¾Í»á´´½¨Á½¸öData¶ÔÏó£¬Ò»¸öCalendar¶ÔÏóºÍTimeZone¶ÔÏó.
¸Ä½ø°æ£º
class Person {
                    private final Date birthDate;
                   
             private static final Date BOOM_START;
    &nb


Ïà¹ØÎĵµ£º

JAVA¿ªÔ´´óÈ«

 
Beanshell  ¡¾Java¿ªÔ´ ¶¯Ì¬ÓïÑÔ¡¿
BeanshellÊÇÓÃJavaд³ÉµÄ£¬Ò»¸öСÐ͵ġ¢Ãâ·ÑµÄ¡¢¿ÉÒÔÏÂÔصġ¢Ç¶ÈëʽµÄJavaÔ´´úÂë½âÊÍÆ÷£¬¾ßÓжÔÏó½Å±¾ÓïÑÔÌØÐÔ¡£BeanShellÖ´Ðбê×¼JavaÓï¾äºÍ±í´ïʽ£¬ÁíÍâ°üÀ¨Ò»Ð©½Å±¾ÃüÁîºÍÓï·¨¡£Ëü½«½Å±¾»¯¶ÔÏó¿´×÷¼òµ¥±Õ°ü·½·¨£¨simple method closure£©À´Ö§³Ö£¬¾ÍÈçͬÔÚPerlºÍJavaScri ......

java¶àÏ̱߳à³ÌÌå»á

ÔÚ Java ³ÌÐòÖÐʹÓöàÏß³ÌÒª±ÈÔÚ C »ò C++ ÖÐÈÝÒ׵ö࣬ÕâÊÇÒòΪ Java ±à³ÌÓïÑÔÌṩÁËÓïÑÔ¼¶µÄÖ§³Ö¡£±¾ÎÄͨ¹ý¼òµ¥µÄ±à³ÌʾÀýÀ´ËµÃ÷ Java ³ÌÐòÖеĶàÏß³ÌÊǶàôֱ¹Û¡£¶ÁÍê±¾ÎÄÒÔºó£¬Óû§Ó¦¸ÃÄܹ»±àд¼òµ¥µÄ¶àÏ̳߳ÌÐò¡£
¡¡¡¡ÎªÊ²Ã´»áÅŶӵȴý£¿
¡¡¡¡ÏÂÃæµÄÕâ¸ö¼òµ¥µÄ Java ³ÌÐòÍê³ÉËÄÏî²»Ïà¹ØµÄÈÎÎñ¡£ÕâÑùµÄ³ÌÐòÓе¥¸ö¿ØÖ ......

´ÓC++¸Éµ½×ªÐÍΪjavaÊÇÍ˲½£¬ÕýÈ·Óë·ñ£¿

½ñÌìÔÚ¹äÂÛ̳µÄʱºò¿´µ½ÓÐÈ˽ò½òÀÖµÀ£º´ÓC++¸Éµ½×ªÐÍΪjavaÊÇÍ˲½
ÎÒ²»ÈÏΪÊÇÕâÑù£¬Ê×ÏÈÓ¦¸ÃÒ»¸öÈ˵ÄÐËȤ£¬¼ÓÉÏÕâÃÅÓïÑÔ£¬ÕâÃŹ¤×÷ÊÇ·ñ·ûºÏÄã
¸É×Ô¼ºÏ²»¶µÄÓïÑÔ±àÂë²ÅÊÇ×îÖØÒªµÄ£¬µ±È»java±È½ÏÈÝÒ׵㣬ÎÒÒ²ÊÇÕâÑùÈÏΪµÄ
µ«ÊÇjava²¢²»ÊÇ´ó¼ÒËù˵µÄÄÇôÈÝÒ×£¬µ±½ñÉç»áË­²»¸Ò˵×Ô¼º»ássh£¬µ±ÊÇ×Ô¼ºÎÊÐÄ×Ô¼ºÑ§µÃÓжàºÃ£¬
ÔÚ ......

Effective Java ѧϰ±Ê¼Ç£¨2£©

ÓÐʱ£¬ÎÒÃÇÔÚдһ¸ö¹¹Ô캯Êýʱ£¬¾­³£ÒòΪËü°üº¬ÖÚ¶àµÄ²ÎÊý¶ø¿àÄÕ,Õâʱ¿ÉÒÔ¿¼ÂÇÓÃBuilderģʽÀ´´´½¨¶ÔÏó¡£
È磬ÎÒÃÇÒªÉè¼ÆÒ»¸öÓªÑø³É·ÝµÄÀ࣬°üº¬ÄÜÁ¿£¬µ°°×ÖÊ£¬Ö¬·¾£¬¸Æ£¬Ìú£¬Ð¿£¬Î¬ÉúËØA, άÉúËØB1 ... µÈ£¬µ«ÔÚ¹¹ÔìµÄʱºò£¬²»Ò»¶¨Ã¿´Î¶¼ÐèÒªÕâЩ²ÎÊý£¬Èç¸Æ£¬Ìú£¬Ð¿ºÍάÉúËصÈÊÇ¿ÉÑ¡µÄ£¬ÎªÁËÊÊÓ¦¶àÖÖ¿ÉÄܵĴîÅ䣬±È½Ïԭʼ ......

Effective Java ѧϰ±Ê¼Ç(4)

Õâ¸öÔ­ÔòºÜ¼òµ¥£¬¾ÍÊÇʹÓÃ˽Óй¹Ô캯Êý·ÀÖ¹À౻ʵÀý»¯¡£
ÓÐʱ£¬ÎÒÃÇ»áдһЩ¹¤¾ßÀ࣬Èçjava.lang.Math »òÊÇ java.util.Arrays, ÕâЩÀàÖж¼ÊǾ²Ì¬º¯Êý£¬ÔÚÉè¼ÆµÄʱºò£¬ÕâЩÀಢ²»ÊÇÓÃÀ´±»ÊµÀý»¯µÄ¡£Õâ¸öʱºò£¬¾ÍºÜÓбØÒª°Ñ¹¹Ô캯Êý˽Óл¯¡£
public class UtilityClass {
private UtilityClass() {
throw new Assertion ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ