• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Doubt about Serialization

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.....!!!










 
Greenhorn
Posts: 10
Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 10
Python Java Linux
  • Likes 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok , Got your point..!!

Thanks for your help...Devendra !!!






 
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think serialisation was removed from the syllabus.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ziggy's right... I don't see serialization listed in the objectives. Some one else could please confirm?
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See this link https://coderanch.com/t/549763/java-programmer-SCJP/certification/SCJP-syllabus#2494503
 
reply
    Bookmark Topic Watch Topic
  • New Topic