answersLogoWhite

0

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.

User Avatar

Wiki User

12y ago

Still curious? Ask our experts.

Chat with our AI personalities

TaigaTaiga
Every great hero faces trials, and you—yes, YOU—are no exception!
Chat with Taiga
ReneRene
Change my mind. I dare you.
Chat with Rene
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
More answers

It ensures that the current value of the variable is read, rather than (perhaps) a cached version caused by some compiler optimization. From Wikipedia: "Generally speaking, the volatile keyword is intended to prevent the compiler from applying any optimizations on the code that assume values of variables cannot change "on their own.""

User Avatar

Wiki User

12y ago
User Avatar

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.

User Avatar

Wiki User

13y ago
User Avatar

Transient Variables

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.

Volatile Variables

The volatile modifier tells the JVM that a thread accessing the variable must always reconcile its own private copy of the variable with the master copy in memory. Did you understand that? Don't worry about it. For the exam, all you need to know about volatile is that, similar to the transient keyword, it can be applied only to instance variables. It is also important to note that using volatile keyword for variable in a class where you are implementing multi-threading is a bad bad idea.

User Avatar

Wiki User

13y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is the use of volatile keyword in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp