This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Statics and serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Statics and serialization" Watch "Statics and serialization" New topic

Statics and serialization

Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Sir / Madam
Why cannot Static variables be serialized/deserialized? Please educate me.

Mansukhdeep Singh

~ Mansukh
Naresh Shanmugam
Ranch Hand

Joined: Jul 16, 2010
Posts: 84
Serialization is only for instance variables.
Static variables are like class variables, i.e only one copy would be maintained irrespective of number of instances created.
The value of an instance variable might differ for each instance, but not the static variable!!
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Mansukhdeep Thind wrote:
Why cannot Static variables be serialized/deserialized? Please educate me.

Static members are associated with the class, not the instances, so it does not make sense to include them when serializing an instance.

|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
I agree. Here's the link:
subject: Statics and serialization
It's not a secret anymore!