Introduction to Java Programming, Seventh Edition, Y. Daniel Liang

Chapter 32 JavaBeans and Bean Events


Section 32.2 JavaBeans
1  Which of the following is true?

A. A bean must be a public class.
B. A bean must have a public no-arg constructor.
C. A bean cannot have any constructors with parameters.
D. A bean must implement the java.io.Serializable interface to ensure a persistent state.

2  Which of the following is true?

A. A bean must provide an accessor method for each data field in the class.
B. A bean must provide a mutator method for each data field in the class.
C. A bean must provide both accessor method and mutator method for each data field in the class.
D. A bean property must be defined as a data field.
E. Every Java GUI component is a JavaBeans component.

Section 32.3 Bean Properties
3  The signature for the accessor method of a Date property birthDate should be __________.

A. public java.util.Date birthDate()
B. public java.util.Date getbirthDate()
C. public java.util.Date getBirthDate()
D. private java.util.Date birthDate()
E. private java.util.Date getBirthDate()

4  The signature for the mutator method of a Date property birthDate should be __________.

A. public void birthDate()
B. public void setbirthDate()
C. public void setBirthDate(java.util.Date date)
D. public void birthDate(java.util.Date date)

5  The signature for the accessor method of a Boolean property visible should be __________.

A. public boolean getVisible()
B. public boolean isVisible()
C. public static boolean isVisible()
D. public boolean visible()
E. private boolean isVisible()

Section 32.4 Java Event Model Review
6  An event and its corresponding listener are referred to as ____________.

A. an event set
B. an event pair
C. an event object
D. an event class

7  Any event is an instance of _________.

A. java.util.EventObject
B. java.awt.Component
C. javax.swing.JComponent
D. java.awt.ActionEvent

8  Any listener is an instance of _________.

A. java.util.EventListener
B. java.awt.ActionListener
C. javax.swing.JComponent
D. java.util.EventObject

9  The signature for the registration method for an ActionEvent should be __________.
    
A. public void setActionListener(ActionListener l)
B. public void addActionListener(ActionListener l)
C. public void addActionListener(ActionEvent l)
D. public void setAction(ActionListener l)

Section 32.5 Creating Custom Source Components
10  Which of the following is true?

A. A source component must have the appropriate registration and deregistration methods for adding and removing listeners.
B. Events can be unicasted (only one listener object is notified of the event).
C. Events can be multicasted (each object in a list of listeners is notified of the event).
D. The naming pattern for adding a unicast listener is "public void add<Event>Listener(<Event>Listener l) throws TooManyListenersException"
E. The naming pattern for adding a multicast listener is "public void add<Event>Listener(<Event>Listener l)"

11  Which of the following statements are true with regard to a source component?

A. The source component contains the code for invoking the event handler from each listener for the source.
B. The registration and deregistration methods are synchronized to avoid race condition on the list that stores the listeners.
C. The source component contains the code to create an event.
D. The source component should always contain the code that register a listener with the source.

12  ___________ creates an ActionEvent.

A. new ActionEvent()
B. new ActionEvent(this)
C. new ActionEvent(this, ActionEvent.ACTION_PERFORMED, null);
D. new ActionEvent(null, ActionEvent.ACTION_PERFORMED, this);

Section 32.6 Creating Custom Event Sets
13  Which of the followings are true?
A. A custom event class must extend java.util.EventObject or a subclass of java.util.EventObject.
B. An event class does not have a no-arg constructor, because you must always specify a source for the event when creating an event.
C. A custom event listener interface must extend java.util.EventListener or a subinterface of java.util.EventListener, and define the signature of the handlers.
D. By convention, an event class should be named with suffix Event.
E. A listener interface for a custom event BeatEvent should be named BeanListener by convention.