What is transient variable?A variable is said to be ‘transient’, which is not participated in object serialization. The variable with ‘transient’ access modifier is not persisted onto the object. Frequently updating values in a Java application will not be serialized by practice. Such variables can be specified as transient. What is transient variable? A variable declared as "transient" in a Serializable class cannot be serialized although the class is declared as serializable.
When the class is written to an ObjectStream, the value of the variable can't be written to the stream and when the class is retrieved from the ObjectStream the value of the variable becomes null.
|