Operators in Java
Operators in Java
Here, in this page we will discuss about the operators in Java. Java provides quite a variety of operators which come in handy to the programmer for the manipulation of variables.
The operators in java are as follows:
Arithmetic Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Miscellaneous Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Miscellaneous Operators
The operators in java are as follows:
Arithmetic Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Miscellaneous Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Miscellaneous Operators
1. Arithmetic Operators
Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra, i.e, to perform the basic mathematical functions.Operator | Functionality |
---|---|
+ | Addition |
– | Subtraction |
* | Multiplication |
/ | Division |
% | Modulus |
2. Relational Operators
Relational operators are used in making decisions and in loops. They are used to test or define some relation between entitiesOperator | Functionality |
---|---|
== (equal to) | To check if two operands are equal or not, if yes, the output becomes true. |
!= (not equal to) | To check if two operands are equal or not, if not, the output becomes true. |
> (greater than) | To check if the left operand is greater than the right operand, if yes, then the output becomes true. |
< (less than) | To check if the left operand is less than the right operand, if yes, the output becomes true. |
>= (greater than or equal to) | To check if the left operand is greater than or equal to the right operand, if yes, then the output becomes true. |
<= (less than or equal to) | To check if the left operand is less than or equal to the right operand, if yes, the output becomes true. |
3. Bitwise Operators
Since the operations in the CPU/ arithmetic unit is done in bit-level, the operators to perform bit-level operations are termed as Bitwise operators.Operator | Functionality |
---|---|
&(Bitwise AND) | The result of AND is 1 only if both bits are 1. |
|(Bitwise OR) | The result of OR is 1 if any of the two bits is 1 |
^(Bitwise XOR) | The result of XOR is 1 if the two bits are different. |
~(Bitwise Complement) | It takes one number and inverts all bits of it |
<<(Shift left) | Left shifts the bits of the first operand, the second operand decides the number of places to shift. |
>>(Shift right) | Right shifts the bits of the first operand, the second operand decides the number of places to shift. |
4. Logical Operators
Logical operators are mainly used to control program flow. They allow a program to make a decision based on multiple conditions.
Operator | Functionality |
---|---|
&&(Logical AND) | It returns true if both statements are true |
||(Logical OR) | It returns true if one of the statements is true |
!(Logical NOT) | It reverses the result, returns false if the result is true |
5. Assignment Operators
Assignment operators are used to assigning the value on its right to the variable on its left.
Operator | Functionality |
---|---|
= (simple assignment) | Assigns values from right side operands to left side operand. |
+= (compound of + and =) | It adds right operand to the left operand and assign the result to left operand. |
-=(compound of – and =) | It subtracts the right operand from the left operand and assigns the result to the left operand. |
*= (compound of * and =) | It multiplies the right operand with the left operand and assigns the result to the left operand. |
/= (compound of / and =) | It divides the left operand with the right operand and assigns the result to the left operand. |
%= (compound of % and =) | It takes modulus using two operands and assigns the result to the left operand. |
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Get over 200+ course One Subscription
Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others
Login/Signup to comment