View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All
View All

Transient in java: What is, How Does it Work?

By Pavan Vadapalli

Updated on Mar 28, 2025 | 3 min read | 5.6k views

Share:

What is Transient in java?

Transient in java is a variable modifier used to avoid serialization. In other words, if an object of a data structure is marked as transient, then the serialization of data structure will not happen.  In simpler words, the transient keyword is used if the value of a specific keyword is not to be stored in a file during serialization. Therefore, the variable’s original value is ignored and the default value of its data type is saved when a transient keyword is encountered by JVM. 

In real-life examples, there are times when private and confidential data is not to be saved in a file. It is, therefore, at this point, the transient keyword plays an important role in order to meet the security constrictions. During serialization, it is always good to use transient keywords with private confidential fields.

Check out our free technology courses to get an edge over the competition.

What is the importance of transient in Java keyword?

By default, all of the object’s variables get stored as bytes in a file or are transferred across the network. In some cases, one wants to avoid persisting with some variables as they are not required. In that circumstance, one can declare these variables as transient. This is the main purpose of the transient keyword.

Check Out upGrad’s Software Development Courses

What is Serialization and Deserialization in Java?

Serialization is a mechanism that converts an object into a stream of Byte. In contrast, the opposite is Deserialization, where the stream of Bytes creates the actual Java object in the memory.

We can well understand the process given in the image given below. (Image courtesy: Google Search). It is clear here that Object gets converted in Byte stream during Serialization and during Deserialization stream of Bytes recreates the Java’s actual object in the memory.

Coverage of AWS, Microsoft Azure and GCP services

Certification8 Months

Job-Linked Program

Bootcamp36 Weeks

When and where is the transient keyword used in java?

Let us now understand when and where we should be using transient in java.

  1. To be implemented when we want secure information not to leak outside.
  2. At times when there is no sense to serialize some fields.
  3. At such times when there are fields that are calculated or derived from other fields.

Let’s try and write a very basic example to understand what exactly the above analogy means. (Image courtesy: Google Search)

Some more related terms and their definitions:

  1. A transient field is a field that is modified with the transient keyword.
  2. Transient fields are important as they have some control over the serialization process and also helps in excluding some object properties in this process.
  3. A transient variable is a variable that may not be serialized.
  4. Serialization can be done as many times as is required. The result would be the same.
  5. A field that is declared with a transient modifier will not take part in the serialized process.
  6. If one wants to avoid variable data being written to a file, one should make that variable transient.
  7. The meaning of the word transient by Google is impermanent or lasting for a short time.
  8. So, if you want to make anything impermanent, use transient in java keyword.

At upGrad, we understand the importance of practical, hands-on learning – especially when it comes to software development. As a result, our courses and training initiatives have practicality at their very core. One such initiative is Full Stack Development Bootcamp which will help you develop all the relevant skills required to excel in full-stack development. 

Pavan Vadapalli

900 articles published

Get Free Consultation

+91

By submitting, I accept the T&C and
Privacy Policy

India’s #1 Tech University

Executive PG Certification in AI-Powered Full Stack Development

77%

seats filled

View Program

Top Resources

Recommended Programs

upGrad

AWS | upGrad KnowledgeHut

AWS Certified Solutions Architect - Associate Training (SAA-C03)

69 Cloud Lab Simulations

Certification

32-Hr Training by Dustin Brimberry

upGrad KnowledgeHut

upGrad KnowledgeHut

Angular Training

Hone Skills with Live Projects

Certification

13+ Hrs Instructor-Led Sessions

upGrad

upGrad KnowledgeHut

AI-Driven Full-Stack Development

Job-Linked Program

Bootcamp

36 Weeks