This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the difference between volatile and static keywords in Java?

 
kumaraswamy dapa
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all can anyone tel me the difference between volatile and static keywords?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The volatile and static keywords have totally different purposes. It's a bit strange to ask what the difference between them is, because they are completely unrelated to each other.

When a member variable or method is static, then it is a class member instead of an instance member. See Understanding Instance and Class Members for details about what that means exactly.

The volatile keyword has to do with multi-threading. It's a bit hard to explain, but it gives you certain guarantees with regard to multiple threads, for example that when one thread has changed the value of a volatile variable, its new value is immediately visible to other threads (with non-volatile variables this is not always the case because of certain optimizations that the JVM might do). Section 8.3.1.4 of the Java Language Specification explains what it means exactly. If you want to know more about the subject, the book Java Concurrency in Practice is a very good book about multi-threading in Java.
 
kumaraswamy dapa
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic