What is a transient variable?


Ans:The transient is a keyword defined in the java programming language. Keywords are basically reserved words which have specific meaning relevant to a compiler in java programming language likewise the transient keyword indicates the following :

-- The transient keyword is applicable to the member variables of a class.
-- The transient keyword is used to indicate that the member variable should not be serialized when the class instance containing that transient variable is needed to be serialized.
For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null

public class Class1{


private transient String password;
}
Use:- In Java, serialization of an object allowed only when all the underlying objects of the object that is currently under serialization contains has a relationship, will not be allowed, some times the developer has no choice of implementing serializable marker interface on some classes as the classes might have been arrived from a third party and the developer has no control over them, but the developer needs to serialize the object's state, then the developer has the choice of marking the objects that not serializable as transient. 

People who read this post also read :



1 comments:

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here.
Kindly keep blogging. If anyone wants to become a Java developer learn from Java EE Online Training from India.
or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More