3/28/2011 Operator Precedence in Java
Operator Precedence in Java
NOTE: Use explicit parentheses when there is even the possibility of confusion.
The operators in Java, shown in order of precedence - from highest to lowest
Priority Operators Operation Associativity
[ ] array index
1 () method call left
. member access
++ pre- or postfix increment
-- pre- or postfix decrement
+ - unary plus, minus
2 ~ bitwise NOT right
! boolean (logical) NOT
(type) type cast
new object creation
3 * / % multiplication, division, remainder left
+ - addition, substraction
4 left
+ string concatenation
<< signed bit shift left
5 >> signed bit shift right left
>>> unsigned bit shift right
< <= less than, less than or equal to
6 > >= greater than, greater than or equal to left
instanceof reference test
== equal to
7 left
!= not equal to
& bitwise AND
8 left
& boolean (logical) AND
^ bitwise XOR
9 left
^ boolean (logical) XOR
| bitwise OR
10 left
| boolean (logical) OR
11 && boolean (logical) AND left
12 || boolean (logical) OR left
uni-bonn.de/…/javaoperators.php?me… 1/2
3/28/2011 Operator Precedence in Java
13 ? : conditional right
= assignment
*= /= += -= %=
14 combinated assignment right
<<= >>= >>>=
(operation and assignment)
&= ^= |=
Further reading
Java Language Specification SE :
Evaluation Order (Expressions )
Retrieved from http://www.uni-bonn.de/~manfear/javaoperators.php.
uni-bonn.de/…/javaoperators.php?me… 2/2