Externalizable vs Serializable

- 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.
- 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.

1 comment:

  1. Thanks for sharing the differences. Btw, I have also shared the differences between serializable and externalizable interfaces. Do let me know how do you like it.

    ReplyDelete