java chapter7, COSC 1437 CH6, COSC 1437 Final exam review1234567

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

flag

A ________ is a boolean variable that signals when some condition exists in the program.

count-controlled

A loop that repeats a specific number of times is known as a(n) ________ loop.

When an array is passed to a method:

All of these answers.

What do you normally use with a partially-filled array?

An accompanying integer value that holds the number of items stored in the array

true

An important style rule you should adopt for writing if statements is to write the conditionally executed statement on the line after the if statement.

It is common practice to use a ________ variable as a size declarator.

final

In Java, you do not use the new operator when you use a(n):

initialization list

A class that is defined inside of another class is called a(n)

inner class.

Which of the following is a valid declaration for a ragged array?

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

To return an array of long values from a method, use this as the return type for the method.

long[]

A sorting algorithm is used to locate a specific item in a larger collection of data. T or F?

F

Java limits the number of dimensions that an array may have to 15. T or F?

F

When the this variable is used to call a constructor

It must be the first statement in the constructor making the call.

Declaring an array reference variable does not create an array. T or F?

T

When an array of objects is declared, but not initialized, the array values are set to null. T or F?

T

Look at the following declaration: enum tree oak maple pine What is the fully-qualified name of the PINE enum constant?

Tree.PINE

An enumerated data type is actually a special type of class.

True

An instance of a class does not have to exist in order for values to be stored in a class's static fields.

True

error

What does the following code do? Scanner keyboard = new Scanner(System.in); String filename; System.out.print("Enter the filename: "); filename = keyboard.readString(); PrinterWriter outFile = new PrinterWriter(filename);

error

What is the value of ans after the following code has been executed? int x = 40; int y = 40; int ans = 0; if (x = y) ans = x + 10;

error

What will be displayed after the following code has been executed? int x = 65; int y = 55; if (x >= y) { int ans = x + y; } System.out.println(ans);

210

What will be the value of x after the following code is executed? int x = 10, y = 20; while (y < 100) { x += y; y += 20; }

20

What would be the value of x after the following statements were executed? int x = 10; switch (x) { case 10: x += 15; case 12: x -= 5; break; default: x *= 3; }

false

When two strings are compared using the String class's compareTo method, the comparison is case-insensitive.

true

When you open a file with the PrintWriter class, the class can potentially throw an IOException.

str1.equalsIgnoreCase(str2)

Which of the following expressions could be used to perform a case-insensitive comparison of two String objects named str1 and str2?

chrA != 'A'

Which of the following expressions determines whether the char variable chrA is not equal to the letter 'A'?

if (temp >= 0 && temp <= 100)

Which of the following statements determines whether temp is within the range of 0 through 100?

"000.0"

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 012.8?

"##0.0%"

Which of the following strings could be passed to the DecimalFormat constructor to display 12.78 as 12.8%?

true

You can use the PrintWriter class to open a file and write data to it.

When a field is declared static, there will be

only one copy of the field in memory.

Enumerated types have this method, which returns the position of an enum constant in the declaration list.

ordinal

Of the following, which would be considered the no-arg constructor for the Rectangle class?

public Rectangle()

You can use this ArrayList class method to replace an item at a specific location in an ArrayList.

set

Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the following statement:

str[0].toUpperCase();

To get the name of a calling enum constant,

use the toString method.

If object1 and object2 are objects of the same class, to make object2 a copy of object1

write a method for the class that will make a field by field copy of object1 data members into object2 data members.

By default, Java initializes array elements with what value?

0

Subscript numbering always starts at what value?

0

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

0 through 14

What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 100; for(int i = 0; i < SUB; i++) { x[i] = y; y += 10; }

180

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

A reference to the String "ghi"

In memory, an array of String objects:

consists of elements, each of which is a reference to a String object

To compare the contents of two arrays, you must compare the elements of the two arrays. T or F?

T

if

The ________ statement is used to create a decision structure, which allows a program to have more than one path of execution.

Assume the class BankAccount has been created, and the following statement correctly creates an instance of the class:

The account object's toString method will be implicitly called.

true or false

The boolean expression in an if statement must evaluate to

If a class has a method named finalize, it is called automatically just before an instance of the class is destroyed by the garbage collector.

True

15

What will be the value of x after the following code is executed? int x,y = 15; x = y--;

A ragged array is:

a two-dimensional array where the rows are of different lengths

Java performs ________, which means that it does not allow a statement to use a subscript that is outside the range of valid subscripts for the array.

array bounds checking

? a block of statments

Enclosing a group of statements inside a set of braces creates

The names of the enum constants in an enumerated data type must be enclosed in quotation marks.

False

You can declare an enumerated data type inside of a method.

False

false

In a for loop, the control variable can only be incremented.

Assuming the following declaration exists: enum tree oak maple pine what will the following code display

OAK

An ArrayList object automatically expands in size to accommodate the items stored in it .T or F?

T

Objects in an array are accessed with subscripts, just like any other data type in an array. T or F?

T

Once an array is created, its size cannot be changed. True T or F?

T

The JVM periodically performs this process to remove unreferenced objects from memory.

garbage collection

The ArrayList class is in this package.

java.util

Each array in Java has a public field named ________ that contains the number of elements in the array.

length

Which of the following is a correct method header for receiving a two-dimensional array as an argument?

public static void passArray(int [][])

What do you call the number that is used as an index to pinpoint a specific element within an array?

subscript

In order to do a binary search on an array:

the array must first be sorted in ascending order

This indicates the number of elements, or values, the array can hold.

the array's size declarator

The only limitation that static methods have is

they cannot refer to nonstatic members of the class.

The sequential search algorithm:

uses a loop to sequentially step through an array, starting with the first element

The binary search algorithm:

will cut the portion of the array being searched in half each time the loop fails to locate the search value

What would be the results after the following code was executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; x = y; y = x;

x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

When you make a copy of the aggregate object and of the objects it references,

you are performing a deep copy.

enum constants have a toString method.

True

the statement or block following the else is executed.

In an if- else statement, if the boolean expression is false

true

When you pass the name of a file to the PrintWriter constructor, and the file already exists, it will be erased and a new empty file with the same name will be created.

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 read data from it?

Overloading is

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

This ArrayList class method deletes an item from an ArrayList.

remove

When an individual element of an array is passed to a method:

the method does not have direct access to the original array

A method's signature consists of

the method name and the parameter list.

What would be the results after the following code was executed? int[] x = {23, 55, 83, 19}; int[] y = {36, 78, 12, 24}; for(int a = 0; a < x.length; a++) { x[a] = y[a]; y[a] = x[a]; }

x[] = {36, 78, 12, 24} and y[] = {36, 78, 12, 24}

true or false

A flag may have the values

all

A for loop normally performs which of these steps?

conditional

A loop that executes as long as a particular condition exists is called a(n) ________ loop.

When you write an enumerated type declaration, you

All of these

Which of the statements are TRUE about the following code? final int ARRAY_SIZE = 10; long[] array1 = new long[ARRAY_SIZE];

All the answers are correct

int number = inputFile.nextInt();

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?

?5

How many times will the following do- while loop be executed? int x = 11; do { x += 20; } while (x > 100);

true

If the expression on the left side of the && operator is false, the expression on the right side will not be checked.

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?

SavingsAccount.getNumberOfAccounts();

Java does not limit the number of dimensions that an array may have. T or F?

T

The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.T or F?

T

false

The for loop is a posttest loop that has built-in expressions for initializing, testing, and updating.

false

The while loop is ideal in situations where the exact number of iterations is known.

If you write a toString method for a class, Java will automatically call the method any time you concatenate an object of the class with a string.

True

When an object is passed as an argument, it is actually a reference to the object that is passed.

True

40

What will be displayed when the following code is executed? int y = 10; if (y == 10) { int x = 30; x += y; System.out.println(x); }

15

What will be the value of x after the following code is executed? int x = 75; int y = 60; if (x>y) x = x-y;

unicode number

When a character is stored in memory, it is actually the ________ that is stored.

?10

How many times will the following for loop be executed? for(int count = 10; count <= 21; count ++) System.out.println("Java is great!")

str1.equals(str2)

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?

false

In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression.

true

Unicode is an international encoding system that is extensive enough to represent all the characters of all the world's alphabets.

1000

What will be the value of bonus after the following code is executed? int bonus, sales = 10000; if (sales < 5000) bonus = 200; else if (sales < 7500) bonus = 500; else if (sales < 10000) bonus = 750; else if (sales < 20000) bonus = 1000; else bonus = 1250;

40

What will be the value of x after the following code is executed? int x = 10; for (int y = 5; y < 20; y +=5) x += y;

?90

What will be the value of x after the following code is executed? int x = 10; while (x < 100) { x += 10; }

ans = 60, x = 0 , y = 50

What will be the values of ans, x, and y after the following statements are executed? int ans = 35, x = 50, y = 50; if (x >= y) { ans = x+10; x -= y; } else { ans = y+10; y +=x; }

? x = 33, y = 9

What will be the values of x and y as a result of the following code? int x = 25, y = 8; x += y++;

The key word this is the name of a reference variable that an object can use to refer to itself.

True

0.0

What would be the value of discountRate after the following statements are executed? double discountRate = 0.0; int purchase =100; if (purchase > 1000) discountRate = 0.05; else if(purchase > 750) discountRate = 0.03; else if(purchase > 500) discountRate = 0.01;

If a[] and b[] are two integer arrays, the expression a == b compares the array contents.T or F?

F

________ is the term for the relationship created by object aggregation.

"Has a"

true

A local variable's scope always ends at the closing brace of the block of code in which it is declared.

What will be the value of x[8] after the following code has been executed? final int SUB = 12; int[] x = new int[SUB]; int y = 20; for(int i = 0; i < SUB; i++) { x[i] = y; y += 5; }

60

What is the value of scores[2][3] in the following array? int [] [] scores = { {88, 80, 79, 92}, {75, 84, 93, 80}, {98, 95, 92, 94}, {91, 84, 88, 96} };

94

sentinel

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

braces

A block of code is enclosed in a set of

true

A file must always be opened before using it and closed when the program is finished using it.

while (inputFile.hasNext())

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops shows the correct way to read data from the file until the end of the file is reached?

The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>();

It specifies that only String objects may be stored in the ArrayList object.

a set of parantheses

Java requires that the boolean expression being tested by an if statement be enclosed in

If the following is from the method section of a UML diagram, which of the following statements is true?

This is a public method that accepts a Stock object as its argument and returns a boolean value.

What would be the results of the following code? int[] x = { 55, 33, 88, 22, 99, 11, 44, 66, 77 }; int a = 10; if(x[2] > x[5]) a = 5; else a = 8;

a=5

This ArrayList class method is used to insert an item into an ArrayList.

add

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."

aggregate

By default, a reference variable that is an instance field is initialized to the value

null

You use this method to determine the number of items stored in an ArrayList object.

numberItems

If numbers is a two-dimensional array, which of the following would give the length of row r?

numbers[r].length


Ensembles d'études connexes

Principles of Marketing test 3 (dynamic study modules)

View Set

TTU Sport Finance (Capital Budgeting)

View Set

Unit 7: Evolution and Natural Selection-Science Study Guide

View Set

Spanish vocab: parents, grandparents, etc.

View Set