• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

new to java... about serialization...

 
Ranch Hand
Posts: 90
Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when we are going to serialize an object... the size of the serialized file is increases if we add a variable in the scope of the class.. but if we add a variable with in the scope of the member function... the size of the file in which we stored the object remains same..... the number of member functions does'nt increase the size of the file..but when we deserialize the object we get the exact state... how the serialization process stores the object...??? please explain... Thank you.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Serialization stores just the Object state. Variables stored in methods are not part of the Object state. They exist only in the scope of the method - that is when the method begins to run the variable gets created, and when the method comes to an end, the variable (effectively) gets thrown away. Since it is not part of the object - just part of the incidental execution of the method - it does not need to be serialized. When the Object is stored and later retrieved it will just be re-created when appropriate.

Methods aren't serialized either. They are part of the .class file, and get loaded via the class loader. All that Serialization does is make sure that the necessary state of the Object is maintained and of the proper version - the JVM makes sure the Class (and its methods) are loaded and so can be executed with the data.
 
Marshal
Posts: 79793
382
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Local variables are not members of the class; they are created and deleted whenever the method is invoked. So they would not change the "size" of the class.
I looked for a few articles: see whether these are of any use: 1 2 3, but I think you will find better descriptions in books like Horstmann and Cornell (in my copy 7th edition vol I, chapter 12, page 666).
 
Let me tell you a story about a man named Jed. He made this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic