Java Interview Questions and Answers on Exception Handling - 1

Question: 1

What are the advantages of the model over the event inheritance model?

The event delegation model has two advantages over the event inheritance model. They are

It enables event handling by objects other than the ones that generate the events.

This allows a clean separation between a components design and its use.

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 be repeatedly process unhandled events as is in the case of the event inheritance.

Question: 2

What event results from the clicking of a button?

The ActionEvent event is generated as the result of the clicking of a button.

Question: 3

What is source and listener?

Source: A source is an object that generates an event. This occurs when the internal state of that object changes is some way.

Listener: A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events.

Second, it must implement methods to receive and process these notifications.

Question: 4

What is the highest level event class of the event delegation model?

The java.util.EventObject class is the highest level class in the event delegation class hierarchy.

Question: 5

What is the difference between the JDK 1.02 event model and event delegation model introduced with JDK 1.1?

The JDK 1.02 event model use an event inheritance or bubbling approach.

In this model, components are required to handle their own events.

If they do not handle a particular event, the event is inherited by (or bubbled up to) the components container and so on, until the highest level container has been tried.

In the event delegation model, specific objects are designated as event handlers for GUI components.

These objects implement event listener interfaces.

The event delegation model is more efficient than the event inheritance model because it eliminates the processing required to support the bubbling of unhandled events.

Related Questions