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

Effective Java Item10

Effective Java 2nd Edition Reading Notes
Item10: Always override toString
×ÜÊǸ²¸ÇtoString·½·¨
 
java.lang.ObjectµÄtoString·½·¨µÄ˵Ã÷Ϊ£º
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.
The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:
 getClass().getName() + '@' + Integer.toHexString(hashCode())
 
java.lang.ObjectµÄtoString·½·¨·µ»ØµÄÊÇÀàµÄÃû×Ö£¬¼ÓÉÏ@·ûºÅ£¬È»ºóÊÇÒ»¸öÎÞ·ûºÅµÄ16½øÖÆÊý(¶ÔÏóµÄhash codeÖµ)£¬ÕâÑùµÄtoString·½·¨ÏÔÈ»´«´ïµÄÐÅÏ¢»¹²»¹»¡£¶øtoString·½·¨µÄ˵Ã÷Öаüº¬ÁË“½¨ÒéËùÓеÄ×ÓÀà¶¼¸²¸ÇÕâ¸ö·½·¨”¡£
 
toString·½·¨ÔÚprintln£¬printf£¬×Ö·û´®Á¬½Ó£¬ÒÔ¼°assert¶ÏÑÔÖУ¬ÒÔ¼°ÔÚµ÷ÊÔÆ÷ÖУ¬¶¼±»µ÷Óá£
 
toString·½·¨Ó¦¸Ã°üº¬ËùÓжÔÏóµÄÖØÒªÐÅÏ¢¡£
 
ÁíÍâÒ»¸öÎÊÌâÊÇ£ºÊÇ·ñÐèÒª¶ÔtoString·µ»ØµÄÖµ½øÐÐÖ¸¶¨¸ñʽ¡£
Ö¸¶¨¸ñʽµÄºÃ´¦ÔÚÓÚËü¿ÉÒÔ×öΪһ¸ö±ê×¼£¬²»»á´øÓÐÆçÒ壬²¢ÇҿɶÁÐԺá£Õâ¸ö·µ»ØÖµ¿ÉÒÔÓÃÓÚÊäÈë»òÕßÊä³ö£¬³Ö¾Ã»¯µÄ¿É¶Á¶ÔÏó(xmlÎļþ)¡£Èç¹ûÖ¸¶¨¸ñʽµÄ»°£¬×îºÃÔÙÌṩһ¸ö¹¤³§ÀàÓÃÓÚ¸ù¾ÝString¹¹ÔìʵÀý¡£
Ö¸¶¨¸ñʽµÄȱµãÔÚÓÚËüÊǺͽӿÚÒ»Ñù£¬Ò»µ©Ö¸¶¨ÁË£¬¾Í²»Äܸı䣬ÒòΪ¿ÉÄÜÓÐÍⲿʹÓÃËü£¬Ò»µ©Ëü¸Ä±äÁË£¬Íⲿ´úÂ뽫ÎÞ·¨Ê¹Óá£
Ò»µ©ÐèÒªÖ¸¶¨¸ñʽ£¬ÄÇôҪ׼ȷµÄ¶¨Òå²¢½øÐÐÎĵµ×¢ÊÍ£º
/**
 * Returns the string representation of this phone number.
 * The string consists of fourteen characters whose format
 * is "(XXX) YYY-ZZZZ", where XXX is the area code, YYY is
 * the prefix, and ZZZZ is the line number.  (Each of the
 * capital letters represents a single decimal digit.)
 *
 * If any of the three parts of this phone numb


Ïà¹ØÎĵµ£º

javaÊ±Çø½â¾ö·½°¸

 tomcatÆô¶¯web·þÎñµÄʱºò×ÜÊÇ»áÓÐ8СʱµÄʱ²î,
×ÁÄ¥Á˺þÃ,×î¼òµ¥µÄ°ì·¨¾ÍÊÇ
ÕÒµ½Îļþ¼Ðjdk1.6.0_07\jre\lib\zi\Etc
ÕâÀï±ß¶¼ÊÇÒ»Ð©Ê±ÇøÎļþGTM+1,GTM+2,GTM+3....
±¸·ÝÒ»·ÝEtc
¿½±´N·ÝGTM+8Îļþ(ÖйúµÄÊ±ÇøÊÇGTM+8)
°ÑGMT+8ÎļþÃû¸Ä³ÉGTM+1,GTM+2,GTM+3....
¸²¸ÇµôÔ­À´µÄEtcÀï±ßµÄÎļþ
ÖØÆôtomcatÎÊÌâ½â¾ö ......

Java Logger(javaÈÕÖ¾)


Ŀ¼
1. ¼ò½é
2. °²×°
3. log4j»ù±¾¸ÅÄî
3.1. Logger
3.2. Appender
3.2.1. ʹÓÃConsoleAppender
3.2.2. ʹÓÃFileAppender
3.2.3. ʹÓÃWriterAppender
3.3. Layout
3.4. »ù±¾Ê¾Àý
3.4.1. SimpleLayoutºÍFileAppender
3.4.2. HTMLLayoutºÍWriterAppender
3.4.3. PatternLayoutºÍConsoleAppender
4. ʹÓÃÍⲿ ......

JDKÖаüº¬µÄ³£ÓÃJavaµ÷ÊÔ¹¤¾ß

1  JDK5.0°üÀ¨µÄµ÷ÊÔ¹¤¾ß
ÎÒÃÇÔÚÕâÀï¶ÔJDK5.0µÄµ÷ÊÔ¹¤¾ß×ö´óÖµĸÅÄîÐԵĽéÉÜ£¬È»ºóÏ£Íûͨ¹ý½éÉÜÎÒ×Ô¼ºÔÚʵ¼Ê¹¤×÷ÖÐʹÓÃÕâЩ¹¤¾ß½â¾öÎÊÌâµÄʵÀýÀ´Èôó¼Ò¶ÔÕâЩ¹¤¾ßÓиüÉîÈëµÄÁ˽⡣
 
¡¡JDK5.0ÀïÃæ¼ÓÈëÁËjstack, jconsole, jinfo, jmap, jdb, jstat, jps, ÏÂÃæ¶ÔÕâЩ¹¤¾ß×ö¼òµ¥½éÉÜ£º
¡¡jstack -- Èç¹ûjava³Ì ......

Jconsole ºÍ jps ÎÞ·¨ÏÔʾ±¾µØ Java ½ø³ÌÁбí

ǰһÕóÔÚ¹«Ë¾ÀïʹÓà jconsle ʱһÇÐÕý³££¬È»¶øÔÚ¼ÒÖеĻúÆ÷ÉÏÈ´³öÏÖÁ˱êÌâËùʾµÄÎÊÌ⣺
jconsole ºÍ jps ÎÞ·¨ÏÔʾ±¾µØ Java ½ø³ÌÁÐ±í¡£
µ±Ê±Ö±½ÓÀûÓà -Dcom.sun.management.jmxremote.port=port Æô¶¯Ä¿±ê java ½ø³Ì£¬²¢ÔÚ jconsole ÖÐͨ¹ý localhost:port ·½Ê½³É¹¦Á¬½ÓÉÏÄ¿±ê java ½ø³Ì¡£ÓÐÁËÕâ¸ö work around Ö®ºó£¬¶ÔÕ ......

³£¼ûË㷨ѧϰ¼°ÆäJavaʵÏÖ

package org.bupt.test;
import java.util.ArrayList;
class MyResource {
    ArrayList<Integer> arrList= new ArrayList<Integer>();
    public MyResource(ArrayList<Integer> arrList) {
        this.arrList = arrList;
&nbs ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ