Skip to main content
Logo image

Java, Java, Java: Object-Oriented Problem Solving, 2022E

Appendix E Operator Precedence Hierarchy

Table E.0.1 summarizes the precedence and associativity relationships for all Java operators. Within a single expression, an operator of order m would be evaluated before an operator of order n if \(m \lt n\text{.}\) Operators having the same order are evaluated according to their association order.
Most operators associate from left to right, but note that assignment operators associate from right to left. For example, consider the following code segment:
Table E.0.1. Java operator precedence and associativity table.
Order Operator Operation Association
0 ( ) Parentheses
1 ++ -- Postincrement, postdecrement L to R
1 . dot operator L to R
2 ++ -- Preincrement, predecrement R to L
2 + - unary plus, unary minus R to L
2 ! Boolean NOT R to L
3 (type) new Type cast, object instantiation R to L
4 * / % Multiplication, division, modulus L to R
5 + - Addition, subtraction L to R
5 + String concatenation L to R
6 < > <= >= Relational operators L to R
7 == != Equality operators L to R
8 ^ Boolean XOR L to R
9 && Boolean AND L to R
10 || Boolean OR L to R
11 = += -= *= /= %= assignment operators R to L