Associativity and Precedence of Operators in Java

Precedence is the priority order of an operator, if there are two or more operators in an expression then the operator of highest priority will be executed first then higher, and then high.
Alternatively, you can say that when an operand is shared by two operators then higher priority operator picks the shared operand for processing

What if all operators in an expression have same priority? In that case the second property associated with an operator comes into play, which is associativity. Associativity tells the direction of execution of operators that can be either left to right or right to left.

Note that, you can change the priority of a Java operator by enclosing the lower order priority operator in parentheses but not the associativity.

Precedence and Associativity Table

Below table presents all Java operators from highest to lowest precedence along with their associativity:

1[ ]
( )
Left -> Right
Right -> Left
Left -> Right
Left -> Right
Left -> Right
Left -> Right
Left -> Right
8&Left -> Right
9^Left -> Right
10|Left -> Right
11&&Left -> Right
12||Left -> Right
13? :Right -> Left
Right -> Left

Operators in Java Previous Next Data Types in Java