• 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Can we Serialize Static Variable

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi any one please tell me

Can We Serialize static variable.

Thanks..
 
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, apparently you can, despite that is doesn't make sense, but it could cause some serious problems. So it should probably be avoided.

Here is a good explanation of a potential pitfall
[ January 11, 2007: Message edited by: David McCombs ]
 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Sirisha

Static variables are NEVER saved as part of the object's state, because they do not belong to the object.
Static variables are not part of the instance's state at all, static variables are purely CLASS variables. They have nothing to do with individual instances. serialization applies only to OBJECTS.
 
Ranch Hand
Posts: 126
VI Editor Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do that but will be useless
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Shashi Kant wrote:hello Sirisha

Static variables are NEVER saved as part of the object's state, because they do not belong to the object.
Static variables are not part of the instance's state at all, static variables are purely CLASS variables. They have nothing to do with individual instances. serialization applies only to OBJECTS.



this is possible by providing the following two methods in our class

as shown below. writeObject(),readObject().



ok baye...
 
Marshal
Posts: 76060
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch , Mohammad Parwez

Please always use code tags, which I have added to your code and you can see how much better it looks.
David McCombs, I couldn’t get the link you posted to open. It also has an incorrect certificate. Please check the link for errors.
 
Campbell Ritchie
Marshal
Posts: 76060
362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hadn’t noticed that link was posted 5 years ago; that must be why it won’t open.
 
Greenhorn
Posts: 16
IntelliJ IDE Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried but we can't serialize static field,through normal serialization concept,may be we can do it through exterlization
 
Legend has it that if you rub the right tiny ad, a genie comes out.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic