wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why static variable serialized here? 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 "Why static variable serialized here?" Watch "Why static variable serialized here?" New topic
Author

Why static variable serialized here?

dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383



This is a book example. Chapter:6, example:15, page:519.

Answers are:
(1) 10 0 10
(2) In order to alter the standard deserialization process you would implement the readObject() method in SpecialSerial.


I am not getting why serialised allows static variable? Also I am not getting what (2) answer wants to say.


SCJP-1.5<br />SCWCD-1.4
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
static variables are not meant for serialization. but it if legal to have static variables in the class whose object you want to serialize.
here the static variable z doesn't get serialized..
[ July 12, 2007: Message edited by: Priyam Srivastava ]

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

Joined: Jun 18, 2007
Posts: 383
In code "z" is a static variable & it gets change after serialized.
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
try to deserialize the object in any other file(try to write the deserialization process in file say Deserialize.java)...then observe whether the value of z changes or not.

by the way what value of z you expect??
dolly shah
Ranch Hand

Joined: Jun 18, 2007
Posts: 383
I got it. But can you explain second answer?
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
I think it would be better if you go through Serialization topic once again from book K&B. you would understand better with example..
Jared Folino
Greenhorn

Joined: Apr 27, 2007
Posts: 25
It might be a bit clearer as well if you remember that s.z is shortcut syntax. The full statement would be SpecialSerial.z
 
wood burning stoves
 
subject: Why static variable serialized here?
 
Similar Threads
Serialization
Serialization SCJP KS && BB
question about serializable
Serializing static variables
what happens when try to serialize static variable