Skip to main content

Assignment & Operator part 6

                                         Java Operator Precedence

    1 unary Operator([],x++,x--,++x,--x,~,!,new,<type>) 
   2 Arithmetic Operator(*,/,%,+,-)
   3 Shift Operators(>> ,>>>,<<)
   4 Comprasion Operators(<,<=,>,>=,instanceof)
   5 Equality Operators(==,!=)
   6 Bitwise Operator(^,&,|)
   7 Short Circuit Operators(&&,||)
   8 Conditional Operators(?:)
   9 Assignment Operators(=,+=,-=,*=,/=,............)

evaluation order of java operands -:In java we have only operator precedence but not operand precedence before applying any operator all operands will be evaluated from left to right.

Example-:
/*
class Test {
public static int m1(int x){
   System.out.println(x);
   return x;
}
public static void main(String... args){
   System.out.print(m1(1)+m1(2)*m1(3)/m1(4)+m1(5)*m1(6));
}
}
output is-: 1
                  2
                  3
                  4
                  5
                  6
                  32 
evalution    (1+2*3/4+5*6)
                  (1+6/4+5*6)
                  (1+1+5*6)
                  (1+1+30)
                   (2+30)
                
*/

Popular posts from this blog

Java

Codes With Java — Basics Codes With Java Java tutorials & fundamentals About Contact Privacy Basic Fundamentals Java source file structure Import Statement Static Import Packages Data Type Variables Final Variable Declaration and Access Modifier Inner classes applicable modifiers Static Modifier Synchronized Native Transient Volatile Interface Introduction Interface Declaration and Implementation Interface methods and variables Naming Conflicts Interface Marker interface and Ad...

Short Circuite Operators part 4

                                                             Short Circuit Operators In  Java logical operators , if the evaluation of a logical expression exits in between before complete evaluation, then it is known as  Short-circuit . A short circuit happens because the result is clear even before the complete evaluation of the expression, and the result is returned. Short circuit evaluation avoids unnecessary work and leads to efficient processing. 1-: AND(&&) 2-:OR(||) these are exactly same as bitwise operators (&,|) except the following differences. Single Short Circuit Operator(&,|) Both arguments Should be evaluated always. relatively performance is low. Applicable for both boolean and Integral types. Double Short Circuit Operator(...

Final Variable

Final Instance Variable If the value of a variable changes from object to object, such a variable is called an instance variable . For every object, a separate copy of the instance variable will be created. Instance variables do not require explicit initialization; JVM always provides default values. Example: class Test { int x; // instance variable public static void main(String... args) { Test t = new Test(); System.out.println(t.x); // output: 0 } } If the instance variable is declared as final , then explicit initialization is mandatory. JVM will NOT provide default values. Example: class Test { final int x; } Compile-time Error: variable x might not have been initialized. Rule: A final instance variable must be initialized before constructor completion . Possible places for initialization: 1. At the time of declaration class Test { final int x = 10; } 2. Inside an instance blo...