aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes static variable and Serialization. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "static variable and Serialization." Watch "static variable and Serialization." New topic
Author

static variable and Serialization.

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

I got it from Exam Lab 01. static variable aren't Serializable. When I serialize the object whose class has static variable. Have look the below code:


Output : 4, 5, 0.
How is it possible? Thanks in Advanced!


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

The value of a was serialized, so it was retrieved when the instance was read, the value of b was not touched during serialization/deserialization. The value of c was reset since it was not serialized, so it was given the default value for its datatype i.e. 0 during deserialization. Also remember serialization is not on the exam now...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Caution : If the JVM is stopped and restarted while the data is saved,
the static variables will be reinitialized too, (like the transients) when
the class is loaded.

Jim ... ...


BEE MBA PMP SCJP-6
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Ankit Garg wrote:The value of a was serialized, so it was retrieved when the instance was read, the value of b was not touched during serialization/deserialization. The value of c was reset since it was not serialized, so it was given the default value for its datatype i.e. 0 during deserialization. Also remember serialization is not on the exam now...


Thanks for the reply. But the value of b is 5 after deserialized? That's my problem.....
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Abimaran Kugathasan wrote:
Thanks for the reply. But the value of b is 5 after deserialized? That's my problem.....


I think that it has nothing to do with serialization / deserialization and all to do that you changed the value of b in the main method and it remains changed throughout the program.
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

pete stein wrote:
I think that it has nothing to do with serialization / deserialization and all to do that you changed the value of b in the main method and it remains changed throughout the program.


Thanks pete stein. Now I got it.


Thanks!
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Abimaran Kugathasan wrote:
Thanks pete stein. Now I got it.


Don't thank me as I was just repeating what Ankit Garg already posted.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static variable and Serialization.
 
Similar Threads
Static variable - serialization Q
Threads,serialisation, static variables - java basic doubts
static in Serialization
static variables serialization
Serialization