Operatosr
There are many
types of operators in java which are given below:
- Unary Operator
- Arithmetic Operator
- Shift Operator
- Relational Operator
- Bitwise Operator
- Logical Operator
- Ternary Operator
- Assignment Operator.
![]() |
operater in java |
Unary
Operators- The Java unary operators require only one operands.
Unary operators are used to perform various operations.
Operator
|
Meaning
|
+
|
Unary
plus (not necessary to use since numbers are positive without using it)
|
-
|
Unary
minus; inverts the sign of an expression
|
++
|
Increment
operator; increments value by 1
|
--
|
decrement
operator; decrements value by 1
|
!
|
Logical
complement operator; inverts the value of a boolean
|
Example
Arithmetic
Operators- Arithmetic operators are used to perform
mathematical operations like addition, subtraction, multiplication etc.
Operator
|
Meaning
|
+
|
Addition
(also used for string concatenation)
|
-
|
Subtraction
Operator
|
*
|
Multiplication
Operator
|
/
|
Division
Operator
|
%
|
Remainder
Operator
|
Example
Shift
Operator- The java left shift operators << is used to shift
all of the bits in value to the left side
and the right shift operators >> is used to move left operands
value to right by the number of bits to specified number of times.
Operator
|
Description
|
<<
|
Left Shift
|
>>
|
Right Shift
|
>>>
|
Unsigned Right Shift
|
Example
Relational Operators- The equality and relational operators
determines the relationship between two operands. It checks if an operand is
greater than, less than, equal to, not equal to and so on. Depending on the
relationship, it results to either true or false.
Operator
|
Description
|
Example
|
==
|
equal
to
|
5
== 3 is evaluated to false
|
!=
|
not
equal to
|
5
!= 3 is evaluated to true
|
>
|
greater
than
|
5
> 3 is evaluated to true
|
<
|
less
than
|
5
< 3 is evaluated to false
|
>=
|
greater
than or equal to
|
5
>= 5 is evaluated to true
|
<=
|
less
then or equal to
|
5
<= 5 is evaluated to true
|
Java Equality and
Relational Operators
|
Example
Operator
|
Description
|
~
|
Bitwise
Complement
|
<<
|
Left
Shift
|
>>
|
Right
Shift
|
>>>
|
Unsigned
Right Shift
|
&
|
Bitwise
AND
|
^
|
Bitwise
exclusive OR
|
|
|
Bitwise
inclusive OR
|
Java Bitwise and Bit
Shift Operators
|
|
Example
Operator
|
Description
|
Example
|
||
|
conditional-OR; true if
either of the boolean expression is true
|
false
|| true is evaluated to true
|
&&
|
conditional-AND;
true if all boolean expressions are true
|
false
&& true is evaluated to false
|
Java Logical Operators
|
No comments:
Post a Comment