| Author |
Serializing static variables
|
Tere Luna
Greenhorn
Joined: Jul 19, 2011
Posts: 12
|
|
Hi,
I'm not sure why this following code (it's in one of the questions for SCJP guide in chapter 6)
El resultado es "10 0 10", I guess that the static variable z was indeed serialized and deserialized or why does it have the value of 10?
Thanks a lot
|
 |
Stanley Hataria
Greenhorn
Joined: Mar 01, 2011
Posts: 6
|
|
hey if you read this line of code
System.out.print(++s.z + " ");
where it increments the static variable. also static variable is for the class so changes are visible everywhere.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
No, static variables aren't serialized. Like Stanley said, first z was 9, then the code incremented it, so now it's 10. If you remove all the code which serializes and deserializes objects from that example you will see the same thing happening.
|
 |
Tommy Delson
Ranch Hand
Joined: Apr 13, 2011
Posts: 206
|
|
Serialization is NOT on the exam as Bert stated, but it's good to learn it.
Static members are not serialized...
See my responses on Serialization for more insight:
http://www.coderanch.com/t/541339/java-programmer-SCJP/certification/static-members-inherited
http://www.coderanch.com/t/539469/java-programmer-SCJP/certification/Serialization#2448680
|
OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
|
 |
Tere Luna
Greenhorn
Joined: Jul 19, 2011
Posts: 12
|
|
Thanks everyone for your answers. They have been very helpful
|
 |
Stanley Hataria
Greenhorn
Joined: Mar 01, 2011
Posts: 6
|
|
Hey Paul ,
Can you state what else is not on the exam?
It would be helpful
|
 |
Tere Luna
Greenhorn
Joined: Jul 19, 2011
Posts: 12
|
|
Yes please, help us identify which topics that are in the guide written by Kathy Sierra and Bert Bates are not in the exam, since they mention almost all the topics are includee
Thanks
|
 |
Tommy Delson
Ranch Hand
Joined: Apr 13, 2011
Posts: 206
|
|
I recommend check out on Oracle website for more information on topics that will be on the exam.
Here is the link you can check out:
http://education.oracle.com/pls/web_prod-plq-dad/db_pages.getpage?page_id=41&p_exam_id=1Z0_853
|
 |
Tere Luna
Greenhorn
Joined: Jul 19, 2011
Posts: 12
|
|
Thanks you Tommy, I'm checking it out right now
|
 |
Naveen Madarapu
Ranch Hand
Joined: May 24, 2011
Posts: 63
|
|
for easy understanding watch this thread
http://www.coderanch.com/t/544894/java-programmer-SCJP/certification/please-explain-output
|
OCPJP
|
 |
 |
|
|
subject: Serializing static variables
|
|
|