Operators are symbols that used to perform operations on variables and values.
Java provides a rich set of operators that can be divided into the following types:
Arithmetic Operators
Relational Operators
Bitwise Operators
Logical Operators
Assignment Operators
Misc Operators
These are used to performing common mathematical operations on variables and data.
Example: Arithmetic Operators
Note for the division operator: If the division operator is used with two integers, then the resulting quotient will also be an integer. And, if one of the operands is a floating-point number, the result will also be in floating-point.
Example: / with floating-point number
These are used to check the relationship between two operands.
Example: Comparison Operators
Note: Relational operators are used in decision making and loops.
These can be applied to the integer types, long, int, short, char, and byte.
Example: Bitwise Operators
These are used to determine the logic between variables or values
Example: Logical оperators
These are used to assign values to variables
Example: Assignment оperators
Conditional Operator ( ? : )
Conditional operator is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide, which value should be assigned to the variable. The operator is written as − variable x = (expression) ? value if true : value if false
Instance of Operator
This operator is used only for object reference variables. The operator checks whether the object is of a particular type (class type or interface type). instance of operator is written as − (Object reference variable) instance of (class/interface type)
If the object referred by the variable on the left side of the operator passes the IS-A check for the class/interface type on the right side, then the result will be true.