## Precedence of Java Operators

Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has higher precedence than the addition operator:

For example, x = 5 + 2 * 2; here x is assigned 9, not 14 because operator * has higher precedence than +, so it first gets multiplied with 2*2 and then adds into 5.

Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will be evaluated first.

Preference |
Category |
Operator |
Associativity |

1^{st} |
Postfix | () [] . (dot operator) | Left toright |

2^{nd} |
Unary | ++ – – ! ~ | Right to left |

3^{rd} |
Multiplicative | * / % | Left to right |

4^{th} |
Additive | + – | Left to right |

5^{th} |
Shift | >> >>> << | Left to right |

6^{th} |
Relational | > >= < <= | Left to right |

7^{th} |
Equality | == != | Left to right |

8^{th} |
Bitwise AND | & | Left to right |

9^{th} |
Bitwise XOR | ^ | Left to right |

10^{th} |
Bitwise OR | | | Left to right |

11^{th} |
Logical AND | && | Left to right |

12^{th} |
Logical OR | || | Left to right |

Conditional | ?: | Right to left | |

Assignment | = += -= *= /= %= >>= <<= &= ^= |= | Right to left | |

Comma | , | Left to right |