top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is a transient variables in java?

+2 votes
438 views
What is a transient variables in java?
posted Mar 2, 2016 by Deepika Jain

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Transient variable in Java is a variable whose value is not serialized during Serialization and which is initialized by its default value during de-serialization, for example for object transient variable it would be null. this behavior can be customized by using Custom Serialized form or by using Externalizable interface. transient variable is used to prevent any object from being serialized and you can make any variable transient by using transient keyword. By the way difference between transient and volatile variable in Java is a famous Java interview question but transient variable is completely different than volatile variable which we have discussed in our post What is volatile variable in Java. In next section we will see complete example of serialization where we will first serialize an instance of Book class which implements Serializable and than de-serialize to see What is the value of transient variable after deserialization.

answer Mar 2, 2016 by Karthick.c
Similar Questions
+1 vote

Why we need transient keyword to prevent serialization of a particular data member. we can also make it static because static data member can not be serialized.

...