Meaningless Drivel is fun!*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 92
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).
 
Don't get me started about those stupid light bulbs.
 
subject: Question related to serialization.
 
Similar Threads
Serialization
Serialization
transient variable ? is there any other way
Custamize serialization and deserialization when using IIOP
What exactly does Serializable do for you?