aspose file tools*
The moose likes Java in General and the fly likes Question related to serialization. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question related to serialization." Watch "Question related to serialization." New topic
Author

Question related to serialization.

john sal
Ranch Hand

Joined: Jul 30, 2010
Posts: 93
While reading a document on serialization i found that there are two call back methods readObject(ObjectInputStream) and writeObject(ObjectOutputStream) are present which are called by the JVM just before the object is serialized and deserialized.

I just wanted to know that when these call back methods are already present then why do we have need for Externalizable interface when we can do the same from these callback methods.
Manjusha Muraleedas
Ranch Hand

Joined: Jun 02, 2010
Posts: 52
In the case of implementing Serializable interface,JVM does the serialization for us using readObject(ObjectInputStream) and writeObject(ObjectOutputStream) methods.

We may override these methods in the class being serialized to handle extra functionalities (like handling transient variables).We still have to call to call defaultReadObject () and defaulWriteObject () methods to get the actual object serialized/deserialized.

In the case of implementing Externalizable interface, we need to write code to save the contents... JVM won't do it for us.





Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

john sal wrote:
I just wanted to know that when these call back methods are already present then why do we have need for Externalizable interface when we can do the same from these callback methods.

Externalization allows you to control what need to serialized. It’s the programmer responsibility to write the class data to the stream (as well the super class, if any).
 
jQuery in Action, 2nd edition
 
subject: Question related to serialization.