Monday, 17 October 2016

Java Tutorial : Java IO (Java serializable vs externalizable | serialization vs externalization -V7)

Master Core Java with Ram N Java!

Subscribe today for in-depth, easy-to-follow Java tutorials and core concepts!

SUBSCRIBE TO RAM N JAVA

The Limitations of Standard Serializable

The standard Serializable interface is a marker interface that tells the JVM to handle serialization automatically. While convenient, it comes with key drawbacks:

  • Lack of Control: The JVM serializes all non-transient fields across the entire class hierarchy, including metadata, which consumes unnecessary bandwidth and storage.
  • All-or-Nothing Deserialization: You cannot selectively choose which fields to deserialize.
  • Performance Overhead: Calculating default serialVersionUID values across complex inheritance trees can impact runtime performance.

Externalizable: Complete Control Over Serialization

To take full command of the serialization process, Java provides the java.io.Externalizable interface. Unlike Serializable, it gives developers direct responsibility over what data gets written to and read from the stream:

  • writeExternal(ObjectOutput out): Define the exact fields and format to serialize.
  • readExternal(ObjectInput in): Restore only the required fields in the matching order.

Key Requirements for Externalizable

When implementing Externalizable in your Java classes, keep these core rules in mind:

  • Your class must provide a public no-argument (zero-arg) constructor, which the JVM invokes during deserialization before calling readExternal.
  • Superclass state is not automatically written—you must explicitly manage inheritance if required.

Watch More Related Java Tutorials

Explore more Java serialization concepts from our channel:


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

Click the below Image to Enlarge 
Java Tutorial : Java IO (Java serializable vs externalizable | serialization vs externalization -V7) 
Java Tutorial : Java IO (Java serializable vs externalizable | serialization vs externalization -V7) 
Java Tutorial : Java IO (Java serializable vs externalizable | serialization vs externalization -V7) 
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