Wednesday, February 24, 2016

What is transient in Java ?

About transient 
transient is a keyword which is used with the member variable of a class to exclude a particular variable from the serialization process (In serialization an object state is saved in bytestream by JVM).

One cannot use the transient keyword with the static variable.

transient variable initialized with the default value during de-serialization
(In Deserialization process object state is recovered by JVM except the static and transient variablers)

also take a look at the what is volatile keyword in java

Advantage
many times as a developer we do not want to serialize some members of object at that one can use the transient keyword and it gives us flexibility in this case as per our requirement.

UseCase
may times some variables value is dependent on other variable, means we can gain value of particular variable from other variables value at that time we can exclude particular variable from being serialization process.
sometimes we use some members of class just for logs purpose those variables also no need to be serialize.

No comments:

Post a Comment

Scrum and Scrum master

Scrum  Scrum is a framework which helps a team to work together.  It is like a rugby team (the scrum name comes from rugby game). Scrum enco...