Friday, 23 September 2016

Java Tutorial : Java IO (Java Serialization_V5)

🚀 Enjoying Java Tutorials?

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

🔔 Subscribe to Ram N Java

What is Java Serialization?

In Java, Serialization is the process of converting the state of an object into a sequence of bytes. This byte stream can then be persisted into a file, stored in a database, or transmitted across a network to another JVM.

The reverse process—recreating the actual Java object from that byte stream in memory—is called Deserialization.

Core Classes and Interfaces

Java provides built-in support for object persistence in the java.io package through several key components:

  • Serializable Interface: A marker interface (it has no methods or fields). A class must implement this interface to signal to the JVM that its instances can be safely serialized.
  • ObjectOutputStream: A high-level processing stream that converts Java objects into byte streams using its writeObject() method.
  • ObjectInputStream: Reads the raw byte stream and reconstructs the original object in memory using its readObject() method.

Why Do We Need Serialization?

  • Persistence: Saves the exact state of objects to disk files or databases across application restarts.
  • Deep Copying: Allows cloning complex, deeply nested object graphs by writing to and reading from a byte array.
  • Network Communication & RMI: Facilitates transferring objects between different JVMs in distributed systems and microservices.

Important Concepts to Remember

  • transient Fields: Fields marked with the transient keyword are excluded from serialization and receive default values upon deserialization.
  • static Fields: Static variables belong to the class rather than an individual instance, so they are never saved in the serialized byte stream.
  • serialVersionUID: A unique identifier that ensures class compatibility between the sender and receiver during deserialization.

Related Tutorials from Ram N Java


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

Click the below Image to Enlarge
Java Tutorial : Java IO (Java Serialization_V5) 
Java Tutorial : Java IO (Java Serialization_V5) 
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