Serialization  only persist state of object and not object itself. static variables and Transient variables are not included in java serialization process and are not the part of the object’s serialized state. if you don't store values of these variables then what would be value of these variable once you deserialize and recreate those object?state of object是指什么?什么情况下用到Serialization?

解决方案 »

  1.   

    state of object 是指对象的状态。序列化是将对象的状态转换成可保持或可传输格式的过程。发序列化与他相反,他将流转换成对象。只有与对象相对应的类实现了Serializable接口的对象才能序列化。序列化的对象能使用ObjectOutputStream将对象的状态存储在磁盘上或写在网络上,用ObjectInputStream能将此状态读取出来组成原来的对象。
      

  2.   


    对象序列化保存的是对象的"状态",即它的成员变量。 if you don't store values of these variables then what would be value of these variable once you deserialize and recreate those object?The answer is 'null'?
      

  3.   

    什么情况下用到Serialization:
    除了在持久化对象时会用到对象序列化之外,当使用RMI(远程方法调用),或在网络中传递对象时,都会用到对象序列化。
      

  4.   

    以下的话都似懂非懂,就是不清楚怎么用的持久化对象(save to a file?)
    RMI
    在网络中传递对象Transient variables cannot be serialized. (Eg. Database connection, file handler)Objects that are stored in the HTTPSession must be Serializable