Ads 468x60px

Pages

Tuesday, 26 June 2012

Java interview questions


Question: What is the purpose of the finally clause of a try-catch-finally statement?
Answer:
The finally clause is used to provide the capability to execute code no matter whether or not an exception is thrown or caught.

Question: What must a class do to implement an interface?
Answer:
It must provide all of the methods in the interface and identify the interface in its implements clause.
Question: What is an abstract method?
Answer:
An abstract method is a method whose implementation is deferred to a subclass. Or, a method that has no implementation (an interface of a method).

Question: What is a static method? 
Answer:
A static method is a method that belongs to the class rather than any object of the class and doesn't apply to an object or even require that any objects of the class have been instantiated.

Question: What is the difference between a static and a non-static inner class?
Answer:
A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.

Question:  What is an object's lock and which object's have locks?
Answer:
  An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.

Question: When can an object reference be cast to an interface reference?
Answer:
An object reference be cast to an interface reference when the object implements the referenced interface.

Question:  What is the difference between a Window and a Frame?
Answer:
The Frame class extends Window to define a main application window that can have a menu bar.

Question: What happens when a thread cannot acquire a lock on an object?
Answer:
If a thread attempts to execute a synchronized method or synchronized statement and is unable to acquire an object's lock, it enters the waiting state until the lock becomes available.

Question: What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?
Answer:
The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

Question: What classes of exceptions may be caught by a catch clause?
Answer:
A catch clause can catch any exception that may be assigned to the Throwable type. This includes the Error and Exception types.

0 comments:

Post a Comment