aspose file tools*
The moose likes Beginning Java and the fly likes new to java... about serialization... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "new to java... about serialization..." Watch "new to java... about serialization..." New topic
Author

new to java... about serialization...

Sanjeev Charla
Ranch Hand

Joined: Apr 02, 2009
Posts: 90

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.
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

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.


Steve
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40064
    
  28
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: new to java... about serialization...