Java Operators are used to perform some operations between operands.
a = 2
b = 3
print(a+b)
OUTPUT:
5
Below are the different types of operators
Assignment operator are used to assign value to a variable. = (equal) symbol is use as an assignment operator.
In the below code value 3 is assigned to a with the assignment operator.
a = 3
It uses to compare two operands.
Logical operator also called as a Boolean operator as it returns true or false after comparison.
It is used to perform or compare more than two conditions. We have three types of bitwise operations:
print( 3 != 4 and 5 != 6)
OUTPUT:
True
2.Logical or: It will return true, if one of the operand are true.
print( 3 != 4 or 5 != 6)
OUTPUT:
True
3. Logical not: It will return true, if operand or operands collectively return false.
print( not 4 != 4)
OUTPUT:
True
Bitwise operator can be easily understood by below table:
Example:
What will the output for bitwise operation of (5 & 9)
print( 5 & 9 )
Output: 1
Bitwise operator can be easily understood by below table:
Example:
What will the output for bitwise operation of (5 | 9)
print( 5 | 9 )
Output: 13
Bitwise operator can be easily understood by below table:
Example:
What will the output for bitwise operation of (5 ^ 9)
print( 5 ^ 9 )
Output: 12
Bitwise operator can be easily understood by below table:
Example:
What will the output for bitwise operation of (~5)
print( ~ 5)
Output: -6
Note: Compiler gives 2βs complement of number. 2βs compliment of 10 is -6.
It compare the equality and memory of objects. There are two types of identity operators.
It will return true if the compare variable is referring to the same object
It will return true if objects are not equal.
The membership operator is used to check if a particular value is present in the collection of values. Itβs mainly used for str, list and tuples. There are two types of operators:
It will return True if a particular value is present in the collection of values.
In below example the output is True as 2 as an integer not present in list.
It will return True if a particular value is not present in the collection of values.
In below example the output is True as 2 as an integer not present in list.
Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.
π LinkedIn
π Blogs
π§ Imran Khan
javadoubts.com Β© All rights reserved