In Java, the transient keyword is used to mark a member variable (field) not a part of the persistent state of an object, i.e. the field will not be persisted when its parent object is serialized.

The following example shows a class which has a transient variable:

class Rectangle {
    int width;
    int height;
    transient long area;
}
When an object of Rectangle class is being serialized, the fields width and height will be persisted, but the field area.

The transient keyword can be only applied for member variable, not for class, method and local variable.

See all keywords in Java.

 

Other Recommended Tutorials:



 


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment