• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

static variable and Serialization.

 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ... ...
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.....
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abimaran Kugathasan wrote:
Thanks pete stein. Now I got it.



Don't thank me as I was just repeating what Ankit Garg already posted.
 
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic