Title: Key Concept - Operators
Course: CPS 189: Java Certification - Review, Practice & Prepare (Development) > Section: Learning Modules

Operators are evaluated according to precedence. The operator of highest precedence is evaluated first; the operator of lowest precedence is evaluated last.

- All operators, except the assignment operators, with the same precedence are evaluated from left to right.
- Assignment operators with the same precedence are evaluated from right to left.
- Parentheses override precedence and modify the evaluation order.

Following is a list of categories and operators listed from highest precedence down to lowest precedence:

Postfix

- expr++ (evaluate and use expr, then increment)
- expr-- (evaluate and use expr, then decrement)

Unary

- ++expr (evaluate and increment expr, then use)
- --expr (evaluate and decrement expr, then use)
- +expr (optional positive value indicator)
- -expr (negative value indicator)
- ~ (bitwise complement)
- ! (not)

Multiplicative

- *, /, % (remainder)

Additive

- + (addition or concatenation), -

Shift

- << (signed left shift), >> (signed right shift), >>> (unsigned right shift)

Relational

- <, >, <=, >=, instanceof (object type comparison)

Equality

- ==, !=

Bitwise AND

- &

Bitwise exclusive OR

- ^

Bitwise inclusive OR

- |

Logical AND

- &&

Logical OR

- ||

Ternary

- ? : (if-then-else statement shorthand)

Assignment

- =

Following operators all provide same statement shortcuts. For example, var += exper is shorthand for var = var + expr.

- +=, -=, *=, /=, %=, &=, ^=, |=, <<=, >>=, >>>=

For additional study, view the resources under Level 1 Study Materials: Unit 1.