Java Serialization Tutorial:
- Serialization in java
- Java Serialization interview questions and answers
- serialversionuid in java serialization
- externalizable in java
- Transient keyword in java
- Difference between Serializable and Externalizable in Java
Before understanding difference, let me provide a short note on Serializable and Externalizable.
Serializable :
Externalizable:
Externalizable vs Serializable:
Parameter
|
Serializable
|
Externalizable
|
---|---|---|
Marker interface
|
It is marker interface. You don’t have to provide implementation of any method.
|
Externalizable is not marker interface, you have to override writeExternal and readExternal method.
|
Control
|
Serializable interface has less control over serialization process and it is optional to override readObject and writeObject.
|
Externalizable interface has more control over serialization process and it is mandatory to override writeExternal and readExternal.
|
JVM uses reflection to perform serialization in the case of Serializable interface which is quite slow.
|
Programmer have to implement readExternal and writeExternal methods but it relatively results in better performance
|
|
Supersedes
|
NA
|
If you implement Externalizable interface and provide implementation of readExternal and writeExternal then it supersedes readObject and writeObject methods in that class. It is due to the fact that Externalizable extends Serializable interface.
|
Constructor called during Deserialization
|
Default constructor is not called during Deserialization process.
|
Default constructor is called during Deserialization process.
|