Atomic Operation and Class:
An operation is classified as atomic if it is performed as a single unit of work without the possibility of interference from other processes.
In the Java language specification, they guarantee that the reading or writing operation is atomic (unless the variable is a long or a double). Variables of type long or double in operations are only atomic if declared with the keyword: volatile.
Suppose we assume that i is defined as an int. The i++ (increment) operation is not an atomic operation in Java. This also applies to the other numeric types, e.g. long. This is because the i++ operation first reads the value currently stored in i, and then it adds one to it. However, between the read and the write, the value of i might have changed.
Since Java 1.5, the java language provides an atomic class with variables such as AtomicInteger or AtomicLong. The class also provides methods like getAndDecrement(), getAndIncrement() and getAndSet() which are all atomic. Using these provides that atomic guarantee.