What is the purpose of the "volatile" keyword in Java? When would you use it?
The volatile
keyword in Java is used to indicate that a variable may be modified by multiple threads. It ensures that changes made by one thread to the variable are visible to other threads immediately. It's often used in double-checked locking and state flags.