Tuesday, 18 October 2016

Java Tutorial : Java IO (Java Serialization and Deserialization notes)

Learn Core Java on Ram N Java!

Subscribe today for concise, clear, and practical Java tutorials!

SUBSCRIBE TO RAM N JAVA

1. The Transient Keyword and Default Values

When you serialize an object, you might not want every single field saved. If you declare a field as transient, Java will skip it during serialization.

Upon deserialization, transient fields automatically receive their language defaults:

  • Object references (like String) are set to null.
  • Numeric types (like int) are initialized to 0.
  • Boolean fields are initialized to false.

2. Why Static Variables Are Not Serialized

A common question in Java interviews is whether static fields are serialized. The short answer is no. Serialization preserves the state of a specific object instance. Because static variables belong to the class itself rather than any individual instance, they are not saved into the byte stream.

3. Object Graph Traversal & NotSerializableException

During serialization, the runtime navigates the entire object graph. If an encountered object does not implement java.io.Serializable, the JVM throws a NotSerializableException indicating the offending class.

The Fix: If you cannot modify that class to make it serializable, declare the reference holding that object as transient.

Watch More Related Java Tutorials

Deepen your understanding of Java IO and serialization with these tutorials:


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

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