Java Operators:
Operators are the mechanism that allows programs to perform computations on various values. There are three types of operators.
- unary operator acts on one operand
- binary operator acts on two operands.
- ternary operator acts on three operands.
On this page
Arithmetic Operators
Operator | Description |
---|---|
+ | Additive operator (also used for String concatenation)
See More about + Operator |
- | Subtraction operator |
* | Multiplication operator |
/ | Division operator |
% | Remainder operator |
Equality and Relational Operators
Relational operators are those that compare two values (For example, = = and < are relational operators).
These operators produce a true or false result. You could store these Boolean values in a variable of type boolean. However, usually you‘ll use these in if and similar statements.
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 |
---|---|
&& | Conditional-AND |
|| | Conditional-OR |
?: | Ternary (shorthand for if-then-else statement) |
Bitwise and Bit Shift Operators
Operator | Description |
---|---|
~ | Unary bitwise complements |
<< | Signed left shift |
>> | Signed right shift |
>>> | Unsigned right shift |
& | Bitwise AND |
^ | Bitwise exclusive OR |
| | Bitwise inclusive OR |