top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is transient variable in JAVA

+6 votes
448 views
What is transient variable in JAVA
posted Dec 6, 2013 by Prachi Agarwal

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
The transient keyword in Java is used to indicate that a field should not be serialized.

Variables can be marked transient to indicate that they are not part of the persistent state of an object.

For example, you may have fields that are derived from other fields, and should only be done so programmatically, rather than having the state be persisted via serialization.

1 Answer

+1 vote
 
Best answer

transient is used to indicate that a class field doesn't need to be serialized. Probably the best example is a Thread field. There's usually no reason to serialize a Thread, as its state is very 'flow specific'.

answer Dec 8, 2013 by Neeraj Pandey
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.

...