Java Operator Precedence Table and Examples
Operator precedence determines the order in which Java evaluates operators within a single expression. Just like in mathematics, multiplication and division run before addition and subtraction: in 5 + 3 * 2, the product 3 * 2 is computed first. Delimiters have the highest precedence — parentheses, array indices, and the member access operator . — followed by unary operators, while the assignment operator sits at the very bottom with the lowest precedence.
Java Operator Precedence Table
Java operators fall into several groups: arithmetic, comparison, logical, bitwise, and assignment operators. The table below lists them in descending order of precedence: level 1 is evaluated first, level 15 last. Operators on the same row share the same precedence.
| Level | Operators | Category |
|---|---|---|
| 1 | [ ] ( ) . | Delimiters: array index, parentheses, member access |
| 2 | ++ -- ~ ! + (unary) - (unary) (type cast) | Unary operators |
| 3 | * / % | Multiplication, division, remainder |
| 4 | + - | Addition (and string concatenation), subtraction |
| 5 | >> >>> << | Bitwise shifts |
| 6 | > >= < <= instanceof | Relational comparison and type check |
| 7 | == != | Equality and inequality |
| 8 | & | Bitwise AND (for boolean — logical AND without short-circuiting) |
| 9 | ^ | Bitwise exclusive OR (XOR) |
| 10 | | | Bitwise OR (for boolean — logical OR without short-circuiting) |
| 11 | && | Logical AND (short-circuit) |
| 12 | || | Logical OR (short-circuit) |
| 13 | ? : | Ternary (conditional) operator |
| 14 | -> | Lambda expression (informal, see note below) |
| 15 | = (and compound forms: +=, -=, *=, and others) | Assignment |
One clarification about row 14: the arrow -> in a lambda expression is not an operator in terms of the Java Language Specification (JLS), and Oracle's official precedence table does not include it. It appears here informally — as a construct with very low precedence: a lambda «captures» everything to the right of the arrow, yielding only to assignment.
Note
Row 2 groups all unary operators together for simplicity. Strictly by the JLS, the postfix forms x++ and x-- rank slightly higher than the prefix forms ++x, --x, unary +/-, ~, !, and type casts. This is a simplification, not a mistake: the difference almost never shows up in practice, but it is worth knowing for interviews.
Associativity: Same Precedence Level
When several operators of the same precedence level appear in a row, the order is decided by associativity. Most binary operators in Java are left-associative — they are evaluated left to right:
int d = 100 - 10 - 5; // left: (100 - 10) - 5 = 85, not 100 - (10 - 5) = 95 Right-associative operators group right to left: assignment = (including compound forms), the ternary operator ? :, and unary operators:
int x, y, z;
x = y = z = 10; // right: x = (y = (z = 10)) - all three variables become 10 How such chains are evaluated step by step is covered in the lesson on the assignment operator.
Examples: How Precedence Changes the Result
Let's start with arithmetic — two expressions that look almost identical produce different results:
int a = 5 + 3 * 2; // result: 11, since multiplication is performed first
int b = (5 + 3) * 2; // result: 16, since addition is performed first due to parentheses As the example shows, parentheses let you change the order of operations — and significantly affect the final result.
Logical operators follow precedence rules too: && is evaluated before ||. Comparisons (level 6) rank above both, so the parentheses around them are optional, but the expression reads more easily with them:
boolean result = (5 > 3) && (10 > 8); // true, since both conditions are true
boolean result2 = (5 > 3) || (10 < 8); // true, since at least one condition is true
boolean r = true || false && false; // true: false && false runs first, then true || false A combination that is easy to get wrong is mixing &, ^, and | without parentheses. Their precedence differs (& is above ^, and ^ is above |), so the result may not match your expectation:
boolean m = true, n = false, k = false;
boolean r1 = m | n & k; // & is higher than |: evaluated as m | (n & k) = true | false = true
boolean r2 = (m | n) & k; // with parentheses: (true | false) & false = false Without parentheses, m | n & k is true; with them, (m | n) & k is false — even though the variables are the same.
Tip
You do not need to memorize the precedence table — it is a cheat sheet, not exam material. Remember the general shape (delimiters and unary operators at the top, assignment at the bottom, arithmetic before comparisons, comparisons before logic), and add explicit parentheses anywhere the order is not obvious: the compiler does not mind, and readers of your code see your intent immediately.
Frequently Asked Questions
Which Java operators have the highest and lowest precedence?
The highest precedence belongs to delimiters — parentheses, the array index [ ], and the member access operator . — immediately followed by unary operators (++, --, !, ~, unary +/-, type casts). The lowest precedence belongs to the assignment operator = and its compound forms: they run last, after the right-hand side has been fully evaluated.
Which is evaluated first: && or ||?
The && operator has higher precedence than ||. So the expression a || b && c is evaluated as a || (b && c), not as (a || b) && c. If you need a different order, add parentheses — they also make the expression clearer even where precedence is already on your side.
What is associativity, and how is it different from precedence?
Precedence decides which of different operators runs first; associativity decides the order of consecutive operators of the same level. Most binary operators in Java are left-associative (100 - 10 - 5 means (100 - 10) - 5), while assignment, the ternary operator, and unary operators are right-associative (x = y = 10 means x = (y = 10)).
Do I need to memorize the Java operator precedence table?
No. It is enough to remember the general outline: delimiters and unary operators at the top, then arithmetic, comparisons, logical operators, and assignment at the very bottom. In every non-obvious case (especially when mixing &, ^, |, or bitwise shifts with arithmetic), professional code uses explicit parentheses — more reliable than memory and clearer to your teammates.
Comments