Sunday, November 2, 2008

JAVA INTERVIEW QUESTIONS

Here you can find out a list of interview questions for core java and advance java. These questions are often asked by the interviewer for core java job interview. We put our maximum effort to make this answers error free. But still there might be some errors. If you feel any answer given for any question is wrong or if you have a more perfect answer to give, please, please inform us by COMMENTING THE POST.


CORE JAVA QUESTIONS AND ANSWERS:

  • Why threads block or enters to waiting state on I/O?
=>Threads enters to waiting state or block on I/O because other threads can execute while the I/O operations are performed.
  • what is a class?
=> A class is a blueprint of any java program. which helps java to be object oriented.
  • what is an object?
=> An Object is instance of a class.
For eg.
    Abc ob = new Abc();

Abc is a class & ob is a object of class Abc.
  • what is a transient variable?
=>A transient variable is a variable that may not be serialized.
  • which containers use a border Layout as their default layout?
=>The window, Frame and Dialog classes use a border layout as their default layout.
  • How Observer and Observable are used?
=>Subclass of Observable class maintain a list of observers. Whenever an Observable object is updated, it invokes the update() method of each of its observers to notify the observers that it has a changed state. An observer is any object that implements the interface Observer.
  • What is an abstract method ?
=>An abstract method is a method that don't have a body. It is declared with modifier abstract.
  • What is a Vector ?
=>Vector is a grow able array of objects.
  • What's new with the stop(), suspend() and resume() methods in JDK 1.2?
=>The stop(), suspend() and resume() methods have been deprecated in JDK 1.2.
  • What is the initial state of a thread when it is created and started?
=>The thread is in ready state.
  • What is a native method?
=> native method is a method that is implemented in a language other than Java.
  • What modifiers may be used with an inner class that is a member of an outer class?
=>A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
  • What is the use of the finally block?
=>Finally is the block of code that executes always. The code in finally block will execute even if an exception is occurred. finally will not execute when the user calls System.exit().
  • Can we call finalize() method ?
=>Yes. Nobody will stop us to call any method , if it is accessible in our class. But a garbage collector cannot call an object's finalize method if that object is reachable.
  • What is the difference between an Interface and an Abstract class?
=>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.
  • Explain different way of using thread?
=>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.
  • Difference between HashMap and HashTable?
=>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.
  • What is the difference between a constructor and a method?
=>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.
Questions and Answers are updated daily.

No comments: