Serialization and Externalization are mechanisms in Java that facilitate the storage and retrieval of object states. Serialization involves converting an object’s state into a format that can be quickly persisted to a file or transmitted over a network. This enables objects to be reconstructed later, even across different platforms or programming languages.
On the other hand, externalization extends serialization by allowing developers to customize the serialization and deserialization processes. Objects implementing the Externalizable interface can define their writeExternal() and readExternal() methods
Difference b/w Serialization & Externalization
Serialization | Exteralization |
---|---|
It’s meant for default Serialization | it is meant for customized Serialization |
Here everything takes care by JVM and programer doesn’t have any control | Here Everything take care by programmer and JVM doesn’t have any Control |
In this case it’s always possible to save total object to the file and its not possible to save part of the object | Based on our requirement we can save either total object are |
Relatively performanced is low | Relatively performance is high |
It is the best choice if we want to save entire object to the file | It is the best choice if we want to save part of object to the file |
The Serialization Interface does not contain any method and it is a marker Interface | Externalization Interface contains two methods writeExternal() and readExternal() |