Lesson 2 | Java operators |

Objective | Summarize the different types of operators supported by Java. |

The arithmetic operators are the most commonly used Java operators.

These operators consist of the unary operators,

These operators consist of the unary operators,

`+`

, `-`

, `++`

, and `--`

, and the binary operators `+`

, `-`

, `*`

,
`/`

, and `%`

. The `++`

and `--`

operators come in both prefix and postfix forms.
The + operator is also used to identify concatenation between two string objects.
Java's bitwise operators consist of a single unary operator

`~`

, and three binary operators, `&`

, `|`

,
and `^,`

that perform bitwise operations on integer values. The binary shift operators are `<<`

, `>>`

, and `>>>`

.
Java provides two groups of logical operators:

The comparison operators consist of the relational operators

- the boolean operators
`!`

,`&`

,`|`

, and `^`

, and the logical short-circuit operators`&&`

and`||`

.

`boolean`

operands.The comparison operators consist of the relational operators

(the equality operators`<`

,`<=,`

`>`

,`>=`

),

(and the`==`

and`!=`

),

`instanceof`

operator.
Java's assignment operators consist of the simple assignment (

`=`

) operator, and the update and assign operators
`+=`

, `-=`

, `*=`

, `/=`

,`%=`

, `&=`

, `|=`

, `^=`

, `<<=`

, `>>=`

, and `>>>=`

.
The ternary operator

If the first operand (

`? :`

(also referred to as the Conditional operator) has three operands and takes the following form:
operand1 ? operand2 : operand3

If the first operand (

`boolean`

) evaluates to true, the value of the second operand is returned. Otherwise, the value of the third operand is returned.
The *cast*^{[1]} operator

`(type)`

is used to convert numeric values from one numeric type to another, or to change an object reference to a compatible type.
[1]*Cast:* To convert from one type to another.