Operator Precedence

Start from the beginning
                                        

                   System.out.println("I am the seventh. Below is from left to right");

                   System.out.println("&& \t" + "|| \t");

            }

          public void ternaryOperators(){

                   System.out.println(operator[7] + " operators");

                   System.out.println("I am the eigth. Below is from left to right");

                   System.out.println("? \t" + ": \t");

           }

          public void assignmentOperators(){

                   System.out.println(operator[8] + " operators");

                  System.out.println("I am the last. Below is from left to right");

                  System.out.println(">>>= \t" + ">>= \t" + "<<= \t" + "!= \t" + "^= \t" + "&= \t" + "%= \t" + "/= \t" + "*= \t" + "-= \t" + "+= \t" + "= \t");

          }

}

public class OperatorPrecedence{

           public static void main(String[] args){

                    MathOperators mo = new MathOperators("PushUrASsRightsBeforeLosingAny");

                     mo.postfixAndPrefixOperators();

                     System.out.println("");

                      mo.unaryOperators();

                      System.out.println("");

                      mo.arithmeticOperators();

                       System.out.println("");

                       mo.shiftOperators();

                      System.out.println("");

                       mo.relationalOperators();

                      System.out.println("");

                      mo.bitwiseOperators();

                       System.out.println("");

                      mo.logicalOperators();

                        System.out.println("");

                      mo.ternaryOperators();

                       System.out.println("");

                       mo.assignmentOperators();

          }

}


================================================================================

Output:

postfix operators

I am the top of the chain. Below is from left to right

x++ x-- ++x --x

unary operators

I am next to the top. Below is from left to right

+x -x ~ !

arithmetic operators

I am third to the top. Below is from left to right

* / % + -

Shift operators

I am the fourth. Below is from left to right

<< >> >>>

relational operators

I am the fifth. Below is from left to right

< > <= >= instanceof == !=

bitwise operators

I am the sixth man. Below is from left to right

& ^ |

logical operators

I am the seventh. Below is from left to right

&& ||

ternary operators

I am the eigth. Below is from left to right

? :

assignment operators

I am the last. Below is from left to right

>>>= >>= <<= != ^= &= %= /= *= -= += =

================================================================================

Note that operator precedence takes place in math calculation or in java program if you forgot to put a parenthesis on your calculation. The significance of this is when you are taking an exam in a company you are applying for. Usually these showed up since it would be easy to ignore it when you knew that you could use a parenthesis since from the start.


Java codes i learned onlineWhere stories live. Discover now