In Java, we have a keyword ‘transient’ which is used to ignore the mentioned variables form getting serialized. What this means is that, when we write our data in a file, then there may be some data that we do not want to be written in the file. So, while writing the object in a file, the data members of that object which are declared as transient will be ignored by the compiler.

But some value must be stored at the place of that variable or else that may create problems while reading the object from the file. So, what the compiler does is that it ignores the actual value of that variable, and the default value assigned to that variable will be stored in the file.

Transient Keyword In Java

The modifier transient in java can be applied to the field members of the class to turn off  serialization on these field members. Every field marked as a transient will not be serialized.

You use a transient keyword to indicate to the java virtual machine that the transient variable is not part of a persistent state of the object.

The** transient** keyword plays a vital role to meet the security constraints. There are numerous real-life examples where we don’t want to store the private data in the file.

Another use case of the transient keyword is not to serialize a variable whose value can be calculated based on other serialized objects or systems such as the age of a person, current date, etc.

#transient #java

Transient Keyword In Java Example | Java Transient Keyword Tutorial
1.35 GEEK