Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Serializable  RSS feed

 
Pankaj.insatyam kumar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can Any one please do tell me what is difference betweeen Externizable and Serialiazable?
 
Santhosh Kumar
Ranch Hand
Posts: 242
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In basic terms, serialiazation means converting a java Object into a series of bytes, which can be persisted and/or transported over the wire to have the Object reconstructed later on.

JDK provides the easy way of serializing a Java object and that is implementing the java.io.Serializable interface. By implemetning the interface, you are approving jvm that this object can be persisted. Note that Serializable is marker interface. You need not provide any implementation.

While convering the object, jvm will write out all details about the object which is required to have the object constructed back like all attributes (excluding transients).

This out-of-box method of serializing may not be efficient all the time. Consider you have a object which holds a reference to an cached content. If you serialize this object, jvm will write out the reference and also the actual content referred by the reference, which can be quite inefficient than just transporting the reference and using that to get cached data in other side. In such cases you can take control over the way objects are converted into the bytes and back into object. That is Externalizing.

To Externalize you would tell the JVM that, "Hey, I know how to save and resurrect myself. So let me take the control" by implementing the java.io.Externalizable interface. When you do so, you have provide the implementation for writeExternal and readExternal methods.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!