Operators are special symbols that perform specific operations on one, two, or three operands Java Language support a rich set of operators which are used to perform mathematical and logical calculations. Operators can be classified into three categories depending upon the number of operands used with the operator, that is unary operators, binary operators, and ternary operators.
Unary operators: These operators operate on one operand. For example, logical not (!), decrement (–), and increment (++) operators are unary operators.
Binary operators: These operators operate on two operands. For example arithmetic (except unary minus) operators (+, -, *, /, %) relational operators (<, <=, >, >=, ==, !=) and logical operators (&&, ||) are binary operators.
Ternary operators: These operators operate on three operands. For example, a conditional operator (?:) is a ternary operator.
Operators can also be classified into different categories, on the basis of the types of operations they perform on the operands. Different types of operators in Java are:
- Arithmetic operators (+, -, *, /, %)
- Logical operators (&&, ||, !)
- Relational operators (<, <=, >, >=, ==, !=)
- Assignment operators (=, op= )
- Increment and decrement operators (++, –)
- Conditional operators (?:)
- Bitwise operators (~, &, |, <<, >>, >>>)
- Special operators such as ‘instanceof’ operator and dot operator (.)
In general-purpose programming, certain operators tend to appear more frequently than others; for example, the assignment operator “=” is far more common than the unsigned right shift operator “>>>”. With that in mind, the further discussion focuses first on the operators that you are most likely to use on a regular basis, and later on, we focus on those operators that are less common. Each discussion is accompanied by a sample code that you can compile and run.