2. Operators in Java
Java provides many types of operators which
can be used according to the need. They are
classified based on the functionality they provide.
Some of the types are:
Arithmetic Operators
Unary Operators
Assignment Operator
Relational Operators
Logical Operators
Ternary Operator
Bitwise Operators
3. Arithmetic Operators
These operators involve the mathematical operators
that can be used to perform various simple or advanced
arithmetic operations on the primitive data types referred to
as the operands.
4. Unary Operators
In Java, the unary operator is an operator that can be used
only with an operand. It is used to represent the positive or
negative value, increment/decrement the value by 1, and
complement a Boolean value. In this section, we will discuss
the unary operator in Java with examples and also understand
the differences between i++ and i+=1.
5. Assignment Operators
Assignment operators are used in Java to assign values to
variables. For example,
int age;
age = 5;
Here, = is the assignment operator. It assigns the value on its right
to the variable on its left. That is, 5 is assigned to the Operator
Example
= a = b; a = b;
+= a += b; a = a + b;
-= a -= b; a = a - b;
*= a *= b; a = a * b;
/= a /= b; a = a / b;
%= a %= b; a = a % b;
6. Relational operator
In computer science, a relational operator is a
programming language construct or operator that tests or
defines some kind of relation between two entities. These
include numerical equality
7. Logical operator
AND Operator ( && ) – if( a && b ) [if true execute else don’t]
OR Operator ( || ) – if( a || b) [if one of them is true execute
else don’t]
NOT Operator ( ! ) – !(a<b) [returns false if a is smaller than b]
8. Ternary Operator
Java ternary operator is the only conditional operator
that takes three operands. It’s a one-liner replacement for
the if-then-else statement and is used a lot in Java
programming. We can use the ternary operator in place of
if-else conditions or even switch conditions using nested
ternary operators.
9. Bitwise Operators
Bitwise operators are used to performing the manipulation of
individual bits of a number. They can be used with any integral type
(char, short, int, etc.). They are used when performing update and
query operations of the Binary indexed There are six types of the
Bitwise operator in Java:
Bitwise AND
Bitwise exclusive OR
Bitwise inclusive OR
Bitwise Compliment
Bit Shift Operators