Operator
Assignment Operator
The assignment operator "=" assigns the value on its right to the operand on its left:
Arithmetic Operators
| Operator | Description |
|---|---|
+ | Additive operator (also used for String concatenation) |
- | Subtraction operator |
* | Multiplication operator |
/ | Division operator |
% | Remainder operator |
Unary Operators
| Operator | Description |
|---|---|
+ | Unary plus operator; indicates positive value (numbers are positive without this, however) |
- | Unary minus operator; negates an expression |
++ | Increment operator; increments a value by 1 |
-- | Decrement operator; decrements a value by 1 |
! | Logical complement operator; inverts the value of a boolean |
Relational Operators
| Operator | Description |
|---|---|
== | equal to |
!= | not equal to |
> | greater than |
>= | greater than or equal to |
< | less than |
<= | less than or equal to |
Conditional Operators
| Operator | Description |
|---|---|
&& | and |
| || | or |
These operators exhibit "short-circuiting" behavior, which means that the second operand is evaluated only if needed.
Ternary operator
?:is known as the ternary operator because it uses three operands.
If someCondition is true, assign the value of value1 to result. Otherwise, assign the value of value2 to result.
Type Comparison Operator
The instanceof operator compares an object to a specified type.
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html
Operation on bits
~
The unary bitwise complement operator "~" inverts a bit pattern.
- it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0".
- For example, a
bytecontains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111".
<<
The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension.
&
The bitwise & operator performs a bitwise AND operation.
^
The bitwise ^ operator performs a bitwise exclusive OR operation.
|
The bitwise | operator performs a bitwise inclusive OR operation.