aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Serialization" Watch "Serialization" New topic
Author

Serialization

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
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.


SCJP-1.5<br />SCWCD-1.4
Neha Bhattad
Ranch Hand

Joined: Aug 20, 2007
Posts: 30
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!
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Neha, I am confuse about which methods are performing normal serialization & which are performing serialization for transient variable? Can you explain?
kiran reddy aluguvelli
Greenhorn

Joined: Aug 08, 2007
Posts: 7
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
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
Originally posted by dolly shah:
I am confuse about which methods are performing normal serialization & which are performing serialization for transient variable? Can you explain?


we cannot serialize transient variables..

normal serialization/deserialization is performed by writeObject() & readObject().

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().


"History would be kind to me, for I intend to write it."
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Thanks Priyam. But in the book page:451, code doesn't show any dog object's serialization. As I understand Dog object goes immediately after private method & before defaultWriteObject().

If I am wrong, correct me.
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169


this is the entire code of example on page 451...i hope you now understand what exactly is happening

As I understand Dog object goes immediately after private method & before defaultWriteObject().

can you be more precise on what you meant by the above statement?

In the above code first Dog object is saved and then we saved collarSize variable..
[ August 22, 2007: Message edited by: Priyam Srivastava ]
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
Thanks Priyam. I got it now after spending couple of hours. Thanks again.
Rahul Nair
Ranch Hand

Joined: Dec 01, 2007
Posts: 138
Hello Priyam,

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 ??

Thanks
[ April 28, 2008: Message edited by: Rahul Nair ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Serialization