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

Effective Java ѧϰ±Ê¼Ç(15)

Ò»¸ö²»¿É¸Ä±ä£¨immutable£©µÄÀ࣬¹ËÃû˼Ò壬¾ÍÊÇÆäʵÀý²»Äܸı䣬¼´ÀïÃæËùÓеÄÐÅÏ¢ÔÚ´´½¨Ê±¾Í¸³Öµ£¬ÔÚÆäÉúÃüÖÜÆÚÖÐÆäÖµ²»±ä¡£
ʹÓò»¿É¸Ä±äµÄÀàµÄÓŵãÔÚÓÚ£¬Éè¼Æ¼òµ¥£¬Ò×ÓÚʵÏÖºÍʹÓ㬾ßÌåÀ´½²£¬ËüµÄ״̬»úºÜ¼òµ¥£¬Ö»ÓÐÒ»¸ö״̬¡£ËüÊÇḬ̈߳²È«£¬Äܹ»×ÔÓɵı»¹²Ïí£¬Äܹ»Í¨¹ý¾²Ì¬¹¤³§Ä£Ê½¾¡¿ÉÄܸ´ÓÃÒѾ­´´½¨³öÀ´µÄ¶ÔÏó£¬Ò²²»ÓÃΪËüдclone»òÊÇ¿½±´¹¹Ô캯Êý£¬²»¿É¸Ä±äµÄÀàÒ²±ãÓÚά»¤£¬ÊÇϵͳµÄÁ¼ÐÔ»ùʯ¡£
ÆäΨһµÄȱµã¾ÍÊÇ£¬Ëü±ØÐëΪ²»Í¬µÄÖµ·Ö±ð´´Ô첻ͬµÄ¶ÔÏó¡£
ʹһ¸öÀàΪimmutable£¬Òª×öµ½ÒÔϼ¸µã¡£
1.²»ÒªÌṩÈκοÉÒÔÐ޸ĶÔÏóÖÐÊý¾ÝµÄ·½·¨¡£
2.È·±£´ËÀ಻»á±»¼Ì³Ð¡£Õâ¸ö¿ÉÒÔ·ÀÖ¹×ÓÀ಻СÐĶԸ¸ÀàÖеÄÊý¾Ý½øÐиü¸Ä¡£
3.ʹËùÓеÄ×Ö¶ÎΪfinal.
4.ʹËùÓеÄ×Ö¶ÎΪprivate.
5.È·±£ËùÓÐ×Ö¶ÎÖеĿɱ»¸Ä±äµÄ¶ÔÏóµÄÒýÓò»±»Íâ½ç»ñµÃ¡£
µ«Òª×¢ÒâµÄµ±ÊµÏÖÐòÁл¯µÄʱºò£¬Èç¹ûÒ»¸ö²»¿É¸Ä±äÀàÖаüº¬¿É¸Ä±äÀàµÄÒýÓ㬾ͱØÐëÌṩһ¸öÏÔʽµÄreadObject»òreadResolve£¬»òʹÓÃObjectOutputStream.writeUnsharedºÍOjbectInputStream.readUnshared·½·¨¡£·ñÔò¾Í¹¥»÷Õ߾ͿÉÄÜ´´½¨Ò»¸ö¿ÉÒԸıäµÄʵÀý¡£
×ܽ᣺³ý·ÇÓÐ×ã¹»µÄÀíÓÉ£¬Ó¦¸Ã½«ÀàÉè¼ÆÎªimmutable¡£
         Èç¹ûÒ»¸öÀ಻ÄÜÉè¼Æ³Éimmutable£¬ÄÇô¾¡Á¿¼õÉٿɸıäµÄ×ֶΡ£


Ïà¹ØÎĵµ£º

Java Web µÚ¶þÌì Servlet»ù´¡

Ò»¡¢
ʲôÊÇ
Servlet
Servlet
ÔÚ
web
ÈÝÆ÷ÖÐÓÃÀ´´´½¨¶¯Ì¬ÍøÒ³Óõģ¬ÒòΪËûûÓÐ
main
·½·¨£¬ËùÒÔ
Servlet
²»ÊÇÒ»¸öÍêÕûµÄ
Java
Ó¦ÓóÌÐò¡£
¶þ¡¢
Servlet
µÄ±àд
×î»ù±¾µÄ
Servlet
Òª°üÀ¨Èý²¿·Ö£¬·Ö±ðΪ
Servlet-name
¡¢
Servlet-class
¡¢
url-pattern
¡£
Èý¡¢
Servlet API
Generi
Servlet
ÊµÏ ......

Java Web µÚÁùÌì ×÷ÓÃÓò¼°¼àÌýÆ÷

Ò»¡¢
web
µÄÈýÖÖ×÷ÓÃÓò
ServletContext(
ÉÏÏÂÎÄ
)
£ºÕû¸ö
web
Ó¦ÓóÌÐò£¬Ï̲߳»°²È«
HttpSession(
ȇȡ
)
£ºÒ»¸ö»á»°½»»¥¹ý³Ì
ServletRequest(
ÇëÇó
)
£ºÒ»´ÎÇëÇó¹ý³Ì
ÊôÐÔ²Ù×÷·½·¨£º
      

void setAttribute(String,Object)
       ......

JavaÕÐË­ÈÇË­ÁË£¿

¼ÇµÃÒ»Äêǰ£¬ÕýÊÇ×Ô¼º¶Ôjava°®²»ÊÍÊÖµÄʱºò£¬¶øÍøÉÏÒ²ÊÇÒ»²¨ÓÖÒ»²¨µÄjava³°·íÈÈ£¬ÎÒ·ßÅ­ÁË£¬¾ÍÏñÈËÈ˶¼»áº´ÎÀ×Ô¼ºÏ²»¶µÄ¶«Î÷Ò»Ñù¡£ÎÒÔÚÄÚÍøÒ»´ÎÓÖÒ»´ÎµÄ·¢Ìû·¢Ð¹£¬¿ÉÄܰ­ÓÚÎÒÊǰæÖ÷£¬javaÅúÅÐÕßÃÇҲûÓлØÌû¡£Ö±µ½ºóÀ´£¬´ó¼ÒÈÏʶÎÒ£¬¶¼ËµÂ··ÉºÜÉó¤java£¬javaºÜÀ÷º¦¡£ÆäʵÎÒÖ»¶ÔJ2SEÂÔ¶®Æ¤Ã«¡£ÎÒϲ»¶javaµÄÔ­ÒòÊÇ£¬¶ÔÓÚÒ»¸ö ......

javaÖÐhashmapºÍhashtableµÄÇø±ð

 
1¡¢  ¼Ì³ÐºÍʵÏÖÇø±ð
HashtableÊÇ»ùÓڳ¾ɵÄDictionaryÀàµÄ£¬HashMapÊÇJava 1.2Òý½øµÄMap½Ó¿ÚµÄÒ»¸öʵÏÖ¡£
2¡¢  Ḭ̈߳²È«²»Í¬
HashTableµÄ·½·¨ÊÇͬ²½µÄ£¬HashMapÊÇδͬ²½£¬ËùÒÔÔÚ¶àÏ̳߳¡ºÏÒªÊÖ¶¯Í¬²½HashMap¡£
3¡¢  ¶ÔnullµÄ´¦Àí²»Í¬
HashTable²»ÔÊÐínullÖµ(keyºÍvalue¶¼²»¿ÉÒÔ),HashMapÔÊÐín ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ