aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Serialization" Watch "Serialization" New topic
Author

Serialization

Sushant Kaushik
Greenhorn

Joined: Dec 12, 2008
Posts: 25
Source - K &B chapter 6, Page 455



The Output is -
before: Fido 35
after: Fido 42

This is fine as Animal class didn't implement Serializable interface so weight got its intialized value of 42.
My question is if I modify Animal class as -

The output is
before: Fido 35
after: Fido 0

Can somebody please explain why in this case I am getting 0 for weight instead of 42?

Thanks,
Sushant
Arie Prastowo
Greenhorn

Joined: Apr 20, 2008
Posts: 22
if you do not use serialization on parent class, it's attribute will not be serialized no matter you mark it as transient or not.
When you deserialized, the attribute from not serialized parent class will be initialized.
But on serialized parent class, a transient attribute is not serialized or deserialized, so the value is 0 as in default value


SCJP 5.0<br />Use the power of mind
Sushant Kaushik
Greenhorn

Joined: Dec 12, 2008
Posts: 25
Thanks Arie..now it got clarified
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Serialization
 
Similar Threads
K &B: "Serialization Is Not for Statics"
How Inheritance Affects Serialization
Serialization question - Superclass is not marked Serializable but the sublass is...
serialiazation- run time exceptions
Serialisation - K&B