15/01/2012
- Externalizable is an interface that enables you to define custom rules and your own mechanism for serialization. Serializable defines standard protocol and provides out of the box serialization capabilities.
- Externalizable extends Serializable.
- Implement writeExternal and readExternal methods of the Externalizable interface and create your own contract / protocol for serialization.
- Saving the state of the supertypes is responsibility of the implementing class.
- You might have seen in my previouse article on how to customize the default implementation of Serializable. These two methods readExternal and writeExternal (Externalizable) supersedes this customized implementation of readObject and writeObject.
- In object de-serialization (reconsturction) the public no-argument constructor is used to reconstruct the object. In case of Serializable, instead of using constructor, the object is re-consturcted using data read from ObjectInputStream.
- The above point subsequently mandates that the Externalizable object must have a public no-argument constructor. In the case of Seriablizable it is not mandatory.

- Behaviour of writeReplace and readResolve methods are same for both Serializable and Externalizable objects. writeReplace allows to nominate a replacement object to be written to the stream. readResolve method allows to designate a replacement object for the object just read from the stream.
- In most real time scenarios, you can use Serializable and write your own custom implementation for serialization by providing readObject and writeObject.
You may need Externalizable,
- If you are not happy with the way java writes/reads objects from stream.
- Special handling for supertypes on object construction during serialization.
















nice explanation …. thank u
abhijit on January 16th, 2012 11:47 amEvery thing what you write is very help full.
Thank you so much.
Anonymous on January 16th, 2012 11:56 amEvery thing what you write is very help full.
Thank you so much.
Sirisha Gundala on January 16th, 2012 11:57 amright to point explaination
DC on January 16th, 2012 12:33 pmThank you so much sir it is really helpful. :)
Anshul Jaiswal on January 16th, 2012 1:20 pmYou can also change default serialization behavior with Serializable interface by overriding writeObject and readObject methods.
Shamil on January 16th, 2012 3:30 pmSuperb Post…I like the way ur present the things with graphical images.
Dev Ghotkule on January 16th, 2012 4:14 pmthanks again…love your posts that educate quickly, efficiently and to the point:)
Irina on January 17th, 2012 1:55 amgreat post
utkal on January 17th, 2012 8:15 amKalakure Joe…
Suresh on January 18th, 2012 10:41 amHi Joe,
Jagdish on January 18th, 2012 9:12 pmI am Jagdish, i have some question in Java.
Please give me ur email id so that i can contact
you….
Hi
I am Hari, i found exactly what i was looking for in this post, it would be great if you can provide some example here as well. Keep up the good work you. Thanks for sharing your knowledge.
Hari on January 19th, 2012 8:10 amthank yu so muchhhh….
i have passed my interview with CTS…
main reason is your site and it helped me a lot, thanks..
Preethi on January 19th, 2012 3:04 pmthank you
jose on February 3rd, 2012 11:34 amits really helpful and knowledgeable.
Ruchika on February 3rd, 2012 12:52 pmThanks so much Sir,
Really it’s knowledge jargon it’s amazing Wow…
Israr on March 14th, 2012 11:47 pmif we use serialization to save an object on memory then we modify that class(definatly object has changed now) now we deserialize that object what will be happen, kindly answer
Farid on March 20th, 2012 3:03 pmHi Joe,
What a blog you have created. It is really very much useful when we are facing interviews. I have learnt a lot from your blog.
Thanks,
Amzad on March 21st, 2012 9:59 amAmzad
Thank you, It is really helpful.
Ganesh on April 3rd, 2012 3:32 pmIT is good but not best.
Anonymous on May 18th, 2012 3:55 pmIt has very useful information for the beginners… good job..joe
Manjula.A on May 19th, 2012 12:12 pmthis site is very interesting and it is presented in the good manner….
Prabu.R on May 21st, 2012 12:42 pmThank u!
/Vj
Vj on May 22nd, 2012 1:41 pm