aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt about Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt about Serialization " Watch "Doubt about Serialization " New topic
Author

Doubt about Serialization

Rahul Bansode
Greenhorn

Joined: Nov 03, 2011
Posts: 18
I have one doubt about serialization topic...!!!

Where does the object gets created when we de-serialize the object from the file??

Is it Heap , Stack or a temporary storage??

According to me , It will be stack....Because the reference to that deserialized object is declared within the method(in which you are de-serializing ) itself .

Please correct , if I am wrong ???

and Suggest the answer with clarification.....!!!










Devendra Mahra
Greenhorn

Joined: Jul 17, 2011
Posts: 10

Objects will be created on heap. The reference can be a local variable or instance variable or any other type depending on your code.
The memory for objects will be allocated on heap.
Rahul Bansode
Greenhorn

Joined: Nov 03, 2011
Posts: 18

But objects gets created on heap , only if you are using new operator.

And construction of deserialized object and Normal object is totally different....!!!

So how come that object will be created on heap.

Please clarify....



Devendra Mahra
Greenhorn

Joined: Jul 17, 2011
Posts: 10



In sample code above, serialization and deserialization are happening in separate methods, the reference variable at time of deserialization i.e. in method deserializeCat is a local variable (c1). If the memory was allocated from stack, then the object will not be accessible from method other than deserializeCat. The memory allocation in case of deserialization is taken care of by readObject method

java 6 api docs ObjectInputStream

The default deserialization mechanism for objects restores the contents of each field to the value and type it had when it was written. Fields declared as transient or static are ignored by the deserialization process. References to other objects cause those objects to be read from the stream as necessary. Graphs of objects are restored correctly using a reference sharing mechanism. New objects are always allocated when deserializing, which prevents existing objects from being overwritten.

Reading an object is analogous to running the constructors of a new object. Memory is allocated for the object and initialized to zero (NULL). No-arg constructors are invoked for the non-serializable classes and then the fields of the serializable classes are restored from the stream starting with the serializable class closest to java.lang.object and finishing with the object's most specific class.
Rahul Bansode
Greenhorn

Joined: Nov 03, 2011
Posts: 18
Ok , Got your point..!!

Thanks for your help...Devendra !!!






O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

I think serialisation was removed from the syllabus.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Ziggy's right... I don't see serialization listed in the objectives. Some one else could please confirm?
O. Ziggy
Ranch Hand

Joined: Oct 02, 2005
Posts: 430

See this link http://www.coderanch.com/t/549763/java-programmer-SCJP/certification/SCJP-syllabus#2494503
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt about Serialization
 
Similar Threads
Garbage Collection Doubt
doubt
Doubt on RequestDispatcher
doubt based on construtor
Serialization doubt