java4all@1986 java. Powered by Blogger.

CORE JAVA INTERVIEW QUESTIONS AND ANSWERS

>> Wednesday, May 25, 2011

Q:What is the difference between an Interface and an Abstract class?
A:     An abstract class can have instance methods that implement a default behavior.
   An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract.
   An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.),
   but has some abstract methods.

Q: What is the purpose of garbage collection in Java, and when is it used?
A: The purpose of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources can be reclaimed and reused.
A Java object is subject to garbage collection when it becomes unreachable to the program in which it is used. .

Q:Explain different way of using thread?
A:The thread could be implemented by using runnable interface or by inheriting from the Thread class.
The former is more advantageous, 'cause when you are going for multiple inheritance..the only interface can help.


Q:Difference between HashMap and HashTable?
A:The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.
(HashMap allows null values as key and value whereas Hashtable doesnt allow). HashMap does not guarantee that the order of the map will remain constant over time.
HashMap is unsynchronized and Hashtable is synchronized.

Q:Difference between Vector and ArrayList?
A:Vector is synchronized whereas ArrayList is not. Vector performance is low ,
When compared to ArrayList.For multiple Threads acting on an object ArrayList is best suitable.
For a single Thread Vector is suitable.Both are growable and re-sizeable.
Vector introduced in 1.0 version where as ArrayList Introduced in 1.2 version.

Q:What is the difference between a constructor and a method?
A: A constructor is a member function of a class that is used to create objects of that class.
It has the same name as the class itself, has no return type,
and is invoked using the new operator.A method is an ordinary member function of a class.
It has its own name, a return type (which may be void), and is invoked using the dot operator.


Q:)Illustrate public,protected,default and private?    
A:public : Public class is visible in other packages, field is visible everywhere (class must be public too)
private : Private variables or methods may be used only by an instance of the same class that declares the variable or method,
A private feature may only be accessed by the class that owns the feature.
protected : Is available to all classes in the same package and also available to all subclasses of the class that owns the protected feature.
This access is provided even to subclasses that reside in a different package from the class that owns the protected feature.
default :What you get by default ie, without any access modifier (ie, public private or protected).
It means that it is visible to all within a particular package.

Q:)What is Difference between static,instance?
A:  static: If the value of variable is same for all objects.For static variables only one copy is created and shared to all objects.
  Instance:I the value of variable is varied from instance to instance.For every object a separated copy of instance is created.
Q:)Why we can't override static methods?
 A: Static means they are associated with class.In static methods ,the binding mechanism is static binding.So it must be available at compile time.


  Q:)What is difference between yield() and sleep()?
A:)When an object invokes yield() ,it returns to ready state.When an object invokes sleep() it goes to waiting state.yeild() is static native, sleep() is only static.

0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP