Java Keyword Transient

The reserved keyword transient is one of the reserved keywords that your not allowed to use as the name of a variable in your Java programs.

The transient keyword is used to identify a member variable as not to be serialized when it is persisted to streams of bytes. What does that mean? Good question, let’s be a little more practical.

When an object is transferred through a network, the object needs to be “serialized” for consistency. The serialization process converts the object state to serial bytes. The serialized bytes are then sent over the network and the object is recreated from those bytes.

So if you mark a member variable with the keyword transient, the variable will not be transferred. Remember that you can only define member variables as transient, not classes.

Let’s see an example of how to define a transient variable in the Java programming language.

class Widget {

    int length;
    int width;
    int height;
    transient int size;
}


The complete list of Java reserved keywords contains a total of 53 keywords that are unable to be used as variable names.

Add a Comment

Your email address will not be published. Required fields are marked *