Search This Blog

Sunday, 30 November 2014

Difference between Vector and ArrayList


Vector:

  • Vector is legacy class means that is introduced in Java 1.0.
  • Vector class are Thread Safe.
  • All method in the Vector class are Syncronized.
  • Relatively Speed is less than the ArrayList.


ArrayList:

  • ArrayList is new  class means that is introduced in Java 2.0.
  • ArrayList class are not Thread Safe.
  • No any method in the Vector class is Syncronized.
  • Relatively Speed is faster than the Vector.

Difference between Enumeration and Iterator

Enumeration:

  • Enumeration is the legacy class which is used on legacy Interface.
  • Enumeration is Fail Safe means we can modify the object in the retrieving time.
  • Enumeration is Introduced in Java 1.0
  • Enumeration has no any method for removing the element.
  • Enumeration method name are Big.


Iterator:

  • Iterator is not legacy class it is used for any type of collection.
  • Iterator is Fail Fast  means we can not modify the object at the retrieving time.
  • Iterator is Introduced in  Java 1.0.
  • Iterator has remove() method for removing the element.
  • Iterator method name are smaller than the Enumeration.

Tuesday, 25 November 2014

Difference between Exception and Error



Exception :


Exception is occured due to logical mistake of our program that's why Exception are occured at runtime.
Programmer can handale the Exception.

Example :FileNotFoundException
ArithmaticException



Error :


Error is occured due to System failure problem.not programmer.
Error can not handale by the programmer.

Example :StackoverflowErrror
lackOfResourceError



Difference between Checked Exception and Unchecked Exception



Checked Exception :


The Exception which are checked by compiler whether programmer handaling or not such type of Exception are callad checked Exception.

Example :FileNotFoundException



UnChecked Exception :


The Exception which are not checked by compiler whether programmer handaling or not such type of Exception are callad Unchecked Exception.

Example :ArthmaticException



Note :


Exception always occur at runtime means the checked or unchecked exception also occured at the Runtime.

Difference between StringBuffer and StringBuilder in Java



StringBuffer :


StringBuffer Introduced In Java 1.0 version.
StringBuffer Is Thread Safe Class.
All method in the StringBuffer are Syncronized.
At speed StringBuffer is slow than the StringBuilder because of syncronization.

StringBuilder :


StringBulider Introduced In Java 5.0 version.
StringBuffer Is Non-Thread Safe Class.
All method are Non- Syncronized.
At speed StingBuilder is faster than the StringBuffer .

Java Interivew Question

Exaplain about final,finally,finaliz in Java


final :

final is modifier in java which is used for variable,method and class.
1 :if declare variable as final that variable becomes a constant means we can not change the value of that variable.
2 :if declare method as final that means we can not override that method in subclass i.e we can not provide the method body into the subclass.
3 :if we declare class as final means we can extends that class.i.e.we can not inherit that class into subclass


finally :

finally is block which is associated with try - catch for resource deallocation.finally is block which 100% excute if any Exception raise or not.if any resource allocated that deallocation code we write into the finaaly block.




finalize :

finalize is a method of object class is also used for deallocation of object.that method is automatically callad by object.if any object going to Garbadge Collection before object going to Garbadge Collection the fialize method is callad for resource deallocation of object.i.e means database connection any network connection allocated that resource are deallocated into the finalize method.