Professional Documents
Culture Documents
BSE2107 OOP II - Object Serialization and Deserialization-1
BSE2107 OOP II - Object Serialization and Deserialization-1
Deserialization in OOP
using Java
Object Serialization
• To read an entire object from or write an entire object to a file, Java
provides object serialization.
• Serialization is a process of converting an object into a sequence of
bytes which can be persisted to a disk or database or can be sent
through streams. The reverse process of creating object from
sequence of bytes is called deserialization.
• A serialized object is represented as a sequence of bytes that includes
the object’s data and its type information.
• After a serialized object has been written into a file, it can be read from
the file and deserialized to recreate the object in memory.
Object Serialization (Cont’d)
• A class must implement Serializable interface present in java.io package in
order to serialize its object successfully.
• Serializable is a marker interface that adds serializable behavior to the
class implementing it.
• Java provides Serializable API encapsulated under java.io package for
serializing and deserializing objects which include; java.io.Serializable,
java.io.Externalizable, ObjectInputStream and ObjectOutputStream, e.t.c.
• Marker Interface is a special interface in Java without any field and
method. Marker interface is used to inform compiler that the class
implementing it has some special behavior or meaning. Some examples of
marker interfaces are, java.io.serializable, java.lang.Cloneable, and
java.util.RandomAccess.
Object Serialization (Cont’d)
• Since object serialization makes exact copies of objects, it
makes it possible to clone objects without overriding the clone
method of Object class.
Object Serialization (cont.)