Knowing the difference between Externalizable vs Serializable is important in two aspects, one – if could be asked as an interview question, two – you can use the knowledge to make better informed decision for performance improvement for applying serialization into your application.
Differences between Externalizable and Serializable
|Mostly, default serialization is easy to implement, but has higher performance cost.||Serialization done using |
|It’s hard to analyze and modify class structure because any change may break the serialization.||It’s more easy to analyze and modify class structure because of complete control over serialization logic.|
|Default serialization does not call any class constructor.||A public no-arg constructor is required while using |
Please note that
Externalizable interface in child interface of
Externalizable extends Serializable. So if any class implements
Externalizable interface and override it’s
readExternal() methods then first preference ig given to these methods over default serialization mechanism provided by JVM,
Read More about Externalizable and Serializable
- More Efficient Serialization with Externalizable in Java
- Java Serializable Interface Implementation Guide
- How Deserialization Process Happen in Java?
Drop me your questions in comments section.
Happy Learning !!