Serializable vs Externizable

Serialization vs Externalization

Serializable is a marker interface (an interface with no methods) Unlike Serializable, Externizable is a standard interface with two methods defined to be implemented by the implementing class.
Serailization is a recursive process, all non-transient variables and super classes in the object hierarchy will be serialized causing an unnecessary overhead User defines what should be serialized and what should not. Hence it is more optimized. Should be preferred for "Fat Objects" 
Serialization uses reflection mechanism for marshalling and un marshalling the objects.  Marshalling/Unmarshalling process is user defined.
During de-serialization no constructor is called, hence initialization done in constructor will be skipped.  During de-serialization default constructor is invoked
A default construtor definition is not mandatory when parameterized constructor(s) are defined An explicit default constructor definition is mandatory, when parameterized constructor(s) is defined. Throws an exception if no default construtor in such cases.
While flattening an Object implementing Serializable requires more space on disk as it store additional inforamation(field names, types super classes info and other metadata) along with the field values An object implementing Externizable, will take lesser disk space while persiting it.
The default serialization mechanism adapts to class changes due to the fact that metadata is automatically extracted from the class definitions Externalization isn't very flexible and requires you to rewrite your readExternal and writeExternal code whenever you change your class definitions.
Implicitly serialize super class. If you are subclassing your externalizable class, you have to invoke your superclass’s implementation. So this causes overhead


Popular posts from this blog

Using Solr Spellchecker from Java

Importing / Indexing MySQL data into Solr

Custom PagingNavigator for SEO friendly URL