Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Serialization  RSS feed

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sushant Kaushik
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Arie..now it got clarified
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!