Start here. This is the direct spoken answer to practice first.
Overview
Compare-and-set changes a value only if it still matches the expected value observed by the caller.
An atomic variable provides thread-safe operations on one value without requiring callers to hold an explicit lock. Compare-and-set checks whether the current value equals an expected value and replaces it only if the check succeeds as one atomic operation. If another thread changed the value first, the update fails and code can retry using the new value. Methods such as incrementAndGet build on atomic read-modify-write behavior.