I am little confuse about private methods writeObject() & readObject(), also defaultWriteObject & defaultReadObject methods. Which methods does the part of saving an Object state manually & which does normal serialization?
What I understand is writeObject() & readObject() methods does the part of saving an Object state manually. defaultWriteObject & defaultReadObject methods does normal serialization.
Please correct me if I am wrong or I forgot anything with respect to understand serialization mechanism. I appreciate your help.
We use readObject() and writeObject() to perform serialization in general.
However, when you want to perform manual serialization, you write your own private readObject() and writeObject() methods in your class.
Within your new readObject() you call defaultWriteObject() to perform serialization. Also in this method, we can manually write parts of some transient objects (or anything else) we may want to save using writeInt() etc.
Hope this helps in some way!
Joined: Jun 18, 2007
Neha, I am confuse about which methods are performing normal serialization & which are performing serialization for transient variable? Can you explain?
hi, Actually transient keyword will skill the serialization process, but If we are using a transient keyword in java.How that variable will passed remotely.For example,i have class in which a variable 'password' is transient and this class implements serializable.When the object is passed remotely all the variables except password willget serializable.Then how does this variable password value will be retrieved at the end
Originally posted by Priyam Srivastava: [CODE]But when you have to do some custom writing and/or reading i.e. something that is not a part of that object graph we use defaultWriteObject() & defaultReadObject().
Can you give me a practical example of some custom writing and/or reading. to understand exactly how defaultWriteObject() & defaultReadObject() behave ??