Chapters 5-8

¡Supera tus tareas y exámenes ahora con Quizwiz!

If a loop does not contain, within itself, a valid way to terminate, it is called a(n) ________ loop do-while for infinite while

infinite

A class that is defined inside another class is called a(n) helper class. enumerated class. nested class. inner class.

inner class.

What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.indexOf("ov"); 18 14 15 17

15

When you write an enumerated type declaration, you are actually creating a special kind of class. should use the standard convention of writing the enum constants in uppercase. do not enclose the enum constants in quotation marks. All of these

All of these

When an array is passed to a method the method has direct access to the original array. it is passed just as any other object would be passed. a reference to the array is passed. All of these are true.

All of these are true.

________ is the term for the relationship created by object aggregation. Inner class "Is a" "Has a" One-to-many

"Has a"

What will be displayed after the following code is executed? StringBuilder strb = new StringBuilder(12); strb.append("The cow "); strb.append("jumped over the "); strb.append("moon."); System.out.println(strb); The cow jump 12The cow jumped over the moon. The cow jumped over the moon. The cow jumped over the moon.

The cow jumped over the moon.

Which of the following ArrayList class methods is used to insert an item at a specific location in an ArrayList? insert add set store

add

In the ________ file format, when data in a spreadsheet is exported, each row is written to a line and commas are used to separate the values in the cells. data interchange extensible markup language comma separated value excel binary

comma separated value

A loop that executes as long as a particular condition exists is called a(n) ________ loop. conditional infinite relational count-controlled

conditional

What will be displayed after the following code is executed? String str1 = "The quick brown fox jumped over the lazy dog."; String str2 = str1.substring(20, 26); System.out.println(str2); lazy d n fox jumped x jump

jumped

The ________ method removes an item from an ArrayList at a specific index. remove clear deleteAt pop

remove

The Character wrapper class provides numerous methods for testing and converting numeric literals. converting objects to primitive data types. testing and converting character data. performing operations with named constants.

testing and converting character data.

Which of the following methods returns a string representing all of the items stored in an ArrayList object? print show getList toString

toString

The ________ method returns a copy of the calling String object with all leading and trailing whitespace characters deleted. concat compress remove trim

trim

To get the name of a calling enum constant simply use the enum constant in the statement. use the toString method. use the ordinal method. use the displayName method.

use the toString method.

Which of the following statements will display the maximum value that a double can hold? System.out.println(Double.MAXIMUM_VALUE); System.out.println(Double.MAX_VALUE); System.out.println(Double.MAX_VAL);

System.out.println(Double.MAX_VALUE);

An item that separates other items is known as a delimiter. partition. sentinel. terminator.

delimiter.

Overloading is having two or more methods with the same signature. writing a method that does too much processing. writing a program that is too large to fit in memory. having two or more methods with the same name but different signatures.

having two or more methods with the same name but different signatures.

When working with the PrintWriter class, which of the following import statements should you have near the top of your program? import java.file.*; import javac.io.*; import java.io.*; import javax.swing.*;

import java.io.*;

Which of the following import statements is required in order to use the ArrayList class? import java.util.Tools; import java.util.API; import java.util.ArrayList; import java.util.Containers;

import java.util.ArrayList;

Which of the following import statements is required to use the StringTokenizer class? import java.text.DecimalFormat; import java.util.Scanner; import javax.swing.JOptionPane; import java.util.StringTokenizer;

import java.util.StringTokenizer;

Which of the following statements converts a String object variable named str to an int and stores the value in the variable x? int x = Integer.parseInt(str); int x = Integer.integer(str); int x - str; int x = Integer.parseInteger(str);

int x = Integer.parseInt(str);

Which of the following is a valid declaration for a ragged array with five rows but no columns? int[][] ragged = new int[][5]; int[][] ragged = new int[5]; int[] ragged = new int[5]; int[][] ragged = new int[5][];

int[][] ragged = new int[5][];

A search algorithm arranges elements in descending order. is rarely used with arrays. is used to locate a specific item in a collection of data. arranges elements in ascending order.

is used to locate a specific item in a collection of data.

To return an array of long values from a method, which return type should be used for the method? long[] long long[ARRAY_SIZE] array

long[]

Which of the following is a correct method header for receiving a two-dimensional array as an argument? public static void passMyArray(int[][] myArray) public static void passMyArray(int[]myArray1, int[]myArray2) public static void passMyArray(array myArray) public static void passMyArray[][](int myArray)

public static void passMyArray(int[][] myArray)

A ________ is a value that signals when the end of a list of values has been reached. sentinel terminal token delimiter

sentinel

You can use the ________ method to replace an item at a specific location in an ArrayList. replace add set remove

set

Before entering a loop to compute a running total, the program should first read all the values into main memory. know exactly how many values there are to total. set all variables to zero. set the accumulator variable to an initial value, often zero.

set the accumulator variable to an initial value, often zero.

In general, there are two types of files which are static and dynamic. encrypted and unencrypted. text and binary. delimited and unlimited.

text and binary.

Given the following method header, what will be returned from the method? public Rectangle getRectangle() the address of an object of the Rectangle class an object that is contained in the class Rectangle a null value the values stored in the data members of the Rectangle object

the address of an object of the Rectangle class

In order to do a binary search on an array the values of the array must be numeric. the array must first be sorted. you must first do a sequential search to be sure the element you are looking for is there. All of these are true

the array must first be sorted.

Which of the following can you use to compare two enum data values? the moreThan, lessThan, and equalsTo methods the equals and compareTo methods the ordinal method the ==, >, and < operators

the equals and compareTo methods

A series of words or other items of data, separated by spaces or other characters, are known as strings. delimiters. tokens. captions.

tokens.

The String class's ________ method accepts a value of any primitive data type as its argument and returns a string representation of the value. valueOf toString getChar trim

valueOf

A partially filled array is normally used when you know how many elements will be in the array but not what the values are. with an accompanying integer value that holds the number of items stored in the array. with an accompanying parallel array. when only a very small number of values need to be stored.

with an accompanying integer value that holds the number of items stored in the array.

When you make a copy of the aggregate object and of the objects that it references, a compiler error will occur. you are performing a deep copy. you are performing a shallow copy. you are performing a nested copy.

you are performing a deep copy.

Assume the following declaration exists: enum Tree ( OAK, MAPLE, PINE ) What will the following code display? System.out.println(Tree.OAK); OAK 0 1 Tree.OAK

OAK

A static field is created by placing the key word static after the access specifier and before the field's data type. after the field name. in brackets, before the field's data type. after the access specifier and the field's data type.

after the access specifier and before the field's data type.

When a method in the ________ class returns a reference to a field object, it should return a reference to a copy of the field object to prevent security holes. nested aggregate inner String

aggregate

A loop that repeats a specific number of times is known as a(n) count-controlled. pretest. infinite. conditional.

count-controlled.

The ________ loop is ideal in situations where you always want the loop to iterate at least once. posttest for while do-while

do-while

The JVM periodically performs the ________ process to remove unreferenced objects from memory. system restore garbage collection memory sweeping memory shuffling

garbage collection

The ________ class is the wrapper class for the char data type. Character StringBuilder Integer String

Character

CRC stands for Class, Recyclability, Collaborations. Class, Redundancy, Collections. Code, Reuse, Constancy. Class, Responsibilities, Collaborations.

Class, Responsibilities, Collaborations.

You can use the enum key word to create your own data type. F Both of these F Neither of these specify the values that belong to the type.

F Both of these

Which of the following statements opens a file named MyFile.txt and allows you to read data from it? File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file); PrintWriter inputFile = new PrintWriter("MyFile.txt"); Scanner inputFile = new Scanner("MyFile.txt"); File Scanner = new File("MyFile.txt");

File file = new File("MyFile.txt"); Scanner inputFile = new Scanner(file);

Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents? PrintWriter outfile = new PrintWriter("MyFile.txt", true); PrintWriter outfile = new PrintWriter(true, "MyFile.txt"); FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter); FileWriter fwriter = new FileWriter("MyFile.txt"); PrintWriter outFile = new PrintWriter(fwriter);

FileWriter fwriter = new FileWriter("MyFile.txt", true); PrintWriter outFile = new PrintWriter(fwriter);

If you have defined a class, SavingsAccount, with a public static method, getNumberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will call the getNumberOfAccounts method? account20.getNumberOfAccounts(); SavingsAccount.account20.getNumberOfAccounts(); SavingsAccount.getNumberOfAccounts(); getNumberOfAccounts();

SavingsAccount.getNumberOfAccounts();

Which of the following statements converts an int variable named number to a string and stores the value in the String object variable named str? String str = Integer.toString(number); String str = integer(number); String str = number.Integer.toString(str); String str = integer.toString(number);

String str = Integer.toString(number);

For the following code, what would be the value of str[2]? String[] str = {"abc", "def", "ghi", "jkl"}; a reference to the String object containing "ghi" "def" "ghi" a reference to the String object containing "def"

a reference to the String object containing "ghi"


Conjuntos de estudio relacionados

Avoiding Group Harms - International Research Perspectives

View Set

The Fall of the Bastille --- 14 July 1789

View Set

Management Chapter 2 Study Guide

View Set

Chapter 1: The Human Body: An Orientation

View Set

Physics 100 Chapter 1( Physics fundamentals)

View Set