CSC / CPE 101-02-03:
Fundamentals of Computer Science (Java-based)



Operator Precedence in Java

Within a single expression, opertions with larger precedence numbers (as shown below) are perfomed below those with smaller numbers; operations at the same level are performed in order of association.

Style tip: when writing expressions that use operators having different precedence levels, the use of parentheses is encouraged. Even if they are, technically, not needed, their use makes the code clearer and less prone to subtle errors (in syntax, semantics, or logic).

Category Operator Precedence Association
subexpression (    ) 11 left to right

(If parentheses are nested,
the (innermost subexpression) is evaluated first.)

postincrement
postdecrement
 dot
++
--
.
10 left to right
preincrement
predecrement
unary operators
++
--
!
-
9 right to left
type cast
object instantiation
(type)
new
8 right to left
multiplicative operators *
/
%
7 left to right
additive operators

string concatenation
+
-
+
6 left to right
relational operators <
<=
>
>=
5 left to right
equality operators ==
!=
4 left to right
boolean XOR ^ 3 left to right
boolean AND && 2 left to right
boolean OR || 1 left to right
assignment operators =
0 right to left

Copyright © 2001 by Carol Scheftic. All rights reserved.
Requests to reuse information from this page should be directed to Carol Scheftic.
Page created 18 April 2001; last updated 18 April 2001.