Serialization
An object is serializable if either itself or any of its ancestors implement Serializable or Externalizable. When a object is serialized, the serialization occurs recursively, which means all the object refrenced within the current object also get serialized and so..on. Complete object graph gets serialized.
Serialzation is done by passing the object as parameter to writeObject() method of ObjectOutputStream instance.
Serialization can be used for deep copy but there a few issues. 1) all the objects refrenced has to be serializable 2) relative poor performce , hence not advisable in performance critical situations 3) Issue involving object instances like Singleton instances ...use readResolve() 4) how to handle transient variables , as those are not serialized.
default clone() method inherited from Object class does shallow copy.
Serialzation is done by passing the object as parameter to writeObject() method of ObjectOutputStream instance.
Serialization can be used for deep copy but there a few issues. 1) all the objects refrenced has to be serializable 2) relative poor performce , hence not advisable in performance critical situations 3) Issue involving object instances like Singleton instances ...use readResolve() 4) how to handle transient variables , as those are not serialized.
default clone() method inherited from Object class does shallow copy.
Comments
Post a Comment