Serialization #1

Definition

Serialization is a process in which current state of Object will be saved in stream of bytes. As byte stream create is platform neutral hence once objects created in one system can be deserialized in other platform.

This Byte stream can be used for different purpose.

Write to Disk

Store in Memory

Sent byte stream to other platform over network

Save byte stream in DB(As BLOB)

Java has already provided out of the box way(java.io.Serializable Interface) to serialize an Object. If you want any class to be serialized then that class needs to implement this interface.

* Serializable interface is just a marker interface. There is no methods in it.

Example. Serializable Class

The serialVersionUID is used as a version control in a Serializable class. If you do not explicitly declare a serialVersionUID, JVM will do it for you automatically, based on various aspects of your Serializable class.