Operators are used in java along with the variables to achieve arithmetic, logical, conditional & relational functionalities. There are different types of operators available as below.
Types of Operators:
- Assignment Operator
- Arithmetic Operators
- Relational Operators
- Conditional Operators
- Unary Operators
- Type Comparison Operator
- Bitwise Operators
- Equality Operator
Assignment Operator:
(=) It is used to assign any value to a variable.
Eg:
int a = 2;
Arithmetic Operators:
+ | Addition operator |
– | Subtraction operator |
* | Multiplication operator |
/ | Division operator |
% | Remainder operator |
Relational Operators:
!= | Not equal to |
> | Greater than |
>= | Greater than or equal to |
< | Less than |
<= | Less than or equal to |
Conditional Operators:
&& | Conditional-AND |
|| | Conditional-OR |
?: | Ternary (shorthand for if-then-else statement) |
Unary Operators:
+ | 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 |
Bitwise Operators:
~ | Unary bitwise complement |
<< | Signed left shift |
>> | Signed right shift |
>>> | Unsigned right shift |
& | Bitwise AND |
^ | Bitwise exclusive OR |
| | Bitwise inclusive OR |
Type Comparison Operator:
instanceof – Checks whether the object is of specific type and returns a boolean.
Equality Operator:
== Checks whether the value of two variables are equal.