answersLogoWhite

0


Best Answer

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
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

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.""

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

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.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

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.

This answer is:
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
Related questions

What is volatile thread?

Threads are not volatile. The volatile is a keyword that is used while having multiple threads in a Java Program. This keyword is used when multiple threads access a particular variable but still it is not mandatory to synchronize or prevent access to that variable.


Is check a keyword in java?

No, 'check' is not a keyword in java language.


Is float is a keyword in java?

yes, float is keyword and data type in java


How java use extern key word which is used in C plus plus?

No extern keyword in Java.


What does the verify keyword do in Java?

"verify" is not a Java keyword. I believe the link, in related links, has the complete list of Java keywords.


Can you declears static in a local variable in a method in java?

we cannot use the staic keyword inside the method... But we can use the final keyword inside the method....


Explain volatile keyword In C?

http://www.netrino.com/node/80 Good Article explaining, volatile keyword in detail. -- Pradeep Reddy


What is foreign keyword in java?

There is no "foreign" keyword in Java, however, there is a native keyword that declares native methods in a native language, such as C or C++.For full list of keywords in Java see related question.


What is literal in java programming?

Literal in java are L, F, null, true, false These act as keyword(have special meaning in java) but these does'nt comes under the category of Java Keyword.


What is java's keyword for the integer data type?

"int" is the keyword for integer


Can a single Java class subclass extend both InputStream and Reader. True or False?

Java does not have multiple inheritance, so no. Java can use multiple interfaces, though, with the "implements" keyword.


How does the final keyword affect the behavior of Object type in Java?

In Java, the final keyword specifies that the object created cannot be further redefined or derived.