Teaching myself about How to Serialize & De-Serialize Objects in Java

Below is an example detailing steps to take on serializing and de-serializing an object.

Why do you need to know about serialization? The process of serialization allows an object’s state to be converted to bytes and transferred over a network or saved to a hard disk. While deserialization reconstructs the object from its bytes.

1. Create the class to be serialized and implement the Serializable interface.

NOTE: The NotSerializableException will be thrown if the object to be serialized does not implement the java.io.Serializable interface.

2. Use ObjectOutputStream class and writeObject(Object obj) method to write the objects to a file.

3. Use ObjectInputStream to deserialize the object and use the readObject() method to read the objects.

Happy Coding! 😃

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store