• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Does private instance variable participate Serialization process?

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have few doubts related to object serialization. Those are as follows:



a] Does instance variable with private access modifier takes part of
object serialization?

b] Does static variable participate in object serialization process?

c] Does instance variable with final modifier participate in object
serialization process?


Thanks in advance,

Regards,
Gopal
 
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
b] NO, static variable does not participate in serialization process. Serialization is strictly restiricted to object and Static variables belong to class. So, Static variables are not serialized.

For other two options, i feel the answer is yes. All the instance variables are serialized except for those who are defined as transient.
 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I made edition on my previous answers as i mismatched the and [c] choice, sorry for that, now its fine

a] Does instance variable with private access modifier takes part of
object serialization? [b]Yes


b] Does static variable participate in object serialization process? They simply can't as serialization is associated with objects, static implies class variables.

c] Does instance variable with final modifier participate in object
serialization process? Yes

The below code will give you clear picture-:


This will give you output as-:

before: Fido 56 German Shepherd
before: Sham 56 Australian Shepherd
before: Gathj 56 Beagle
after: Fido 56 German Shepherd
after: Sham 56 Australian Shepherd
after: Gathj 56 Beagle



Here you can see that for static variables serialization has no meaning. As they are class variables.
[ September 17, 2008: Message edited by: Pranav Bhatt ]
 
V. Potluri
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi chander and Pranav,

Thanks for spending your precious time to clear my doubt.
Have a pleasant day ahead!

Regards,
Gopal
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic