Java Quick Reference
  Language Fundamentals
  Operators and Assignments
  Flow Control and Exceptions
  Declarations and Access Control
  Garbage Collection
  Overloading and Overriding
  Threads
  The java.lang Package
  The java.util Package
  The java.awt Package
  The java.io Package
  References
  Miscellaneous Notes
  Tips & Traps
  Mock Exams

The java.io Package - Serialization

Serialization (JCL1)

  • serialization is the process of converting an object to a stream of bytes in such a manner that the original object can be rebuilt (lets you write an object to a file or other data container)
  • an object can be serialized only if it's class implements the Serializable or Externalizable interface; it's superclass must have a no-arg default constructor or be Serializable itself
  • a classes serializable fields are all of its nontransient and nonstatic fields; this applies to all public, protected, package and private fields (JCL1)
Note
Only the accessible fields of the superclasses are serialized
  • the serialized fields are written out using ObjectOutputStream.defaultWriteObject() and read back using ObjectOutputStream.defaultReadObject()
  • all the objects referred to directly or indirectly are also serialized
  • if a field contains an object that is not serializable, a NotSerializableException is thrown
  • deserialization is the process of restoring a serialized object to a copy of the original object
  • all Java primitive types, arrays, Strings and objects can be serialized/deserialized
  • primitive types can be serialized using DataInputStream Interface and deserialized using DataOutputStream Interface
Pkg Overview Data Streams Character Streams Byte Streams File Class Readers & Writers
Filter Streams Data Input/Output Reading & Writing Files Serialization