K&B (SCJP1.5) page 456 says that serialization is not for statics. I understand that statics are class variables hence do not get saved during serialization. So that led me to try and find out what happens when an object which has a static member is saved. What happens when the object is saved then read back?
I tried to solve the above with the folowing code:
The static variables are stored at the class level. They are not tied to any object. And we can serialize only the Object. So, technically static variables can not be serialized. This means that the static variable values doesn't get serialized. In the deserialized object the value of the static variable will always be the latest value of that variable. The value the variable had, when serializing the object will not persist.
Just after the below code you try modifying the value of the static variable:
Now when you deserialize the value of the variable will be 1000 and not 1, which was the value when it was serialized. This won't be the case with instance variables.
Hope this helps...
-Aravind<br />SCJP 5.0 (91%), Preparing for SCBCD.
Joined: Jul 25, 2008
Originally posted by Aravind Jerubandi: [QB] In the deserialized object the value of the static variable will always be the latest value of that variable. The value the variable had, when serializing the object will not persist.[QB]