• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Serializing static variables

 
Tere Luna
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 20998
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tere Luna
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone for your answers. They have been very helpful
 
Stanley Hataria
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Paul ,
Can you state what else is not on the exam?
It would be helpful
 
Tere Luna
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks you Tommy, I'm checking it out right now
 
Naveen Madarapu
Ranch Hand
Posts: 64
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for easy understanding watch this thread

http://www.coderanch.com/t/544894/java-programmer-SCJP/certification/please-explain-output
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic