• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding Object Serialization...

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

According to my knowledge what I know is that:

"Static variables are not saved as part of serialization. The purpose of serialization is to save the state of an object, and a static variable belongs to the class and not to an object of the class."

But when I check practically, static variable data is also part of Serializable state of the object.

Here is the code:





Can anybody guide me, whether my understanding is right or wrong? becaue
in above output, [BOLD]CityName is static in the code , but apeared
in the output[/BOLD], which shouldn't be according to my knowledge.


Thanks in advance.

Regards,
Potluri
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My dear friend. You just said that the variable cityName since is static belongs to the class. You set the value of this variable at the begining of your method and by the time you deserialize the object, it is still set.

The value that you see in the output is not taken from the deserialized object, but it was the one you set for the class variable at the begginning.

If you want to test it. Set the variable before serialization, then set it to blank before deserializing and you will see.

cityName = "New York";
serialize(object);
cityName="";
deserialize(object);

And you will see cityName continues to be blank (""). In other words, serialization is not touching your variable, but you are.
[ September 14, 2007: Message edited by: Edwin Dalorzo ]
 
V. Potluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Edwin,

Thanks for your precious time for giving me the reply. Thanks a lot. Have a great day.

Thanks and Regards,
Potluri.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I faced same doubt, I just divided Serialization and Deserialization into TWO programs. Thats it
reply
    Bookmark Topic Watch Topic
  • New Topic