Operators in Java


☞Before taking look at operators, let see some terms related to them.

Operators : They are the symbol or sign used to specify an operation to be performed.
Example : +, -, >, ==, etc. are operators.

Operands : The elements used in the operation on which action is to be taken.
Example : In a + b, a and b are operands whereas + is an operator.

Expression : It is a combination of operators and operands.
Example : a * b + c is an expression.

Arithmetical Statement : When an expression is assigned to a variable, the complete set is called arithmetical statement.
Example : result = a * b + c; is a arithmetical statement.


Types of operators in Java

☞Following are the types of operators in java.

1.	Unary Operator,
2.	Arithmetic Operator,
3.	shift Operator,
4.	Relational Operator,
5.	Bitwise Operator,
6.	Logical Operator,
7.	Ternary Operator and
8.	Assignment Operator.

☞On the basis of operands, operators are of three types.

1.  Unary Operator      ➺    It acts upon one operand.
2.  Binary Operator     ➺    It acts upon two operands.
3.  Ternary Operator    ➺    It acts upon three operands

Precedence and Associativity in Java

☞When an expression or statement involves multiple operators, Java resolves the order of execution through Operator Precedence.

☞Example : 2 * 3 / 5

☞Associativity is the order in which an expression having multiple operators of same precedence is evaluated.

☞Example : 2 * 3 / 5 * 9

☞Table of precedence of operators and associativity is given below :

Operators Precedence Associativity
Separators () [] L to R
Unary + - ++ -- ! R to L
Arithmetic * / %
+ -
L to R
Shift << >> >>>
Relational < <= > >=
== !=
Bitwise &
^
|
Logical &&
||
Conditional ? :
Assignment = += *= -= /= etc R to L

Note : According to ICSE syllabus, we will learn arithmetic, relational, logical and ternary operator. We will see ternary operator in if-else section.