Example & Tutorial understanding programming in easy ways.

what is transient variables in java with example?

A transient variable is a variable that may not be serialized. You use the transient keyword to indicate to the Java virtual machine that the indicated variable is not part of the persistent state of the object. Variables that are part of the persistent state of an object must be saved when the object is archived.

Syntax of Transient Variable
transient type varName = value;

Example of transient variable in java
public class Stock {
private transient Logger logger = Logger.getLogger(Stock.class); //will not serialized
private String symbol; //will be serialized
private BigInteger price; //serialized
private long quantity; //serialized
}

Read More →