Serialization is the process of converting flexible in memory objects to a rigid binary implementation.
Basically you convert an object into a bytestream.
That stream can then be:
The reverse process is called Deserialization. It involves taking the bytestream and loading it back into memory as an object. That object can then be programmatically manipulated.
In java to serialize a type you first make it implement
java.io.Serializable interface. This interface was introduced back in JDK 1.0.
Serializable interface is a marker interface. This means that it has neither data members nor methods. It basically marks the interface as having certain capabilities.
Serialization and Deserialization is implemented using two classes defined in thej
When an object is serialized the result is a sequence of bytes.
This sequence of bytes contains:
When an object is deserialized, the sequence of bytes then gets decorded back into a new equivalent instance.
However note that for successful serialization and deserialization you should not change the class names, field names and field types. Doing this can break compatibility between the old and new versions of the class.