Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Why Transient:** Excludes field from serialization. Use for: computed/cached values, sensitive data (passwords), non-Serializable (Thread, Socket). **Behavior:** On deserialize, transient fields get default (null, 0, false). Custom logic via writeObject/readObject....
Why Transient: Excludes field from serialization. Use for: computed/cached values, sensitive data (passwords), non-Serializable (Thread, Socket).
Behavior: On deserialize, transient fields get default (null, 0, false). Custom logic via writeObject/readObject.
Production: Mark passwords, connection handles, threads. For Spark: broadcast variables and accumulators are serialized—ensure DTOs don't include non-serializable refs. transient is explicit opt-out.
private transient String password;
private transient Thread worker;
Red Flag: Serializing object with Thread field without transient. Pro-Move: 'We use transient for lazy caches in our DTOs—recomputed after deserialization on worker.'
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.