The volatile keyword in Java is used as an indicator to Java compiler and Thread that do not cache value of this variable and always read it from main memory because of this it's guaranteed that all reader thread will see updated value of the volatile variable once write operation completed.
So if you want to share any variable in which read and write operation is atomic by implementation e.g. read and write in an int or a boolean variable then you can declare them as volatile variable.
The Java volatile keyword cannot be used with method or class and it can only be used with a variable
Note: If a variable is not shared between multiple threads, you don't need to use volatile keyword with that variable