Sometimes you face a scenario where you want concurrent threads to access a variable asynchronously. In such conditions, we use volatile variables. JVM ensures that value of volatile variable remain consistent within each thread.
class VolatileExample {
volatile int counter;
. . .
}