i

JAVA Complete Course

Serialization

Serialization is the process of converting object’s state into a byte stream, while deserialization is the opposite operation. Serialization converts Java object into a sequence (static stream) of bytes which can then be transferred over a network or saved to a database.

ObjectInputStream and ObjectOutputStream are classes which extend java.io.InputStream and java.io.OutputStream respectively. ObjectOutputStream can write primitive types and graphs of objects to an OutputStream as a stream of bytes. These streams can subsequently be read using ObjectInputStream.

Let’s see an example. We have a Car class, we will create instance of it, then we will serialize it and after that we will deserialize it.

A screenshot of a cell phone

Description automatically generated