Mastering Java

Essential concepts for mastering Java programming

Member-only story

Mastering Java Serializable Interface with Examples

12 min readJun 18, 2023

--

Photo by Conny Schneider on Unsplash

Overview

In Java, Serialization is the conversion of the state of an object into a byte stream; deserialization does the opposite. Stated differently, serialization is the conversion of a Java object into a static stream (sequence) of bytes, which we can then save to a database or transfer over a network.

The Serializable interface in Java is used whenever you need to serialize an object, which means converting its state to a byte stream, so that it can be saved to a database, sent over a network, or stored in a file, etc. Conversely, this byte stream can be used to recreate the actual Java object in memory when needed. This process is called deserialization.

Here are some specific cases when you might want to use Serializable:

  1. Persisting application data: If you want to save the state of your application to disk, so that it can be reloaded later, you might want to use serialization. For example, many desktop applications allow you to save your work to a file, which can be reloaded later. The state of your work can be represented as a serialized object.
  2. Sending data over network: If you’re sending data to another machine, that data needs to be converted to a byte stream…

--

--

Mastering Java
Mastering Java

Published in Mastering Java

Essential concepts for mastering Java programming

Larry | Peng Yang
Larry | Peng Yang

Written by Larry | Peng Yang

Software Engineer in Tokyo. Aim to understand computer science very well. www.buymeacoffee.com/yangpeng. www.linkedin.com/in/yangpeng-tech.

Responses (1)