Java derives many feature from C language(mother of programming language). Like C and C++ , java provide a large collection of operators to work on variables.
It also provides many new operators to work with like conditional operators(? : ) and instanceOf operator
Types Of Operators
Relational Operators Relational operator are refer to those operator that are used in program to manipulate variables to perform some comparison like ==(equal),!=(not equal) etc.
Arithmetic Operators These operator are used to perform mathematical calculation like +(addition), -(subtraction),*(multiplication),/(divide) etc.
Logical Operators These operator are used in logical decision like && (logical and) , || (logical or) etc. and return true or false as a result.
Assignment Operators Assignment (=) operator have only one operator to assign value from one variable to other, like a=b.
Here we assign b value to a.
Bitwise OperatorsIt works on bits and performs bit-by-bit operation.Firstly ,It convert integer value into bit.
Java have bitwise operators, which can be applied to the number or digit types, long, int, short, char, and byte.
Conditional Operators These operator is also known as the ternary operator. It have three operands and is used to evaluate Boolean expressions. The purpose of the operator is to decide which value should be assigned to the variable. The operator is written as:
variable a = (expression) ? value if true : value if false
List Of Operators And Their Precedence
Precedence in operator decides in expression which two operands are calculated first , it define how an whole expression is evaluated.
Associativity | Operator Category | Operator Symbol |
---|---|---|
Left to right | Postfix | () [] . (dot operator) |
Right to left | Unary | ++ – – ! ~ |
Left to right | Multiplicative (Arithmetic Operator) | * / % |
Left to right | Additive (Arithmetic Operator) | + – |
Left to right | Shift (Bitwise Operator) | >> >>> << |
Left to right | Relational (Relational Operator) | > >= < <= |
Left to right | Equality (Relational Operator) | == != |
Left to right | Bitwise AND | & |
Left to right | Bitwise OR | | |
Left to right | Bitwise XOR | ^ |
Left to right | Logical AND | && |
Left to right | Logical OR | & |
Right to left | Assignment | = += -= *= /= %= >>= <<= &= ^= |= |
Right to left | Conditional | ?: |