Thursday, June 24, 2010

CORE JAVA CONTD...

QUESTION: What is the advantage of the event-delegation model over the earlier event-inheritance model? ANSWER: The event-delegation model has two advantages over the event-inheritance model. First, it enables event handling to be handled by objects other than the ones that generate the events (or their containers). This allows a clean separation between a component's design and its use. The other advantage of the event-delegation model is that it performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to repeatedly process unhandled events, as is the case of the event-inheritance model.

QUESTION: How are commas used in the intialization and iteration parts of a for statement?
ANSWER: Commas are used to separate multiple statements within the initialization and iteration parts of a for statement.

QUESTION: What is an abstract method?
ANSWER: An abstract method is a method whose implementation is deferred to a subclass.

QUESTION: What value does read() return when it has reached the end of a file?
ANSWER: The read() method returns -1 when it has reached the end of a file.

QUESTION: Can a Byte object be cast to a double value?
ANSWER: No, an object cannot be cast to a primitive value.

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: If a variable is declared as private, where may the variable be accessed?
ANSWER: A private variable may only be accessed within the class in which it is declared.

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: What is the % operator?
ANSWER: It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.
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: Which class is extended by all other classes?
ANSWER: The Object class is extended by all other classes.

QUESTION: Can an object be garbage collected while it is still reachable?
ANSWER: A reachable object cannot be garbage collected. Only unreachable objects may be garbage collected.

QUESTION: Is the ternary operator written x : y ? z or x ? y : z ?
ANSWER: It is written x ? y : z.