0% found this document useful (0 votes)
7 views

Serialization & Deserialization in Java

The document explains serialization and deserialization in Java, highlighting that serialization converts objects into byte streams for storage or transfer, while deserialization reconstructs objects from these streams. It outlines the implementation process, advantages, limitations, and scenarios for using serialization. Key points include the need for the Serializable interface, performance overhead, and security concerns.

Uploaded by

tarun.tyagi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Serialization & Deserialization in Java

The document explains serialization and deserialization in Java, highlighting that serialization converts objects into byte streams for storage or transfer, while deserialization reconstructs objects from these streams. It outlines the implementation process, advantages, limitations, and scenarios for using serialization. Key points include the need for the Serializable interface, performance overhead, and security concerns.

Uploaded by

tarun.tyagi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Nayankumar Dhome

[email protected]

𝐒𝐞𝐫𝐢𝐚𝐥𝐢𝐳𝐚𝐭𝐢𝐨𝐧
𝐚𝐧𝐝
𝐃𝐞𝐬𝐞𝐫𝐢𝐚𝐥𝐢𝐳𝐚𝐭𝐢𝐨𝐧
𝐢𝐧 𝐉𝐚𝐯𝐚

Let’s Swipe Right


by Nayankumar Dhome [email protected]

𝗪𝗵𝗮𝘁 𝗶𝘀
𝗦𝗲𝗿𝗶𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻?
Serialization is the process of
converting an object into a byte
stream. This byte stream can then be:

1. Stored in a file or database.

2. Transferred across a network.

3. Used for deep cloning of objects.

Let’s Swipe Right


by Nayankumar Dhome [email protected]

𝗪𝗵𝗮𝘁 𝗶𝘀
𝗗𝗲𝘀𝗲𝗿𝗶𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻?
Deserialization is the reverse
process of Serialization. It
reconstructs an object from a byte
stream, restoring its state in
memory.

Let’s Swipe Right


by Nayankumar Dhome [email protected]

𝗛𝗼𝘄 𝗦𝗲𝗿𝗶𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻
𝗪𝗼𝗿𝗸𝘀 𝗶𝗻 𝗝𝗮𝘃𝗮?
1. 𝗜𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁 𝘁𝗵𝗲 𝗦𝗲𝗿𝗶𝗮𝗹𝗶𝘇𝗮𝗯𝗹𝗲
𝗜𝗻𝘁𝗲𝗿𝗳𝗮𝗰𝗲 :
A class must implement the
𝗷𝗮𝘃𝗮.𝗶𝗼.𝗦𝗲𝗿𝗶𝗮𝗹𝗶𝘇𝗮𝗯𝗹𝗲 interface to
allow its objects to be serialized.

2. 𝗨𝘀𝗲 𝗢𝗯𝗷𝗲𝗰𝘁𝗢𝘂𝘁𝗽𝘂𝘁𝗦𝘁𝗿𝗲𝗮𝗺 :
Write the serialized object to a file or
output stream.

3. 𝗨𝘀𝗲 𝗢𝗯𝗷𝗲𝗰𝘁𝗜𝗻𝗽𝘂𝘁𝗦𝘁𝗿𝗲𝗮𝗺 :
Read the serialized object from
a file or input stream.

Let’s Swipe Right


by Nayankumar Dhome [email protected]

1. Serialization

Let’s Swipe Right


by Nayankumar Dhome [email protected]

2. Deserialization

Let’s Swipe Right


by Nayankumar Dhome [email protected]

𝗔𝗱𝘃𝗮𝗻𝘁𝗮𝗴𝗲𝘀 𝗼𝗳
𝗦𝗲𝗿𝗶𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻
1. Save objects to disk for
persistence.

2. Transfer objects between


systems (e.g., across a
network).

3. Simplify cloning and deep


copying.

Let’s Swipe Right


by Nayankumar Dhome [email protected]

𝗟𝗶𝗺𝗶𝘁𝗮𝘁𝗶𝗼𝗻𝘀 𝗼𝗳
𝗦𝗲𝗿𝗶𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻
1. 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 𝗼𝘃𝗲𝗿𝗵𝗲𝗮𝗱:
Serialization is slower than
other data storage methods.

2. 𝗖𝗼𝗺𝗽𝗮𝘁𝗶𝗯𝗶𝗹𝗶𝘁𝘆 𝗶𝘀𝘀𝘂𝗲𝘀:
Changes to a class can break
deserialization.

3. 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆 𝗰𝗼𝗻𝗰𝗲𝗿𝗻𝘀:
Serialized data can be
exploited if not handled
securely.

Let’s Swipe Right


by Nayankumar Dhome [email protected]

𝗪𝗵𝗲𝗻 𝘁𝗼 𝗨𝘀𝗲
𝗦𝗲𝗿𝗶𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻?
1. When saving the state of
objects for future use.

2. When transferring objects


over networks in distributed
applications.

3. During remote method


invocations (e.g., RMI).

Let’s Swipe Right


by Nayankumar Dhome [email protected]

IF YOU FIND
THIS HELPFUL,
LIKE AND
REPOST IT WITH
YOUR
CONNECTIONS

Nayankumar Dhome
[email protected] LIKE & REPOST

You might also like