Difference/Comparison between/of Serializable and Externalizable

I’m asked the difference between the two interfaces, Serializable and Externalizable more often than i’d like. It’s pretty simple really. Serializable does all the dirty work for you, it writes the object to the output stream on it’s own without you having to bother about anything at all. Externalizable on the hand makes you do ALL the work. You must handle the reading and writing on your own.

 

The easiest difference to remember is the methods to be implemented by the class. That information can be easily obtained from the javadocs.

The major difference however, the one most people miss, is that the default no-arg constructor is called during the reconstruction of an object who’s class implements the Serializable interface. However, this call is not made for a class which implements the Externalizable interface.

Hope that helps.

Share and Enjoy:
  • del.icio.us
  • Google Bookmarks
  • DZone
  • Reddit
  • Digg
  • Facebook
  • Netvibes
  • StumbleUpon
  • Technorati
  • LinkedIn
  • MySpace
  • Print
  • Slashdot
  • Share/Bookmark

Tags: , , ,

Leave a Reply