1
0

Operator Precedence & Associativity Rules in Java

The precedence of operators decides the order of execution of operators. The operators with higher precedence are executed first. If more than one operator of the same precedence appears in the same expression then the order of execution among these operators is decided by the rule of associativity. The following table shows the precedence and associativity of all operators.

Operator Precedence and Associativity:

Operators Description Symbol Priority Associativity
Member Access   1 Left to right
Bracket () 1 Left to right
Array Element Reference [] 1 Left to right
Unary Minus 2 Right to left
Increment  ++ 2 Right to left
Decrement 2 Right to left
Logical Not ! 2 Right to left
Bitwise Complement ~ 2 Right to left
Casting (type) 2 Right to left
Multiplication * 3 Left to right
Division / 3 Left to right
Modulus % 3 Left to right
Addition + 4 Left to right
Subtraction 4 Left to right
Left Shift << 5 Left to right
Right Shift >> 5 Left to right
Logical Right Shift >>> 5 Left to right
Less Than < 6 Left to right
Less Than or Equal to <= 6 Left to right
Greater Than > 6 Left to right
Greater Than or Equal to >= 6 Left to right
Type Comparison instanceof 6 Left to right
Equal to == 7 Left to right
Not Equal to != 7 Left to right
Bitwise AND & 8 Left to right
Bitwise XOR ^ 9 Left to right
Bitwise OR | 10 Left to right
Logical AND  && 11 Left to right
Logical OR || 12 Left to right
Ternary Operator ?: 13 Left to right
Assignment Operator = 14 Right to left
Compound Assignment op= 14 Right to left

Leave a Reply