• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Serializing static variables

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 28366
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:


https://coderanch.com/t/541339/java-programmer-SCJP/certification/static-members-inherited

https://coderanch.com/t/539469/java-programmer-SCJP/certification/Serialization#2448680
 
Tere Luna
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks you Tommy, I'm checking it out right now
 
Ranch Hand
Posts: 64
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for easy understanding watch this thread

https://coderanch.com/t/544894/java-programmer-SCJP/certification/please-explain-output
 
"How many licks ..." - I think all of this dog's research starts with these words. Tasty tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic