Operators in java

Operator:-
Operator in Java is a symbol that is used to perform operations. 
For example: +, -, *, / etc.
There are many types of operators in Java which are given below:
  • Unary Operator,
  • Arithmetic Operator,
  • Shift Operator,
  • Relational Operator,
  • Bitwise Operator,
  • Logical Operator,
  • Ternary Operator and
  • Assignment Operator.

Java Operator Precedence

Operator TypeCategoryPrecedence
Unarypostfixexpr++ expr--
prefix++expr --expr +expr -expr ~ !
Arithmeticmultiplicative* / %
additive+ -
Shiftshift<< >> >>>
Relationalcomparison< > <= >= instanceof
equality== !=
Bitwisebitwise AND&
bitwise exclusive OR^
bitwise inclusive OR|
Logicallogical AND&&
logical OR||
Ternaryternary? :
Assignmentassignment= += -= *= /= %= &= ^= |= <<= >>= >>>=


Java Unary Operator 

The Java unary operators require only one operand. Unary operators are used to perform various operations i.e.:

  • incrementing/decrementing a value by one
  • negating an expression
  • inverting the value of a boolean.

Java Unary Operator Example: ++ and --

  1. public class OperatorExample{  
  2. public static void main(String args[]){  
  3. int x=10;  
  4. System.out.println(x++);//10 (11)  
  5. System.out.println(++x);//12  
  6. System.out.println(x--);//12 (11)  
  7. System.out.println(--x);//10  
  8. }}  
Output:

10                                                           
12                                                           
12                                                           
10