Chapter 10 Section 10.2 10.2 Q2: An anonymous : a.has no value. b.is a constant or literal. c.can be changed.

northcarolinawrySoftware and s/w Development

Nov 3, 2013 (3 years and 10 months ago)

477 views




Chapter 10


Section 10.2


10.2 Q2: An anonymous
String
:

a.

has no value.

b.

is a constant or literal.

c.

can be changed.

d.

none of the above.


Section 10.3


10.3 Q1: A
String

constructor cannot be passed variables of type:

a.

char

arrays.

b.

int

arrays.

c.

byte

arrays.

d.

String
s

and
StringBuffer
s
.


10.3 Q2:
String

objects are immutable. This means they:

a.

Must be initialized.

b.

Cannot be deleted.

c.

Cannot be changed.

d.

None of the above


Section 10.4


10.4 Q2: How many
String

objects are instantiated by the following code segment (not
including the literals)?

String s1, output;

s1 = "hello";



output += "
\
nThe string reversed is: "

;



for ( int i = s1.length()
-

1; i >= 0; i
--

)


output += s1.charAt( i ) + " " ;


a.

2.

b.

1.

c.

4.

d.

5.


Section 10.5


10.5 Q1: The statement

s1.equalsIgnoreCas
e( s4 )

is equivalent to which of the following?

a.

s1.regionMatches( true, 0, s4, 0, s4.length() );

b.

s1.regionMatches( 0, s4, 0, s4.length() );

c.

s1.regionMatches( 0, s4, 0, s4.length );

d.

s1.regionMatches( true, s4, 0, s4.length );


Section 10.7


10.7 Q2: For

String c = "Hello. She sells sea shells at seashore";

The Java statements


int i = c.indexOf( "ll" );


int j = c.lastIndexOf( "ll" );

will result in:




a.

i = 2

and
j = 24
.

b.

i = 3

and
j = 24
.

c.

i = 2

and
j = 25
.

d.

i = 3

and
j = 23
.


Section 10.8


10.8 Q1: For


Strin
g c = "Now is the time for all";

The Java statements


String i = c.substring( 7 );


String j = c.substring( 4, 12 );

will result in:

a.

i = "he time for all"

and
j = "is the time"
.

b.

i = "the time for all"

and
j = "s the time"
.

c.

i = "the time for all"

and
j

= "is the time "
.

d.

i = "he time for all"

and
j = "s the time"
.


Section 10.10


10.10 Q2: Which of the following is not a method of class
String
?

a.

toUpperCase
.

b.

trim
.

c.

toCharacterArray
.

d.

All of the above are methods of class
String
.


Section 10.11


10.11 Q1:

Which of the following will create a
String

different from the other three?

a.

String r = "123456"

b.

int i = 123;

int j = 456;

String r = String.valueOf(j) + String.valueOf(i);

c.

int i = 123;

int j = 456;

String r = String.valueOf(i) + String.valueOf(j);

d.

int

i = 123;


int j = 456;


String r = i + j;


Section 10.12


10.12 Q2: Which of the following expressions could be used to determine if two
String
s are composed of the
same characters?

a.

String

method
equals
.

b.

The equals operator (
==
).

c.

String

method
inter
n
.

d.

None of the above.


Section 10.13


10.13 Q1:
StringBuffer

objects can be used in place of
String

objects if:

a.

The string data is not constant.


b.

The string data size may grow.

c.

Performance is not critical.

d.

All of the above.





Section 10.14


10.14 Q1: Given

the following declarations:

StringBuffer buf;

StringBuffer buf2 = new StringBuffer();

String c = new String( "test" );

Which of the following is not a valid
StringBuffer

constructor?

a.

buf = new StringBuffer();

b.

buf = new StringBuffer( buf2 );

c.

buf = new Str
ingBuffer( 32 );

d.

buf = new StringBuffer( c );


Section 10.15


10.15 Q1: Which of the following statements is true?

a.

The capacity of a
StringBuffer

is equal to its length.

b.

The capacity of a
StringBuffer

cannot exceed its length.

c.

The length of a
StringBuffer

cannot exceed its capacity.

d.

Both a and b are true.


Section 10.16


10.16 Q1: Consider the statement below:

StringBuffer sb1 = new StringBuffer( "a toyota" );

Which of the following creates a
String

object with the value
"toy"
?

a.

String res = sb1.subString( 2
, 5 );

b.

char dest[] = new char[ sb1.length() ];

sb1.getChars( 2, 5, dest, 0 );

String res = new String( dest );

c.

char dest[] = new char[ sb1.length ];

dest = sb1.getChars( 2, 5 );

String res = new String( dest );

d.

char dest[] = new char[ sb1.length() ];

dest
= sb1.getChars( 0, 3 );


String res = new String( dest );


10.16 Q2: To find the character at a certain index position within a
String
, use the method:

a.

getChars
, with the index as an argument.

b.

getCharAt
, with the index as an argument.

c.

charAt
, with the inde
x as an argument.

d.

charAt
, with the character you are searching for as an argument.


Section 10.17


10.17 Q1: Which of the following creates the string of the numbers from 1 to 1000 most efficiently?

a.


String s;

for ( int i = 1; i <= 1000; i++ )


s += i
;

b.

StringBuffer sb = new StringBuffer( 10 );


for ( int i = 1; i <= 1000; i++ )


sb.append( i );

String s = new String( sb );

c.

StringBuffer sb = new StringBuffer( 3000 );


for ( int i = 1; i <= 1000; i++ )


sb.append( i );

String s = new String( sb

);

d.

All are equivalently efficient.





Section 10.18


10.18 Q1: Consider the statements below:

StringBuffer sb = new StringBuffer( "a toyota" );

sb.insert( 2, "landrover" );

sb.delete( 11, 16 );

sb.insert( 11, " " );

The
StringBuffer

contents at the end o
f this segment will be:

a.

a landrovertoyota
.

b.

a landrover a
.

c.

a landrov a
.

d.

a landrover toy a
.



Section 10.20


10.20 Q2: Consider the Java segment:

String line1 = new String( "c = 1 + 2 + 3" ) ;

StringTokenizer tok = new StringTokenizer( line1 );

int count = t
ok.countTokens();

The value of count is:

a.

8.

b.

7.

c.

13.

d.

4.


10.20 Q3: Consider the Java segment:

String line1 = new String( "c = 1 + 2 + 3" ) ;

StringTokenizer tok = new StringTokenizer( line1, "+=" );


String foo = tok.nextToken();

String bar = tok.nextToken()
;

The values of
foo

and
bar

are:

a.

foo

is
“c ”
,
bar

is


= ”
.

b.

foo

is
“c”
,
bar

is
“ ”
.

c.

foo

is


= ”
,
bar

is


+ ”
.

d.

foo

is
“c ”
,
bar

is


1 ”
.


Chapter 12


Section 12.1


12.1 Q1: Which of the following is not a specific GUI component (control or widgit)?

a.

St
ring.

b.

Label.

c.

Menu.

d.

List.


Section 12.2


12.2 Q2: Which of the following is not a benefit of using Swing GUI components?

a.

Most Swing components are heavyweight.

b.

Most Swing components are written completely in Java

c.

Swing components allow the user to specify a

uniform look and feel across all platforms.

d.

Swing components allow the user to change the look and feel while the program is running.


Section 12.3





12.3 Q1: Which of the following is not a valid constructor for a
JLabel
?

a.

JLabel( int, horizontalAlignment,

Icon
image );

b.

JLabel( Icon
image );

c.

JLabel( String text, Icon
image, int

horizontalAlignment );

d.

JLabel( String text
, int

horizontalAlignment );


12.3 Q2: Which of the following steps is not required to use a
JLabel

as a GUI component?

a.

Declare a reference
to a
JLabel
.

b.

Add to the
contentPane()
.

c.

Instantiate the
JLabel
.

d.

Initialize the
JLabel

text.


Section 12.4


12.4 Q1: Which of the following generate GUI events?

A.

Typing in a text field.

B.

Selecting an item from a menu.

C.

Calling an
itemListener
.

D.

Calling an
adjust
mentListener
.

a.

A and B.

b.

B and C.

c.

C and D.

d.

A and D.


Section 12.5


12.5 Q2:
JTextField

and
JPasswordField

events are handled using which interfaces?

a.

Both use the
ActionListener

interface.

b.

Both use the
TextFieldListener

interface.

c.

Both use the
TextComponentLi
stener

interface.

d.

They use
TextFieldListener

and
ActionListener

interfaces respectively.


Section 12.6


12.7 Q2: Which of the following does not generate an item event when pressed?

a.

JRadioButton
.

b.

JToggleButton
.

c.

JCheckBox
.

d.

JButton
.


Section 12.8


12.8 Q1: W
hen a
JComboBox

is clicked on:

a.

An
ItemEvent

is generated.

b.

A scrollbar is always generated.

c.

An
ActionEvent

is generated.

d.

The
JComboBox

expands to a list.


Section 12.14


12.14 Q1: Which layout manager is the default for
JFrame
?

a.

FlowLayout
.

b.

BorderLayout
.

c.

Gri
dLayout
.

d.

None of the above.


Section 12.14.1





12.14.1 Q2: The layout manager that allows alignment to be controlled is:

a.

FlowLayout
.

b.

BorderLayout
.

c.

GridLayout
.

d.

None of the above.


12.14.1 Q2:
FlowLayout

is:

a.

An
abstract

class.

b.

A way of organizing components v
ertically.

c.

The most basic layout manager.

d.

Left
-
aligned by default.


12.14.2 Q2: The class
BorderLayout
:

a.

Divides an area into five regions:
NORTH
,
SOUTH
,
EAST
,
WEST
, and
CENTER
.

b.

Divides an area into five regions:
UP
,
DOWN
,
LEFT
,
RIGHT
, and
MIDDLE
.

c.

Orders co
mponents vertically.

d.

Orders components horizontally.


Section 12.14.3


12.14.3 Q1: The class
GridLayout

constructs _________ to hold components.

a.

A horizontal grid with one row.

b.

A vertical grid with one column.

c.

A grid with
m

rows and
n

columns.

d.

A square gri
d with the same number of rows as columns.


12.14.3 Q2: When components are added to a container with a
GridLayout
, the component:

a.

Fills the next spot in the row, continuing in the first position of the next row if the current row is full.

b.

Fills the next s
pot in a column, continuing in the first position of the next column if the column is full.

c.

Fills in row
x
, column
y

if
x

and
y
are two integers passed to the
Container

method

add
.

d.

Fills in a random empty position in the grid.


Chapter 13


Section 13.6


13
.6 Q1: A
JFrame

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

a.

DISPOSE_ON_CLOSE
.

b.

DO_NOTHING_ON_CLOSE
.

c.

LOWER_ON_CLOSE
.

d.

HIDE_ON_CLOSE
.

13.6 Q2: Which of the following is not one of the seven met
hods for handling window events?

a.

windowClosing
.

b.

windowClosed
.

c.

windowOpening
.

d.

windowOpened
.


Section 13.7


13.7 Q1: The three applet methods guaranteed to be called by the
appletviewer

are:

a.

init() start() close()
.

b.

init() start() destroy()
.

c.

init() start() pa
int()
.

d.

init() start() update()
.





Section 13.8


13.8 Q2: Which of the statements below is false?

a.

Menus can be attached to
JFrame

objects.

b.

Mnemonics can be used with object of all classes that have subclass
javax.swing.JMenuItem
.

c.

The method
setJMenuBar

attac
hes a menu bar to an object.

d.

None of the above.


Section 13.10


13.10 Q1: Which of the following is not a Java AWT portability issue?

a.

GUI components that have different looks on different platforms may use different amounts of space.

b.

GUI components may hav
e different default functionality.

c.

Different platforms may have different representations of integers.

d.

All of the above.


Section 13.11


13.11 Q1: Which constructor below creates a
JInternalFrame

that is resizable, closable, maximizable, and
minimizable?

a.

J
InternalFrame frame =

new JInternalFrame("Internal Frame", true, true, true, true);

b.

JInternalFrame frame =

new JInternalFrame("Internal Frame", true, true, false, true);

c.

JInternalFrame frame =

new JInternalFrame("Internal Frame", true, true, true, false
);

d.

JInternalFrame frame =

new JInternalFrame("Internal Frame", false, false, true, true);


Section 13.14


13.14 Q2: Which of the following is not a
CardLayout

methods?

a.

next()
.

b.

first()
.

c.

previous()
.

d.

second()
.


Chapter 16


Section 16.1


16.1 Q2: File process
ing programs are generally implemented in Java as __________.

a.

Applets.

b.

Multithreaded programs.

c.

Applications.

d.

Interfaces.


Section 16.2


16.2 Q1: Which statement is false?

a.

The smallest data item in a computer can assume the value 0 or the value 1.

b.

The term
"bit" is short for "byte digit."

c.

Java Unicode characters are composed of 2 bytes each.

d.


A record is typically composed of several fields.



16.2 Q2: Which of the following is arranged in increasing size order?

a.

Field, bit, file, database

b.

Byte, file, databa
se, record




c.

Byte, field, file, record

d.

Bit, field, record, file.


Section 16.4


16.4 Q1: Which statement regarding Java files is false?

a.

Java imposes no structure on a file.

b.

Notions like "record" do not exist in Java files.

c.

The programmer must structure file
s to meet the requirements of applications.

d.

Records in a Java sequential file are stored in order by record key.


16.4 Q2: When displayed, a
JFileChooser

dialog does not allow the user to interact with any other program
window until the
JFileChooser

dialo
g is closed. Dialogs that behave in this fashion are called __________
dialogs.

a.

Synchronized.

b.

Modal.

c.

Median.

d.

Choice.


Section 16.5


16.5 Q1:
RandomAccessFile

method __________ repositions the file
-
position pointer to any position in the file.

a.

seek

.

b.

search
.

c.

serve
.

d.

set
.


Section 16.6


16.6 Q1: Which statement is false?

a.

Updating only a small portion of a sequential
-
access file is a relatively expensive operation.

b.

Updating a large portion of a sequential
-
access file is a relatively efficient operation.

c.

Updatin
g a sequential
-
access file typically involves copying the file.

d.

Updating only a small portion of a sequential
-
access file is a relatively efficient operation.


Section 16.7


16.7 Q1: Which statement is true?

a.

Sequential
-
access files are appropriate for "in
stant
-
access" applications.

b.

Transaction
-
processing systems are good examples of "instant
-
access" applications.

c.

Data cannot be inserted in a random
-
access file without destroying other data in the file.

d.

Airline reservation systems, point
-
of
-
sale systems, a
nd automated teller machines are best implemented as
sequential
-
access applications.


Section 16.8


16.8 Q1: When a
RandomAccessFile

stream is associated with a file, data is read or written beginning at the
location in the file specified by the _________
_.

a.

File
-
location pointer.

b.

Read/write pointer.

c.

File
-
position pointer.

d.

Transaction pointer.


16.8 Q2: Which statement is false?

a.

Swing components display null byte characters as rectangles.

b.

The file open mode for a
RandomAccessFile

can be "
r
" to open the fil
e for reading.

c.

The file open mode for a
RandomAccessFile

can be "
w
" to open the file for writing.

d.

The file open mode for a
RandomAccessFile

can be "
rw
" to open the file for reading and writing.





Section 16.10


16.10 Q1: Which statement about sorting with
direct access techniques is false?

a.

It can be blazingly fast compared to the bubble sort.

b.

It uses storage efficiently.

c.

It uses large amounts of storage relative to the actual space needed to hold the items being sorted.

d.

If often wastes storage.


16.10 Q2: W
hich statement is false? Open a file with the
"r"

mode …

a.

To be able to read from the file.

b.

To prevent unintentional modification of the file's contents.

c.

To implement the "principle of least privilege."

d.

To allow writing only at the end of the file.