Order of Precedence and Associativity of Operators in Java

 Introduction

Operators are unique symbols in Java. These operators do specific tasks in Java. These operators follow an order of precedence and associativity in Java. In Java, operators with lower precedence are operated after the operators with higher precedence.

Operators

  • Arithmetic Operators.
     
  • Relational Operators
     
  • Bitwise Operators
     
  • Boolean Logical Operators

Arithmetic Operators

  • Addition   ---   +
     
  • Subtraction   ---   -
     
  • Multiplication   ---   *
     
  • Division   ---   /
     
  • Modulus   ---   %
     
  • Increment   ---   ++
     
  • Decrement   ---   --
     
  • Addition Assignment   ---   +=
     
  • Subtraction Assignment   ---   -=
     
  • Multiplication Assignment   ---   *=
     
  • Division Assignment   ---   /=
     
  • Modulus Assignment   ---   %=

Relational Operators

  • Equal to   ---   ==
     
  • Not equal to   ---   !=
     
  • Greater than   ---   >
     
  • Less than   ---   <
     
  • Greater than or equal to   ---   >=
     
  • Less than or equal to   ---   <=

Bitwise Operators

  • Bitwise unary NOT   ---   ~
     
  • Bitwise AND   ---   &
     
  • Bitwise OR   ---   |
     
  • Bitwise exclusive OR   ---   ^
     
  • Shift Right   ---   >>
     
  • Shift Left   ---   <<
     
  • Shift Right zero fill   ---   >>>
     
  • Bitwise AND assignment   ---   &=
     
  • Bitwise OR assignment   ---   \=
     
  • Bitwise exclusive OR assignment   ---   ^=
     
  • Shift Right assignment   ---   >>=
     
  • Shift Left assignment   ---   <<=
     
  • Shift Right zero fill assignment   ---   >>>=

Boolean Logical Operators

  • Logical AND   ---   &
     
  • Logical OR   ---   \
     
  • Logical XOR   ---   ^
     
  • Short circuit OR   ---   ||
     
  • Short circuit AND   ---   &&
     
  • Logical Unary NOT   ---   !
     
  • AND assignment   ---   &=
     
  • OR assignment   ---   \=
     
  • XOR assignment   ---   ^=
     
  • Equal to   ---   ==
     
  • Not Equal to   ---   !=
     
  • Ternary if-then-else   ---   ?:

Order of Precedence and Associativity
 

Associativity    Operators
L to R   ()  [] 
R to L   ++  --  +  -  !  ~ 
L to R       *  /  %
L to R     +  -
L to R     <<  >>  >>>
L to R   <  <=  >  >=
L to R   ==  !=
L to R   &
L to R   ^
L to R   |
L to R     &&
L to R   ||
R to L   ? :
R to L   =  +=  -=  *=  /=  %=  &=  ^=  |=  <<=  >>=  >>>=


Summary

This article has explained the operators and their order of precedence and associativity in Java.

Up Next
    Ebook Download
    View all
    Learn
    View all