Arithmetic Operators in Java
Java's five arithmetic operators — +, -, *, /, and % — work on any numeric primitive, and + additionally works on String to mean concatenation. Division and modulo both behave differently depending on the operand types: integer division truncates toward zero, floating-point division produces a full decimal result, and modulo returns whatever is left over after division.
Beyond those five, ++ and -- are shorthand for adding or subtracting exactly one. Each comes in a prefix form (++x) and a postfix form (x++), and the difference is a real behavioral one, not just style: prefix updates the variable before the surrounding expression reads it, while postfix reads the old value first and updates afterward.
The five arithmetic operators
+, -, *, /, % cover addition, subtraction, multiplication, division, and remainder.
Plus does double duty
Between numbers it adds; between a String and anything else it concatenates, converting the other side to text automatically.
Integer vs floating-point division
Dividing two ints truncates toward zero; if either operand is a float or double, the division keeps its decimal part.
Modulo
% returns the remainder left over after division, useful well beyond just describing "what's left."
Increment and decrement
++ and -- add or subtract exactly one, and exist in both prefix (++x) and postfix (x++) forms.
Prefix versus postfix
Prefix updates the variable before the surrounding expression reads it; postfix reads the old value first and updates afterward.
public class ArithmeticDemo { public static void main(String[] args) { int x = 5; System.out.println("Pre-increment: " + (++x)); int y = 5; System.out.println("Post-increment: " + (y++)); System.out.println("y after post-increment: " + y); }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.