Friday, 23 September 2016

Java Tutorial : Java IO (Java Serialization_V1)

🚀 Enjoying Java Tutorials?

Subscribe to Ram N Java for clean, beginner-friendly core Java tutorials and interview prep!

🔔 Subscribe to Ram N Java

Java Serialization Explained

Serialization is one of the core foundational features of Java IO. It provides a standard, platform-independent mechanism for converting the state of an object into a byte stream. This byte stream can be written to a file, stored in a database, or transmitted across network connections, making it vital for enterprise applications and distributed systems.

How Java Serialization Works

The serialization architecture in Java revolves around two complementary processes:

  • Serialization: Flattens an in-memory object graph into a sequential stream of binary bytes using ObjectOutputStream.writeObject().
  • Deserialization: Reads the binary byte stream and reconstructs the identical object graph back into heap memory using ObjectInputStream.readObject().

Core Components of Serialization

1. The java.io.Serializable Interface

Classes must explicitly opt in to serialization by implementing java.io.Serializable. Because it contains no methods or variables, it acts as a marker interface that instructs the JVM runtime that objects of this class are safe to serialize.

2. Exclusion with transient and static

  • transient: Prevents sensitive or temporary fields from being serialized. These fields will be initialized to their default values (e.g., null, 0) upon deserialization.
  • static: Belongs to the class rather than an object instance, meaning static variables are never saved into the serialized stream.

3. serialVersionUID Compatibility

The serialVersionUID constant is used to verify that the sender and receiver of a serialized object have loaded classes that are compatible with respect to serialization.

Quick Reference Table

Component Description
Serializable Marker interface required for classes to be serializable
ObjectOutputStream Writes object state to a byte stream via writeObject()
ObjectInputStream Reconstructs objects from a byte stream via readObject()
transient Omits fields from serialization

Related Tutorials from Ram N Java


Click here to watch in Youtube :
https://www.youtube.com/watch?v=6RhAJWsKYCc&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java IO (Java Serialization_V1) 
Java Tutorial : Java IO (Java Serialization_V1) 
See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Tutorials