易截截图软件、单文件、免安装、纯绿色、仅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 调用命令 备份mysql数据库

 代码如下:
  1  String command  =   " cmd /c C:/Program Files/MySQL/MySQL Server 5.0/bin>mysqldump -h localhost -u root -p aijia > E:/aijia.dmp " ;
  2      try    {
  3     Process process& ......

Java虚拟机 和 java虚拟机下的进程

一、什么是Java虚拟机
     当你谈到Java虚拟机时,你可能是指:
     1、抽象的Java虚拟机规范
     2、一个具体的Java虚拟机实现
     3、一个运行的Java虚拟机实例
二、Java虚拟机的生命周期
     一个运行 ......

Serializable java序列化

Bean Serializable Interface 的接口让BEAN可以串行化,将其变成一个可保存为以后使用的二进制流。当一个BEAN被系列化到磁盘上或者其他任何地方,其状态被保存起来,其中的属性值也不会改变。在BEAN的规范中,JSP并没有要求BEAN实现Serializable接口。但是,如果您希望自己控制您所创建的组件的serialization进程,或者您想 ......

java与网络


1 网络通信的本质是进程间通信。   
2 Tcp协议和UDP协议
TCP:开销大,用于可靠性要求高的场合。
TCP的过程相当于打电话的过程
UDP:用在对实时性要求比较高的场合。
UDP的过程相当于写信的过程。
注意:socket是套接字,ip和port(端口号 0~65535个端口,一个端口只能有一个进程)
3,   ......

常见算法学习及其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号