Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js
Batts
Quiz by , created more than 1 year ago

Fall 2014

1900
0
0
Batts
Created by Batts over 10 years ago
Rate this resource by clicking on the stars below:
1 2 3 4 5 (0)
Ratings (0)
0
0
0
0
0

0 comments

There are no comments, be the first and leave one below:

Close

Java Test 2

Question 1 of 49 Question 1 of 49

1

Which components contains menus?

Select one of the following:

  • Combo box

  • Menu bar

  • Title bar

  • Menu button

Explanation

Question 2 of 49 Question 2 of 49

1

Which of the following statements for a JTextField is FALSE?

Select one of the following:

  • Can be used to display editable text.

  • Displays a list of fields.

  • Can be used to display un-editable text.

  • Enables users to enter data from the keyboard.

Explanation

Question 3 of 49 Question 3 of 49

1

Which of the following statements about heavyweight components is FALSE?

Select one of the following:

  • The look-and-feel may vary across platforms

  • Several Swing components are heavyweight components

  • The functionality may vary across platforms

  • AWT components are not heavyweight components

Explanation

Question 4 of 49 Question 4 of 49

1

Which pair of words does NOT complete the sentence below correctly?
A ______ is a _______.

Select one of the following:

  • JComponent, Container

  • Container, JPanel

  • Container, Component

  • Component, Object

Explanation

Question 5 of 49 Question 5 of 49

1

__________ provides the basic attributes and behaviors of a window — a title bar at the top of the window, and buttons to minimize, maximize and close the window.

Select one of the following:

  • JSwing

  • JWindowControl

  • JFrame

  • JLabel

Explanation

Question 6 of 49 Question 6 of 49

1

Method ________ can be used to set the layout manager of a container.

Select one of the following:

  • setLayoutManager

  • setGUILayout

  • setLayout

  • setManager

Explanation

Question 7 of 49 Question 7 of 49

1

A JLabel can be attached to a JFrame using method:

Select one of the following:

  • attach

  • add

  • contain

  • append

Explanation

Question 8 of 49 Question 8 of 49

1

A JRadioButton is different from a JCheckBox in that _______.

Select one of the following:

  • a JRadioButton is a state button, JCheckBox is not.

  • a JRadioButton is a type of button, JCheckBox is not

  • a JRadioButton is a subclass of JToggleButton, JCheckBox is not.

  • normally several JRadioButtons are grouped together and are mutually exclusive.

Explanation

Question 9 of 49 Question 9 of 49

1

The logical relationship between radio buttons is maintained by objects of what class?

Select one of the following:

  • RadioButtonGroup

  • ButtonGroup

  • MutualExclusionGroup

  • Group

Explanation

Question 10 of 49 Question 10 of 49

1

Adding a ButtonGroup object to a container:

Select one of the following:

  • results in a compilation error.

  • None of the above.

  • is necessary for the functionality of the ButtonGroup to work properly.

  • causes all the JRadioButtons in the group to have their event handlers registered.

Explanation

Question 11 of 49 Question 11 of 49

1

JButtons generate what type of event?

Select one of the following:

  • WindowEvents

  • ChangeEvents

  • MouseEvents

  • ActionEvents

  • Both A and D are correct

Explanation

Question 12 of 49 Question 12 of 49

1

A JFrame supports three operations when the user closes the window.
Which of the choices below is NOT one of the three:

Select one of the following:

  • HIDE_ON_CLOSE

  • DISPOSE_ON_CLOSE

  • LOWER_ON_CLOSE

  • DO_NOTHING_ON_CLOSE

Explanation

Question 13 of 49 Question 13 of 49

1

Which of the following is not one of the seven methods for handling window events?

Select one of the following:

  • windowClosing

  • windowClosed

  • windowOpening

  • windowOpened

Explanation

Question 14 of 49 Question 14 of 49

1

Which of the following is FALSE?

Select one of the following:

  • JFrame is a subclass of Frame (which is a subclass of Window).

  • JFrame is a lightweight component.

  • A JFrame window will look like all other windows displayed on that platform.

  • JFrames have a title bar and a border.

Explanation

Question 15 of 49 Question 15 of 49

1

What happens if setSize is not called on a JFrame (assume pack is not called)?

Select one of the following:

  • Only the title bar appears.

  • The window is displayed at its preferred size

  • It is a syntax error.

  • The window is not displayed.

Explanation

Question 16 of 49 Question 16 of 49

1

Which of the following does NOT generate GUI events?

Select one of the following:

  • Displaying the text in a label.

  • Selecting an item from a menu.

  • Typing in a text field.

  • Moving the mouse.

Explanation

Question 17 of 49 Question 17 of 49

1

Which of the following most completely describes the steps for setting up event handling for a GUI component?

Select one of the following:

  • Create a class that represents the event handler and implement an appropriate event-listener interface.

  • Create a class that represents the event handler, implement an appropriate event-listener interface and register the event handler.

  • Implement an appropriate event-listener interface and register the event handler.

  • Create a class that represents the event handler, attach the JFrame to a JWindow object and register the event handler.

Explanation

Question 18 of 49 Question 18 of 49

1

When the user presses Enter in a JTextField, the GUI component generates an _______, which is processed by an object that implements the interface ________ .

Select one of the following:

  • TextEvent, TextEventListener.

  • ActionEvent, ActionEventListener.

  • ActionEvent, ActionListener.

  • TextEvent, TextListener.

Explanation

Question 19 of 49 Question 19 of 49

1

Forgetting to register an event-handler object for a particular GUI component’s event type causes _______.

Select one of the following:

  • None of the above.

  • all of the GUI component's events to be ignored.

  • a compilation error.

    .

  • events of that type to be ignored.

Explanation

Question 20 of 49 Question 20 of 49

1

JTextField contains method _______ to obtain the data entered

Select one of the following:

  • getPassword

  • getText

  • getEcho

  • getInput

Explanation

Question 21 of 49 Question 21 of 49

1

How many even-listener interfaces correspond to each event type?

Select one of the following:

  • zero

  • one

  • one or more

  • two

Explanation

Question 22 of 49 Question 22 of 49

1

The logical relationship between radio buttons is maintained by objects of what class?

Select one of the following:

  • ButtonGroup

  • MutualExclusionGroup

  • RadioButtonGroup

  • Group

Explanation

Question 23 of 49 Question 23 of 49

1

Adding a ButtonGroup object to a container:

Select one of the following:

  • is necessary for the functionality of the ButtonGroup to work properly.

  • none of the above

  • results in a compilation error.

  • causes all the JRadioButtons in the group to have their event handlers registered.

Explanation

Question 24 of 49 Question 24 of 49

1

Which of the following statements about anonymous inner classes is FALSE?

Select one of the following:

  • They are declared without a name.

  • They typically appear inside a method declaration.

  • They can access their top-level class’s members.

  • They are declared with the anonymous keyword.

Explanation

Question 25 of 49 Question 25 of 49

1

Which of the following objects CANNOT trap mouse events?

Select one of the following:

  • JTextField

  • JButton

  • ButtonGroup

  • JComponent

Explanation

Question 26 of 49 Question 26 of 49

1

Which of the following is a MouseMotionListener method?

Select one of the following:

  • mousePressed

  • mouseDragged

  • mouseExited

  • mouseClicked

Explanation

Question 27 of 49 Question 27 of 49

1

A MouseHandler object implements which TWO interfaces?

Select one of the following:

  • MouseListener and MouseEventListener

  • MouseListener and MouseMotionListener

  • MouseListener only

  • MouseListener and MouseActionListener

Explanation

Question 28 of 49 Question 28 of 49

1

In what cases are adapter classes useful?

Select one of the following:

  • None of the above.

  • When an adapter GUI control is clicked.

  • When every method in the event-listener interface is to use the same functionality.

  • When it is not desirable to declare every method in the event-listener interface.

Explanation

Question 29 of 49 Question 29 of 49

1

Which of the following is NOT a KeyListener method?

Select one of the following:

  • keyClicked

  • keyTyped

  • keyReleased

  • keyPressed

Explanation

Question 30 of 49 Question 30 of 49

1

Which of the following classes is not used for file input?

Select one of the following:

  • Formatter

  • ObjectInputStream

  • FileReader

  • FileInputStream

Explanation

Question 31 of 49 Question 31 of 49

1

Streams that input bytes from and output bytes to files are known as:

Select one of the following:

  • character-based streams

  • byte-based streams

  • Unicode-based streams

  • bit-based streams

Explanation

Question 32 of 49 Question 32 of 49

1

Which of the following statements is not equivalent to

File name = new File( "c:\\books\\2009\\files.txt" );

Assume we are currently in the directory c:\books.

Select one of the following:

  • File name = new File( "files.txt" );

  • File name = new File( "c:\\books\\2009", "files.txt" );

  • File name = new File( "2009", "files.txt" );

  • All of the above are equivalent to the statement in the question.

Explanation

Question 33 of 49 Question 33 of 49

1

Which of the following is not an application of a File object?

Select one of the following:

  • Determine whether a file is writable.

  • Open or edit a file.

  • Determine if a file exists.

  • Determine whether a file is readable.

Explanation

Question 34 of 49 Question 34 of 49

1

When all the contents of a file are truncated, this means that:

Select one of the following:

  • All the data in the file is discarded.

  • the data in the file is saved to a backup file.

  • the file is deleted.

  • a FileNotFoundException occurs.

Explanation

Question 35 of 49 Question 35 of 49

1

To catch an exception, the code that might throw the exception must be enclosed in a

Select one of the following:

  • try block

  • throws block

  • catch block

  • finally block

Explanation

Question 36 of 49 Question 36 of 49

1

In the catch block below, what is arithmeticException?

catch ( ArithmeticException arithmeticException )
{
System.err.printf( arithmeticException );
}
// end catch

Select one of the following:

  • A finally block.

  • An exception handler.

  • The name of catch block’s exception parameter.

  • The type of the exception being caught.

Explanation

Question 37 of 49 Question 37 of 49

1

An uncaught exception:

Select one of the following:

  • is an exception that occurs for which there are no matching catch clauses.

  • is an exception that occurs for which the matching catch clause is empty.

  • is another term for a thrown exception.

  • is a possible exception that never actually occurs during the execution of the program.

Explanation

Question 38 of 49 Question 38 of 49

1

Which of the following exceptions is a checked exception?

Select one of the following:

  • IOException.

  • ArithmeticException

  • InputMismatchException.

  • RuntimeException.

Explanation

Question 39 of 49 Question 39 of 49

1

If the catch-or-declare requirement for a checked exception is not satisfied:

Select one of the following:

  • a stack trace will be displayed indicating the exception that has occurred and where it occurred.

  • the compiler will issue an error message indicating that the exception must be caught.

  • a stack trace will be displayed, along with a message indicating that the exception must be caught.

  • the compiler will issue an error message indicating that the exception must be caught or declared.

Explanation

Question 40 of 49 Question 40 of 49

1

In the Java coordinate system, the point (0, 0) is:

Select one of the following:

  • The lower-left corner of the screen.

  • The lower-right corner of the screen.

  • The upper-right corner of the screen.

  • The upper-left corner of the screen.

Explanation

Question 41 of 49 Question 41 of 49

1

Which of the following statements about the Graphics object is true?
A. The Graphics object is an argument to class Component’s repaint method.
B. The Graphics object is instantiated by the user.
C. The Graphics object is the argument to a lightweight GUI component's paintComponent method.
D. The Graphics class is abstract.
E. The Graphics object manages a graphics context.

Select one of the following:

  • A, B, D, E.

  • C, D, E.

  • A, C, E.

  • All are true.

Explanation

Question 42 of 49 Question 42 of 49

1

Which of the following are valid Java statements?
A. Color c = new Color( 0, 255, 0 );
B. Color c = new Color( 0.0f, 1.0f, 0.0f );
C. Color c = new Color( 0.0d, 1.0d, 0.0d );
D. setGreen( c.getGreen() - 2 );

Select one of the following:

  • A, B.

  • All of the above.

  • A, B, C.

  • A, B, D.

Explanation

Question 43 of 49 Question 43 of 49

1

Which of the following properly create and initialize a Font object?
A. Font f = new Font();
B. Font f = new Font( "Serif", Font.Bold + Font.Italic, 19 );
C. Font f = new Font( Font.Bold, 20, "SansSerif" );
D. Font f = new Font( 20, Font.Bold, "Monospaced" );

Select one of the following:

  • D.

  • B and C.

  • A and B

  • B.

Explanation

Question 44 of 49 Question 44 of 49

1

Method getFont of class Graphics returns:

Select one of the following:

  • a Font object representing the current font.

  • the current font name as a string.

  • the font size in points.

  • a Graphics object representing the current font.

Explanation

Question 45 of 49 Question 45 of 49

1

The Java statement:
g.fillOval( 290, 100, 90, 55 );

Select one of the following:

  • Draws a filled oval with its center at coordinates x=290, y=100, with height=90 and width=55.

  • Draws a filled oval bounded by a rectangle with its upper left corner at coordinates x=290, y=100, with width=90 and height=55.

  • Draws a filled oval with its left most point at coordinates x=290, y=100, with height=90 and width=55.

  • Draws a filled oval bounded by a rectangle with its upper left corner at coordinates x=290, y=100, with height=90 and width=55.

Explanation

Question 46 of 49 Question 46 of 49

1

The Java statement:
g.draw3DRect( 290, 100, 90, 55, true );

Select one of the following:

  • draws a rectangle that appears to be raised (the top and left edges of the rectangle are slightly darker than the rectangle).

  • draws a rectangle that appears to be lowered (the top and left edges of the rectangle are slightly darker than the rectangle).

  • draws a rectangle that appears to be raised (the bottom and right edges of the rectangle are slightly darker than the rectangle).

  • draws a rectangle that appears to be lowered (the bottom and right edges of the rectangle are slightly darker than the rectangle).

Explanation

Question 47 of 49 Question 47 of 49

1

Consider the code segment below:
int xValues[] = { 100, 150, 200, 100 };
int yValues[] = { 30, 130, 30, 30 };
g.drawPolyline( xValues, yValues, 4 );

What kind of figure does it draw?

Select one of the following:

  • Rectangle

  • Triangle

  • Square

  • A V with its corner at the top.

Explanation

Question 48 of 49 Question 48 of 49

1

Consider the Java code segment below:
Polygon poly2 = new Polygon();
poly2.addPoint( 100, 30 );
poly2.addPoint( 100, 130 );
Which of the following will create a polygon that is a square?

Select one of the following:

  • poly2.addPoint( 200, 130 );
    poly2.addPoint( 200, 30 );

  • poly2.addPoint( 200, 60 );
    poly2.addPoint( 200, 130 );

  • poly2.addPoint( 100, 130 );
    poly2.addPoint( 100, 230 );

  • poly2.addPoint( 100, 60 );
    poly2.addPoint( 100, 130 );

Explanation

Question 49 of 49 Question 49 of 49

1

The fact that class Graphics is abstract contributes to Java’s portability because:

Select one of the following:

  • drawing is performed differently on every platform that supports Java. A subclass of Graphics must be created that uses the drawing capabilities of the current platform.

  • Class Graphics is not abstract.

  • objects of non-abstract classes can only be instantiated on the Windows platform.

  • drawing should not be performed on non-Linux platforms.

Explanation