Thursday, 22 September 2011

What are the differences between ArrayList and LinkedList? java interview questions....

Answer: 
  • it's is a List implementation backed by a Java array, like Vector class
  •  If there are lots of growth periods, performance degrades as the old array needs to be copied into the new array.
  •  However, random access is very quick as it uses an array index to access.
  • LinkedList, the List implementation is backed by a doubly linked list data structure, allowing easy inserts/deletions anywhere in the structure, but really slow random accesses as the access must start at an end to get to the specific position.

for more answers click here



Monday, 19 September 2011

java interview questions ...


What is a static method? java interview questions..

Ans:
  • Static variables are always called by the class name.
  • Class variables or static variables are declared with the static keyword in a class. These are declared outside a class and stored in static memory.
  • The scope of the class variable is same an instance variable. 
  • A static variable is associated with the class as a whole rather than with specific instances of a class. Each object will share a common copy of the static variables .
  •  Class variables are mostly used for constants Its initial value is same as instance variable and gets a default value when its not initialized corresponding to the data type.

for more answers click here


Friday, 16 September 2011

What is the difference between instanceof and isInstance? java interview questions

Ans:



  •  instanceof is used to check to see if an object can be cast into a specified type          without throwing a cast class exception.

  •  isInstance() determines if the specified object is assignment-compatible with the object represented by this Class.         

  • This method is the dynamic equivalent of the Java language instanceof operator.   


  •  The method returns true if the specified Object argument is nonnull and can be cast to the reference type represented by this Class object without raising a ClassCastException. It returns false

  • In instanceof operator You can compare it to a named type only, and not to a Class object. 
  • isInstance remove this problem and call instanceof operator dynamically.




for more answers click here

Monday, 12 September 2011

Difference between Overloading and Overriding? java interview questions...


Ans
          
               1. In overloading,there is a relation ship between methods 
                   available in the same class where as in overridding,there 
                   is relationship between a super class method and subclass 
                   method.
               2. overloading doesn't block  inheritence from the 
                   superclass where as overridding blocks inheritence.

              3. in overloading,seperate methods share the same name 
                  where as in overridding,subclass methods replaces the 
                 superclass.

              4.overloading must have different method signatures where 
                 as overriding must have same signature.

                                 more answers click here

What are the differences between boolean & operator and & operator? java interview questions

Ans:


  • When an expression containing the & operator is evaluated, both operands are evaluated.

  • And the & operator is applied to the operand. When an expression containing && operator is evaluated, the first operand is evaluated.


  •  If the first operand returns a value of true then only the second operand is evaluated otherwise the second part will not get executed. && is also called short cut and.

         more questions and answers click here .





Saturday, 10 September 2011

What are the Applet’s Life Cycle methods? java interview questions..


Ans:
 Following are methods in the life cycle of an Applet:

init() method – called when an applet is first loaded. This method is called only once in the                              entire cycle of an applet. This method usually intialize the variables to be used in the applet.

start( ) method – called each time an applet is started.

paint() method – called when the applet is minimized or refreshed. This method isused for drawing different strings, figures, and images on the applet window.

stop( ) method – called when the browser moves off the applet’s page.

• destroy( ) method – called when the browser is finished with the applet.

How to Make a Class Serializable ? java interview questions


Ans:
There are four basic things you must do when you are making a class serializable. They are:
1. Implement the Serializable interface.
2. Make sure that instance-level, locally defined state is serialized properly.
3. Make sure that superclass state is serialized properly.
4. Override equals( ) and hashCode( ).

Define Hashtable,HashMap and HashSet ? java interview questions


Ans:
Hashtable


Hashtable is basically a datastructure to retain values of key-value pair.
  • It didn’t allow null for both key and value. You will get NullPointerException if you add null value.

  • It is synchronized. So it come with its cost. Only one thread can access in one time.
HashMap
Like Hashtable it also accepts key value pair.
  • It allows null for both key and value

  • It is un-synchronized. So come up with better performance.
HashSet
HashSet does not allow duplicate values. It provides add method rather put method. You also use its contain method to check whether the object is already available in HashSet. HashSet can be used  where you want to maintain a unique list.