Order of precedence and associatively of operators


Posted in : Core Java Posted on : October 13, 2010 at 6:44 PM Comments : [ 0 ]
Advertisements
This section contains the detail about the Order of precedence and associatively of operators in java.

Order of precedence and associatively of operators

Operators are special characters within the Java language that perform operations on arguments to return a specific result. Some of the types of basic operators are given below :

  • Arithmetic Operators

  • Relational Operators

  • Bitwise Operators

  • Boolean Logical Operators

  • Arithmetic Operators

    In java, arithmetic operators have the same use as in algebra.  Given below table consist of list of arithmetic operators :

    Operator  Result
            + Addition
            -  Subtraction (also unary minus)
           * Multiplication
            / Division
           % Modulus
          ++ Increment
          += Addition assignment
          -= Subtraction assignment
         *= Multiplication assignment
          /= Division assignment
         %= Modulus assignment
          -- Decrement

    Bitwise Operators

    Java defines several bitwise operators which can be applied to the integer types, long, int, short, char, and byte. These operators act upon the individual bits of their operands. They are summarized in the following  :

    Operator Result
           ~ Bitwise unary NOT
          & Bitwise AND
           | Bitwise OR
          ^ Bitwise exclusive OR
         >> Shift Right
        >>> Shift Right  zero fill
        << Shift left
        &= Bitwise AND assignment
        \=  Bitwise OR assignment
        ^=  Bitwise exclusive OR assignment
       >>=  Shift Right assignment
       >>>=  Shift Right  zero fill assignment
        <<= Shift left assignment

    Relational operator

    The relational operator determine the relationship that one operand has to other. Specifically, they determine equality and ordering . The relational operators are shown here :

    Operator Result
         = = Equal to
         != Not equal to
          > greater than 
          < less than
         >= greater than or equal to
         <= less than or equal to

    Boolean Logical Operators

    The Boolean logical operators shown here operates only on Boolean operands. All of the binary logical operators combine  two Boolean values to form a resultant Boolean value.

    Operator Results
          & Logical AND
          \ Logical OR
          ^ Logical XOR(exclusive OR)
         || Short-circuit OR
        && Short-circuit  AND
         ! Logical Unary not
        &= AND assignment
        \= OR assignment
        ^= XOR assignment
        = = Equal to
        != Not equal to
        ? : Ternary if-then-else

    Precedence of Java Operators :

    Given below table shows the order of precedence for java operators, from highest to lowest :

    Highest      
    ( ) [] .  
    ++    --     ~       !
    *     /    %    
    +   -     
    >> >>>    <<  
    >   >=     <  <= 
    = =  !=     
    &      
    ^      
    |      
    &&      
    ||      
    ? :      
    =      
    Lowest      

    Note :The elements in the same row have the same precedence.

    Go to Topic «PreviousHomeNext»

    Your Comment:


    Your Name (*) :
    Your Email :
    Subject (*):
    Your Comment (*):
      Reload Image
     
     
    Tutorial Topics