Q72: How does Serialization work, and what is the role of transient and serialVersionUID?

Serialization transforms object state into a byte stream (ObjectOutputStream).

  • serialVersionUID: Unique version identifier verifying that sender and receiver loaded compatible class definitions during deserialization (InvalidClassException on mismatch).
  • transient: Keyword applied to fields that MUST be skipped during serialization (e.g., passwords, transient caches).
Key Takeaways
  • serialVersionUID verifies class compatibility during deserialization.
  • transient fields are excluded from serialized byte streams.
Knowledge Check

What value does a transient int variable hold upon being deserialized from a byte stream?