answersLogoWhite

0

What is a transient variable?

Updated: 8/11/2023
User Avatar

Wiki User

12y ago

Best Answer

Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the val ue of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

A transient variable is a variable that may not be serialized

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a transient variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the purpose of transient keyword in Java?

A variable which is declared as transient will not be serialized. This means that when you use an ObjectOutputStream to store the current state of a class, anything labeled as transient will be skipped over.A common use of this keyword is to ensure that sensitive user information (usernames, passwords, etc.) is not accidentally saved to a file.


Can transient variables be declared as 'final' or 'static'?

Transient Variables are those that do not get serialized during the Serialization process. A Static variable is one that is mapped to the Class and is not mapped to any object instance and hence they would not get serialized. So, there should be no problem with declaring a transient variable as static. On the other hand, A final variable is one that's value cannot change. So if you declare a final variable as transient, it would get stored as null during serialization and when you try to de-serialize the variable, you will get errors because, the variable is final and you cannot assign values for it and it is saved as null during serialization. Result: Yes you can have static transient variables but not final transient variables.


Why do persistent programming language allow transient object?

If you mark an instance variable as transient, you're telling the JVM to skip (ignore) this variable when you attempt to serialize the object containing it. Don't worry about Serialization just yet. That is a cool feature of java that we shall be seeing in greater detail in one of the subsequent chapters. For not it is enough to know that a transient variable will be ignored when the object is serialized.


What is the use of volatile keyword in java?

Transient keyword is used by java programmers for variables, if the programmer does not want to store them permanently. In case of serialization, the fields which are kept transient, are not the part of serialization process and not serialized. Volatile is used along with the variable name, that can change its value without informing the JVM. The system clock values are stored in Volatile variable. They do not inform JVM when they change their value.


What is an AC Transient response?

ac transient analysis is frequency domain analysis.

Related questions

What is the purpose of transient keyword in Java?

A variable which is declared as transient will not be serialized. This means that when you use an ObjectOutputStream to store the current state of a class, anything labeled as transient will be skipped over.A common use of this keyword is to ensure that sensitive user information (usernames, passwords, etc.) is not accidentally saved to a file.


Can transient variables be declared as 'final' or 'static'?

Transient Variables are those that do not get serialized during the Serialization process. A Static variable is one that is mapped to the Class and is not mapped to any object instance and hence they would not get serialized. So, there should be no problem with declaring a transient variable as static. On the other hand, A final variable is one that's value cannot change. So if you declare a final variable as transient, it would get stored as null during serialization and when you try to de-serialize the variable, you will get errors because, the variable is final and you cannot assign values for it and it is saved as null during serialization. Result: Yes you can have static transient variables but not final transient variables.


How can you prevent a member variable from becoming serialized?

By marking it transient.


Why do persistent programming language allow transient object?

If you mark an instance variable as transient, you're telling the JVM to skip (ignore) this variable when you attempt to serialize the object containing it. Don't worry about Serialization just yet. That is a cool feature of java that we shall be seeing in greater detail in one of the subsequent chapters. For not it is enough to know that a transient variable will be ignored when the object is serialized.


What is the use of volatile keyword in java?

Transient keyword is used by java programmers for variables, if the programmer does not want to store them permanently. In case of serialization, the fields which are kept transient, are not the part of serialization process and not serialized. Volatile is used along with the variable name, that can change its value without informing the JVM. The system clock values are stored in Volatile variable. They do not inform JVM when they change their value.


A sentence for the word transient?

Nature is transient.


What is transient market segment?

transient market


What is a transient market segments?

transient market


What the meaning of transient room?

what is the meaning of transient room


How do you use transients in a sentence?

it will be transient fashions.


How do you calculate the average transient rate?

Average Transient Rate


Is there such thing as transient appendicitis?

Some attacks of appendicitis are mild and transient.