Skip to main content

Posts

java interview question from operators

Topic  1-: new Vs newInstance() 2-:instanceof Vs isInstance() 3-:ClassNotFoundException Vs NoClassDefFoundException                                                                 new Vs newInstance() new     It is operator in java. we can use a new operator to create objects if we know class name at the beginning.           ex-:                Student s=new Student();                Test t=new Test(); In this case of new operator based on our requirements we can invoke any constructor           ex-:                Test t=new Test();    ...

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); ...

Assignment Operators

                                                             Assignment Operators There are three types of assignment operators. 1-: Simple assignment ( int x=10) 2-: Chained assignment (int a,b,c,d; a=b=c=d=e=f=10); 3-:Compund assignment (a+=10)                                                             Chained Assignment we can't perform chained assignments directly at the time of declaration. /* int a,b,c,d; a=b=c=d=20; System.out.print(a+" "+b+" "+c+" "+d) ; Output-: 20 20 20 20 int a=b=c=d=20; System.out.print(a+" "+b+" "+c+" "+d);//compile tim...

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(...

Operators & Assignment part 3

                                                                                       Operators & Assignment 1-:instanceof Operators 2-:Bitwise Operators                                                                        instanceof Operators we can use instanceof operator to check whether the given object is of a particular type are not. Example-: /* list is a collection of objects. List l=new List(); l.add(Customer); l.add(Student); l.add(Test); Object o=l.get(...

Assignment operator part 2

                                                    Operator & Assignments 1-:String Concatination Operator(+) 2-:Relational Operators(>,>=,<,<=) 3-:Equality Operators(==,!=)                                                     String Concatenation operator  The only overloaded operator in java is (+) operator some time it accesses arithmetic addition operator some time it access String concatenation operator. if at least one argument is String Type then + operator access concatenation operator and if both arguments are Number type then + operator access arithmetic addition operator. Example-: ...

Error in variable Declaration

  All declaration problem If int greater than size we got error-> error: integer number too large     int x=2147483648; error: integer number too large     int x=-2147483649; error: incompatible types: boolean cannot be converted to int     int x=true; error: incompatible types: int cannot be converted to boolean     boolean x=10; error: incompatible types: possible lossy conversion from double to long   long x=10.88; error: cannot find symbol     boolean x=True;               ^   symbol:   variable True : error: incompatible types: int cannot be converted to boolean   if(x){       ^ : error: incompatible types: int cannot be converted to boolean   while(x){ Above the last both error valid in c and C++ but error in java Size of char in java 2 byte because java is unicode based but c and c++ are ascii code based language System...