Types of Operators
Unary Operator
Arithmetic Operator
Shift Operator
Relational Operator
Bitwise Operator
Logical Operator
Ternary Operator
Assignment Operator
Unary Operator
Java unary operators require only one operand. Unary operators are used to perform
various operations i.e:
incrementing/decrementing a value by one.
o post increment ( a++ ).
o pre increment ( ++a ).
o post decrement ( a-- ).
o pre decrement ( --a ).
negating an expression ( ~ ).
inverting the value of boolean ( ! ).
Arithmetic Operator
Java arithmetic operators are used to perform addition, subtraction, multiplication, and
division. They act as basic mathematical operations (+, -, *, /, %).
Shift Operator
Left Shift Operator: Java left shift operator (<<) is used to shift all of the
bits in a value to the left side of a specified number of times (10<<2 = 10 * 2^2).
Right Shift Operator: Java right shift operator (>>) is used to move the value
of the left operand to right by the number of bits specified by the right
operand (10>>2 = 10 / 2^2).
Relational Operator
Java relational operator are used to comparing two variables. Java relational operator
always returns a boolean value i.e: true (or) false (==, !=, <, >, <=, >=).
Logical Operator and Bitwise Operator
AND Operator(Logical: &&, Bitwise: &) and OR Operator(Logical: ||,Bitwise:
|)
o The logical (&&) operator doesnÕt check the second condition if the first
condition is true. It checks the second condition only if the first one is
true.
o The bitwise (&) operator always checks both conditions whether first
condition is true or false.
Ternary Operator
Java ternary operator is used as one line replacement for if - then - else statement
used a lot in Java programming. It is the only conditional operator which takes three
operands (condition ? result1 : result2).
Assignment Operator
Java assignment operator is one of the most common operators. It is used to assign the
value on its right to the operand on its left (+=, -=, *=, /= etc.).