## Precedence |

BASIC |

**Precedence rules** tell in what order operations are done. For example,
the rules tell you that `2+3*4`

is 14, not 20.

In an arithmetic expression,

- Anything inside parentheses is done first.
- Unary minus is done next.
- Multiplications and divisions are done before additions and subtractions.
- Operations of equal precedence are done left to right (for example,

is 4, not 6).10 - 5 - 1 - Assignments are done last.

In a condition,

- Anything inside parentheses is done first.
- Arithmetic is done before equality and inequality tests.
- Logical operations are done after equality and inequality tests.
- "Not" (
`!`

) is done before "and" (`&&`

) - "And" (
`&&`

) is done before "or" (`||`

).

- "Not" (
- Assignments are done last.

For example,

means

.

STYLE |

Because there are a lot of operations in Java, most programmers do not know the complete table of precedence. Therefore, you should use parentheses for any expressions not fully covered by the above rules.

ADVANCED |

Every operator has a precedence, as given by Sun's precedence table.