JavaIntermediate#serialization

What happens to static and transient fields during serialization?

Static fields belong to the class, not an instance, so they are never serialized. transient fields are explicitly excluded from serialization and get their default value (e.g., null, 0) upon deserialization.

Example
class Account implements Serializable {
  String owner;
  transient String password; // excluded from serialized bytes
}

Related Questions

1
JavaAdvanced#serialization

How can you customize the serialization process?

Open
2
JavaIntermediate#design-patterns

What is the Factory design pattern?

Open
3
JavaIntermediate#design-patterns

What is the Builder pattern and when should you use it?

Open