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 W3C DOM ½øÐÐXML²Ù×÷µÄÀý×Ó£¬°üº¬Á˲éѯ¡¢Ôö¼Ó¡¢Ð޸ġ¢É¾³ý¡¢±£´æµÄ»ù±¾²Ù×÷¡£½ÏÍêÕûµÄÃèÊöÁËÒ»¸öXMLµÄÕû¸ö²Ù×÷Á÷³Ì¡£ÊʺϸÕÈëÃÅJAVA XML²Ù×÷µÄÅóÓѲο¼ºÍѧϰ¡£
¼ÙÉèÓÐXMLÎļþ£ºtest1.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
< ......
ǰһÕóÔÚ¹«Ë¾ÀïʹÓà jconsle ʱһÇÐÕý³££¬È»¶øÔÚ¼ÒÖеĻúÆ÷ÉÏÈ´³öÏÖÁ˱êÌâËùʾµÄÎÊÌ⣺
jconsole ºÍ jps ÎÞ·¨ÏÔʾ±¾µØ Java ½ø³ÌÁÐ±í¡£
µ±Ê±Ö±½ÓÀûÓà -Dcom.sun.management.jmxremote.port=port Æô¶¯Ä¿±ê java ½ø³Ì£¬²¢ÔÚ jconsole ÖÐͨ¹ý localhost:port ·½Ê½³É¹¦Á¬½ÓÉÏÄ¿±ê java ½ø³Ì¡£ÓÐÁËÕâ¸ö work around Ö®ºó£¬¶ÔÕ ......
תÌû´¦£ºhttp://dong-java.javaeye.com/blog/375150
1¡£ÍƼöʹÓÃOralce±È½ÏеÄ10.2.0.3 JDBC Drivers¡£Õâ¸ö°æ±¾¶Ô±È9.2µÄ×î´óµÄºÃ´¦ÊÇDriverManager.setLoginTimeoutº¯ÊýÊÇÆð×÷Óõġ£ÉèÖÃÁËÕâ¸ö²ÎÊý£¬ÔÚ¶ñÁÓµÄÍøÂç»·¾³ÖоͲ»»áÓÐÁ¬½ÓÊý¾Ý¿âµÄº¯Êý³¤Ê±¼ä²»·µ»ØµÄÇé¿ö¡£
2¡£JDBC Developer!ˉs Guide and Refer ......
JAVA³ÌÐòÔ±ÃæÊÔÖ®¿û»¨±¦µä
1¡¢ÃæÏò¶ÔÏóµÄÌØÕ÷ÓÐÄÄЩ·½Ãæ
1.³éÏ󣺳éÏó¾ÍÊǺöÂÔÒ»¸öÖ÷ÌâÖÐÓ뵱ǰĿ±êÎ޹صÄÄÇЩ·½Ã棬ÒÔ±ã¸ü³ä·ÖµØ×¢ÒâÓ뵱ǰĿ±êÓйصķ½Ãæ¡£³éÏó²¢²»´òËãÁ˽âÈ«²¿ÎÊÌ⣬¶øÖ»ÊÇÑ¡ÔñÆäÖеÄÒ»²¿·Ö£¬ÔÝʱ²»Óò¿·Öϸ½Ú¡£³éÏó°üÀ¨Á½¸ö·½Ã棬һÊǹý³Ì³éÏ󣬶þÊÇÊý¾Ý³éÏó¡£
2.¼Ì³Ð£º¼Ì³ÐÊÇÒ»ÖÖÁª½áÀàµÄ²ã´ÎÄ£ ......