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?
对象序列化保存的是对象的"状态",即它的成员变量。 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'?
除了在持久化对象时会用到对象序列化之外,当使用RMI(远程方法调用),或在网络中传递对象时,都会用到对象序列化。
RMI
在网络中传递对象Transient variables cannot be serialized. (Eg. Database connection, file handler)Objects that are stored in the HTTPSession must be Serializable