Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is handle and first reference in serialization

 
kumarth ravi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading on serialization topic from the the following url:
http://java.sun.com/j2se/1.5.0/docs/guide/serialization/spec/serial-arch.html#5800

In 1.2 Writing to an Object Stream section,I could not understand the following statement.Can you explain this,especially the first reference and handle.

statement
---------
Within a stream, the first reference to any object results in the object being serialized or externalized and the assignment of a handle for that object. Subsequent references to that object are encoded as the handle.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Say you had two objects a and b. a has a variable that refers to b and b has a variable that refers to a. When you serialize a the object stream drills down and serializes b. While doing that it finds a reference to a. If it tried to serialize a from scratch again it would be in an endless loop. Instead it recognizes that a is already in stream (maybe not complete yet?) so it can serialize b with a "handle" to a. When it de-serializes it can use the handles to reconstruct the reference variables.

The same thing can happen in more complex object graphs even without cycles, say maybe a, b and c all refer to d.

That seemed to take way too many words to describe. Did it make any sense?
 
kumarth ravi
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your clear explanation.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic