• Post Reply Bookmark Topic Watch Topic
  • New Topic

A doubt in serialization  RSS feed

 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii to all.
I know that with serialization we can save state of an object to a persistent media with implementing java.io.Serializable interface , and in that interface there is no methods , how r the things working behind this implementations so that we are eligle for serializing that object.can anyone please explain this with full details...

I will be really thankful to him.

Thanks in advance.

Regards
Ajit
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serializable is a Marker Interface which while it has no methods, still infers behavior on the part of the implementor. Have a look at the documentation for java.io.ObjectOutputStream and java.io.ObjectInputStream which describe the details of how serialization is implemented.
 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thnx Joe Ess
 
Vladimir Nesov
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Object graph is being traversed, as I got it from implementation, in depth-first order. It may be important if object being saved contains many cross-references. If such DFS tree is too deep, it'll result in stack overflow. If while reading restoring code relies on part of graph not yet read, it'll end in some wrong behaviour. You can modify order by explicitly encoding it in readObject/writeObject methods.
 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Vladimir.

But still i have some doubt. Is this happening in background as we are implementing Serializable interface , if so then how sun is implementing this without providing any method in that interface.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ajit Amitav Das:
how sun is implementing this without providing any method in that interface.


The interface is just a signal to Java that it's OK to serialize an object. Somewhere inside the Java libraries is code that looks, conceptually, like

 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thavks Ernest,

I got some idea now on serialization.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!