Last Updated on 21 August 2019   |   Print Email
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.
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.
Comments