In Java, a++ and ++a both increment the variable a by 1, but the timing of when the increment happens is different:


a++ — Post-increment

Use first, then increment.

int a = 5; int b = a++;  // b = 5, then a becomes 6
  • The current value of a (5) is assigned to b, and then a is incremented.

  • After execution: a = 6, b = 5


++a — Pre-increment

Increment first, then use.

int a = 5; int b = ++a;  // a becomes 6 first, then assigned to b
  • a is incremented before being assigned to b.

  • After execution: a = 6, b = 6


In short:

ExpressionOrder of OperationDescription
a++Use, then incrementUses the original value, then adds 1
++aIncrement, then useAdds 1 first, then uses the new value

If you just write a++; or ++a; as a standalone line, they have the same effect — both simply increment a by 1.


The prefixes “pre” and “post” signify before and after, respectively.

Pre: Indicates something happening before an event (e.g., pre-game means before the game starts).
Post: Indicates what occurs after an event (e.g., post-surgery care involves recovery following an operation).

In summary, “pre” is used for events or actions that occur prior to something, while “post” is used for those that occur afterward.