Programming |
Operator precedence means if there is more than one operator in an expression then which expression will be solved first and what will be the direction of solving the expression. It is similar to BODMAS rule in mathematics. This is a tabular representation of the precedence and associativity of Java Operators.
Precedence* |
Operator |
Type |
Associativity |
15 |
() |
Parentheses |
Left to Right |
14 |
++ |
Unary post-increment |
Right to left |
13 |
++ |
Unary pre-increment |
Right to left |
12 |
* |
Multiplication |
Left to right |
11 |
+ |
Addition |
Left to right |
10 |
<< |
Bitwise left shift |
Left to right |
9 |
< |
Relational less than |
Left to right |
8 |
== |
Relational is equal to |
Left to right |
7 |
& |
Bitwise AND |
Left to right |
6 |
^ |
Bitwise exclusive OR |
Left to right |
5 |
| |
Bitwise inclusive OR |
Left to right |
4 |
&& |
Logical AND |
Left to right |
3 |
|| |
Logical OR |
Left to right |
2 |
? : |
Ternary conditional |
Right to left |
1 |
= |
Assignment |
Right to left |
*Larger number means higher precedence.