COSC 1437 Final exam review12345678910

Ace your homework & exams now with Quizwiz!

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

15

A computer program is

A set of instructions that enable the computer to solve a problem or perform a task.

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

True

In ________, inheritance is shown with a line that has an open arrowhead at one end that points to the superclass.

a UML diagram

A for loop normally performs which of these steps?

all

A file that contains raw binary data is known as a(n)

binary file

After the header, the body of the method appears inside a set of

braces, {}

The RandomAccessFile class treats a file as a stream of

bytes.

UML diagrams do not contain

object names

A group of related classes is called a(n)

package

Computers can do many different jobs because they are

programmable

The term ________ commonly is used to refer to a string that is part of another string.

substring

Each byte is assigned a unique number known as an address.

true

You can concatenate String objects by

using the concat method or the + operator.

A UML diagram uses the ________ symbol to indicate that a member is private.

-

When saving a Java source file, save it with an extension of

.java

Which of the following is not a valid Java comment?

/* comment

What will be the value of position after the following code is executed? int position; String str = "The cos jumps over the moon."; position=str.indexOf("ov");

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;

15

In the following code, assume that inputFile references a Scanner object that has been successfully used to open a file: double totalIncome = 0.0; while (inputFile.hasNext()) { try { totalIncome += inputFile.nextDouble(); } catch(InputMismatchException e) { System.out.println("Non-numeric data encountered " + "in the file."); inputFile.nextLine(); } finally { totalIncome = 35.5; } } What will be the value of totalIncome after the following values are read from the file? 2.5 8.5 3.0 5.5 abc 1.0 A) 19.5 B) 0.0 C) 35.5 D) 75.0

35.5

For the following code, how many times would the while loop execute? StringTokenizer st = new StringTokenizer("Java programming is fun!"); while(st.hasMoreTokens()); System.out.println(st.nextToken());

4

If, within one try statement you want to have catch clauses that catch exceptions of the following types, in which order should they appear in your program? (1) Throwable (2) Exception (3) RuntimeException (4) NumberFormatException A) 4, 3, 2, 1 B) 2, 3, 1, 4 C) 4, 1, 3, 2 D) 3, 1, 2, 4

4, 3, 2, 1

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); }

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;

40

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

RAM is usually

A volatile type of memory, used only for temporary storage

To read data from a binary file you create objects from the following classes: A) FileInputStream and DataInputStream B) File and PrintWriter C) File and Scanner D) BinaryFileReader and BinaryDataReader

FileInputStream and DataInputStream

To write data to a binary file you create objects from the following classes: A) File and PrintWriter B) File and Scanner C) FileOutputStream and DataOutputStream D) BinaryFileWriter and BinaryDataWriter

FileOutputStream and DataOutputStream

Which of the following import statements is required to use the Character wrapper class?

No import statement is needed

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

OAK

What is syntax?

Rules that must be followed when writing a program

Variables are

Symbolic names made up by the programmer that represents locations in the computer's RAM

This statement tells the compiler where to find the JOptionPane class and makes it available to your program.

System.exit(0);

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.

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

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

StringBuilder objects are not immutable.

True

When working with the String and StringBuilder class's getChars method, the character at the start position is included in the substring, but the character at the end position is not included.

True

You will cause an off-by-one error, when working with a character position within a string, if you think of the first position in a string as 1.

True

enum constants have a toString method.

True

This is a named storage location in the computer's memory.

Variable

What will be displayed after the following code is executed? String str = "RSTUVWXYZ";

W

What will be displayed after the following statements are executed? Stringbuilder strb=

We have lived in Tampa, Trenton, and Atlanta.

Which of the following statements will correctly convert the data type, if x is a float and y is a double?

X=(float)y;

Unchecked exceptions are those that inherit from: A) the Error class or the RuntimeException class B) the Error class or the Exception class C) the Exception Class or the RuntimeException class D) only the Error class

a

What is demonstrated by the following code? try { (try block statements . . .) } catch(NumberFormatException | IOException ex) { respondToError(); } A) Multi-catch, a catch clause that can handle more than one exception, beginning in Java 7 B) A catch clause that can handle either exception type, but not both C) A conditional catch clause prototype that uses an overloaded OR operator to bind exception types D) This code is not supported in any version of Java, an error will result.

a

When writing a string to a binary file or reading a string from a binary file, it is recommended that you use: A) Methods that use UTF-8 encoding B) The Scanner class methods C) The FileReader and Writer class methods D) The System.In and System.Out methods

a

When you write a method that throws a checked exception, you must: A) have a throws clause in the method header B) override the default error method C) use each class only once in a method D) ensure that the error will occur at least once each time the program is executed

a

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

add

The try statement may have an optional ________ clause, which must appear after all of the catch clauses. A) try-again B) finally C) default D) abort

b

To serialize an object and write it to the file, use this method of the ObjectOutputStream class. A) SerializeObject B) WriteObject C) Serialize D) SerializeAndWrite

b

What will be the result of the following code? FileOutputStream fstream new FileOutputStream("Output.dat"); DataOutputStream outputFile = new DataOutputStream(fstream); A) The outputFile variable will reference an object that is able to write text data only to the Output.dat file. B) The outputFile variable will reference an object that is able to write binary data to the Output.dat file. C) The outputFile variable will reference an object that is able to read binary data from the Output.dat file. D) The outputFile variable will reference an object that is able to write to Output.dat as a random access file.

b

If your code does not handle and exception when it is thrown, this prints an error message and crashes the program. A) Java error handler B) multi-catch C) default exception handler D) try statement

c

What will the following code display? String input = "99#7"; int number; try { number = Integer.parseInt(input); } catch(NumberFormatException ex) { number = 0; } catch(RuntimeException ex) { number = 1; } catch(Exception ex) { number = -1; } System.out.println(number); A) 99 B) 997 C) 0 D) 1

c

When an exception is thrown: A) it must always be handled by the method that throws it B) the program terminates even if the exception is handled C) it must be handled by the program or by the default exception handler D) it may be ignored

c

The following catch clause catch(Exception e)

can handle all exceptions that are instances of the Exception class or one of its subclasses.

In the ________ file format, when the data in a spreadsheet is exported, each row is written to a line, and the values in the cells are separated by commas.

comma separated value

This is a section of code that gracefully responds to exceptions when they are thrown. A) Thrown class B) Default exception handler C) Exception D) Exception handler

d

A characteristic of ________ is that only an object's methods are able to directly access and make the changes to the object's data.

data hiding

This is an item that separates other items.

delimiter

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? PrinterWriter diskOyt = new PrintWriter("DiskFile.txt");

diskOut.println("Calvin");

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);

error

This key word indicates that a class inherits from another class.

extends

What will be displayed after the following code has been executed? boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon"; matches = str1.endsWith(str2); System.out.println(matches);

false

When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.

false

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

false

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

flag

Classes that inherit from the Error class are: A) for exceptions that are thrown when a critical error occurs, and the application program should not try to handle them B) for exceptions that are thrown when a critical error occurs, and the application program should try to handle them C) for exceptions that are thrown when an IOException occurs, and the application program should not try to handle them D) for exceptions that are thrown when an IOException error occurs, and the application program should try to handle them

for exceptions that are thrown when a critical error occurs, and the application program should not try to handle them

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

garbage collection

The following catch statement can: catch (Exception e) {...} A) handle all exceptions that are instances of the Exception class, but not a subclass of Exception B) handle all throwable objects by using polymorphic reference as a parameter in the catch clause C) handle all exceptions that are instances of the Exception class or a subclass of Exception D) is an error since no objects are instantiated in the Exception class

handle all exceptions that are instances of the Exception class or a subclass of Exception

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

initialization list

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);

Which of the following commands will run the compiled Java program named ReadIt?

java Readit

The ArrayList class is in this package.

java.util

Which Scanner class method reads a String?

nextLine

Any ________ argument passed to the Character class's toLowerCase method or toUpperCase method is returned as it is.

nonletter

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

not 1 or 5

What will be displayed after the following code is executed? String str = "abc456"

not ABC???

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

In the blueprint/house analogy, think of a class as a blueprint that describes a house and ________ as instances of the house built from the blueprint.

objects

When a field is declared static, there will be

only one copy of the field in memory.

A subclass can directly access

only public and protected members of the superclass.

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

ordinal

If a method in a subclass has the same signature as a method in the superclass, the subclass method ________ the superclass method.

overrides

If you do not provide an access specifier for a class member, the class member is given ________ access by default.

package

A constructor is a method that

performs initialization or setup operations.

This type of loop will always be executed at least once.

posttest

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

public Rectangle()

Which of the following statements declares Salaried as a subclass of PayType?

public class Salaried extends PayType

A class must implement the Serializable interface in order for objects of the class to be serialized.

t

Beginning in Java 7, multi-catch can reduce a lot of duplicated code in a try statement that needs to catch multiple exceptions, but perform the same operation for each one.

t

If the class SerializedClass contains references to objects of other classes as fields, those classes must also implement the Serializable interface in order to be serialized.

t

In versions of Java prior to Java 7, each catch clause can handle only one type of exception.

t

When the code in a try block may throw more than one type of exception, you need to write a catch clause for each type of exception that could potentially be thrown.

t

The Character wrapper class provides numerous methods for

testing and converting character data.

In general, there are two types of files:

text and binary

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

true

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

true

A method that stores a value in a class's field or in some other way changed the value of a field is known as a mutator method.

true

A procedure is a set of programming language statements that, together, perform a specific task.

true

A solid-state drive has no moving parts and operates faster than a traditional disk drive.

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.

true

Application software refers to programs that make the computer useful to the user.

true

Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members.

true

The Java Virtual Machine is a program that reads Java byte code instructions and executes them as they are read.

true

The System.out.printf method allows you to format output in a variety of ways.

true

The java.lang package is automatically imported into all Java programs.

true

In Java, there are two categories of exceptions:

unchecked and checked

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

unicode number

To get the name of a calling enum constant,

use the toString method.

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

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.

Which of the following is not involved in finding the classes when developing an object-oriented application?

write the code

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

"##0.0%"

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

"000.0"

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

"Has a"

When one object is a specialized version of another object, there is this type of relationship between them.

"is a"

Protected class members can be denoted in a UML diagram with the ________ symbol.

#

In UML diagrams, what symbol indicates that a member is public?

+

What will be the value of z after the following statements have been executed? int x = 4, y = 33; double z; z = (double) (y / x);

8.0

What will be the tokens in the following statement? StringTokenizer st = new StringTokenizer("9-14-2014", "-", true);

9, 14, 2014, and -

When you write an enumerated type declaration, you

All of these

When an array is passed to a method:

All of these answers.

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

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

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

What is the following statement an example of? import java.util.Scanner;

An explicit import statement

If you do not provide initialization values for a class's numeric fields, they will

Be automatically initialized with 0.

You can use the enum key word to

Both create your own data type and specify the values that belong to that type

The ________ class is the wrapper class for the char data type.

Character

This shows the inheritance relationships among classes in a manner that is similar to a family tree.

Class hierarchy

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

ClassB

In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC

ClassC

The key word new

Creates an object in memory.

What does encapsulation refer to?

Encapsulation refers to the combining of data and code into a single object.

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

F

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

False

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);

If you want to append data to the existing binary file, BinaryFile.dat, use the following statements to open the file. A) FileOutputStream fstream = new FileOutputStream("BinaryFile.dat"); DataOutputStream binaryOutputFile = new DataOutputStream(fstream); B) FileOutputStream fstream = new FileOutputStream("BinaryFile.dat", false); DataOutputStream binaryOutputFile = new DataOutputStream(fstream); C) FileOutputStream fstream = new FileOutputStream("BinaryFile.dat", true); DataOutputStream binaryOutputFile = new DataOutputStream(fstream); D) FileOutputStream fstream = new FileOutputStream("BinaryFile.dat"); DataOutputStream binaryOutputFile = new DataOutputStream(fstream, true);

FileOutputStream fstream = new FileOutputStream("BinaryFile.dat", true);DataOutputStream binaryOutputFile = new DataOutputStream(fstream);

Which of the following statements opens a file named MyFile.txt and allows you to append data to its existing contents?

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

Which of the following is not a rule that must be followed when naming identifiers?

Identifiers can contain spaces.

When the this variable is used to call a constructor

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

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.

The exception classes are in packages in the ________. A) Java API B) JVM C) Compiler D) Ex class

Java API

What will be the value of position after the following code is executed? position=str.lastIndexOf("ov",14);

NOT 1

Which of the following statements converts a double variable named tax to a string and stores the value in the String object variable named str?

String str = Double.toString(tax);

To print "Hello, world" on the monitor, use the following Java statement:

System.out.println("Hello, world");

Which of the following statements will display the maximum value that a double can hold?

System.out.println(Double.MAX_VALUE);

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

T

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

T

Java does not limit the number of dimensions that an array may have. 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

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: BankAccount account = new BankAccount(5000.0); What is true about the following statement? System.out.println(account);

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

What will be displayed after the following statements are executed? StringBuilder strb = new StringBuilder (12);

The cow jumped over the moon.

If the data.dat file does not exist, what will happen when the following statement is executed?

The file data.dat will be created

The scope of a local variable is

The method in which they are defined.

Application software refers to

The programs that make the computer useful to the user

To indicate the data type of a variable in a UML diagram, you specify

The variable name followed by a colon and the data type.

What would be displayed as a result of the following code? int x = 578; System.out.print("There are " + x + 5 + "\n" + "hens in the hen house.");

There are 5785 hens in the hen house.

All exceptions are instances of classes that extend this class. A) RunTimeException B) Throwable C) Error D) Exception

Throwable

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

Most of the String comparison methods are case sensitive.

True

Key words are

Words that have a special meaning in the programming language

A wrapper class is a class that is "wrapped around" a primitive data type and allows you to create objects instead of variables.

Wrapper classes

If ClassC is derived from ClassB, which is derived from ClassA, this would be an example of

a chain of inheritance

A runtime error is usually the result of

a logical error

What does the following UML diagram entry mean? + setHeight (h : double) : void

a public method with a parameter of data type double that does not return a value

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

a set of parantheses

A ragged array is:

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

In all but rare cases, loops must contain within themselves

a way to terminate

What is the following statement an example of? import java.util.*;

a wildcard import

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

A class becomes abstract when you place the ________ key word in the class definition.

abstract

A(n) ________ is a method that appears in a superclass, but expects to be overridden in a subclass.

abstract

The variable used to keep the running total is called a(n)

accumulator

A protected member of a class may be directly accessed by

all of the above

The catch clause: A) follows the try clause B) starts with the word catch followed by a parameter list in parentheses containing an ExceptionType parameter variable C) contains code to gracefully handle the exception type listed in the parameter list D) all of the above

all of the above

The StringBuilder class's insert method allows you to insert into the calling object's string

all of these

Which of the following are used as delimiters if the StringTokenizer class's constructor is called and a reference to a String object is passed as the only argument?

all of these

When an "is a" relationship exists between objects, it means that the specialized object has

all the characteristics of the general object, plus additional characteristics

All fields declared in an interface

are final and static

A class's responsibilities include

both the things a class is responsible for doing and the things a class is responsible for knowing

A block of code is enclosed in a set of

braces

When an exception is thrown by code in the try block, the JVM begins searching the try statement for a catch clause that can handle it and passes control of the program to: A) each catch clause that can handle the exception. B) the last catch clause that can handle the exception. C) the first catch clause that can handle the exception. D) If there are two or more catch clauses that can handle the exception, the program halts.

c

In the following statement, what data type must recField be?

char[]

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

chrA != 'A'

One or more objects may be created from a(n)

class

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

conditional

In a UML diagram, you show a realization relationship by connecting a class and an interface with a

dashed line that has an open arrowhead at one end

Variables are classified according to their

data type

If the code in a method can potentially throw a checked exception, then that method must: A) handle the exception B) have a throws clause listed in the method header C) neither A nor B D) either A or B

either A or B

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

You show inheritance in a UML diagram by connecting two classes with a line that has an open arrowhead that points to the subclass.

false

It is common practice in object-oriented programming to make all of a class's

fields private

If a random access file contains a stream of characters, which of the following would you use to set the pointer on the fifth character? A) file.seek(4); B) file.seek(5); C) file.seek(9); D) file.seek(8);

file.seek(8);

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

final

When a method is declared with the ________ modifier, it cannot be overridden in a subclass.

final

A constructor

has the same name as the class.

You should not define a class field that is dependent upon the values of other class fields

in order to avoid having stale data

If a loop does not contain within itself a way to terminate, it is called

infinite loop

In object-oriented programming, ________ allows you to extend the capabilities of a class by creating another class that is a specialized version of it.

inheritance

In a catch statement, what does the following code do? System.out.println(e.getMessage()); A) It prints the stack trace. B) It prints the error message for an exception. C) It prints the code that caused the exception. D) It overrides the toString method.

it prints the error message for an exception.

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

long[]

A method

may have zero or more parameters.

Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.

methods

The ability to catch multiple types of exceptions with a single catch is known as ________, and was introduced in Java 7. A) multi-catch B) super catch C) exception trapping D) compound catch

multi-catch

This ArrayList class method deletes an item from an ArrayList.

remove

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

sentinel

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

set

The ________ method is used to display a message dialog.

showMessageDialog

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

str1.equals(str2)

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

In the following Java statement what value is stored in the variable name? String name = "John Doe";

the memory address where "John Doe" is located

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.

In a class hierarchy,

the more general classes are toward the top of the tree and the more specialized classes are toward the bottom.

In a try/catch construct, after the catch statement is executed: A) the program returns to the statement following the statement in which the exception occurred B) the program terminates C) the program resumes at the statement that immediately follows the try/catch construct D) the program resumes at the first statement of the try statement

the program resumes at the statement that immediately follows the try/catch construct

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

the statement or block following the else is executed.

The only limitation that static methods have is

they cannot refer to nonstatic members of the class.

The ________ method returns a copy of the calling String object, in which all leading and trailing whitespace characters have been deleted.

trim

A constructor is a method that is automatically called when an object is created.

true

A variable's scope is the part of the program that has access to the variable.

true

An abstract class is not instantiated itself, but serves as a superclass for other classes.

true

An access specifier indicates how the class may be accessed.

true

When you call one of the Scanner class's methods to read a primitive value, such as nextInt or nextDouble, and then call the nextLine method to read a string, an annoying and hard-to-find problem can occur.

true

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

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.

true

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

true

A flag may have the values

true and false

For the following code, which statement is not true? public class Circle { private double radius; public double x; private double y; }

y is available to code that is written outside the Circle class.

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

you are performing a deep copy.

For the following code, which statement is not true? public class Sphere { private double radius; public double x; private double y; private double z; }

z is available to code that is written outside the circle class.

In a multi-catch, (introduced in Java 7) the exception types are separated in the catch clause by this symbol: A) * B) ? C) | D) &

|

By default, Java initializes array elements with what value?

0

Subscript numbering always starts at what value?

0

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;

1000

How many bits are in a byte?

8 bits in a byte

The numeric classes' "parse" methods all throw an exception of this type if the string being converted does not contain a convertible numeric value. A) NumberFormatException B) ParseIntError C) ExceptionMessage D) FileNotFoundException

NumberFormatException

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();

Enclosing a group of statements inside a set of braces creates

a block of statements

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

Which of the following is not part of the programming process?

all these are parts of the programming process

The IllegalArgumentException class extends the RuntimeException class, and is therefore: A) a checked exception class B) an unchecked exception class C) never used directly D) none of the above

an unchecked exception class

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; }

ans = 60, x = 0, y = 50

Because Java byte code is the same on all computers, compiled Java programs

are highly portable

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

The data contained in an object is known as

attributes

The throw statement informs the compiler that a method throws one or more exception.

f

________ refers to the physical components that a computer is made of.

hardware

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

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

When a class implements an interface, an inheritance relationship known as ________ is established.

interface inheritance

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

numbers[r].length

The original name for Java was

oak

A(n) ________ is a software entity that contains data and procedures.

object

When a class does not use the extends key word to inherit from another class, Java automatically extends it from the ________ class.

object

In Java, a reference variable is ________ because it can reference objects of types different from its own, as long as those types are related to its type through inheritance.

polymorphic

The two primary methods of programming in use today are

procedural and object-oriented.

Whereas ________ is centered on creating procedures, ________ is centered on creating objects.

procedural programming, object-oriented programming

Software refers to

programs

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

true

You can write a super statement that calls a superclass constructor, but only in the subclass's constructor.

true

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

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

If the IOData.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("IOData.dat", "rw"); A) A FileNotFoundException will be thrown. B) An IOExcepton will be thrown. C) The file IOData.dat will be created. D) This is a critical error, the program will stop execution.

The file IOData.dat will be created.

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

True

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

count-controlled

The throws clause causes an exception to be thrown.

f

If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method.

false

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

false

In an inheritance relationship, the subclass constructor always executes before the superclass constructor.

false

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

false

An exception object's default error message can be retrieved using this method.

getMessage()

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

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

All methods specified by an interface are

public

When an object is serialized, it is converted into a series of bytes that contain the object's data.

t

When deserializing an object using the readObject method, you must cast the return value to the desired class type.

t

An object typically hides it data, but allows outside code to access

the methods that operate on the data.

When an argument is passed by value,

the parameter variable holds the address of the argument.

Because the subclass is more specialized than the superclass, it is sometimes necessary for the subclass to replace inadequate superclass methods with more suitable ones.

true

If you use a flag in a format specifier, you must write the flag before the field width and the precision.

true

Logical errors are mistakes that cause the program to produce erroneous results.

true

Named constants are initialized with a value, and that value cannot change during the execution of the program.

true

Programming style includes techniques for consistently putting spaces and indentation in a program so visual cues are created.

true

Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.

true

The boolean data type may contain the following range of values:

true or false

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;

0.0

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

100

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

12

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

What is the result of the following expression? 17 % 3 * 2 - 12 + 15

7

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 order for an object to be serialized, its class must implement this interface. A) Serial B) Writable C) Serializable D) ObjectOutputStream

Serializable

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);

Which of the following statements is invalid?

double r = 2.9X106;

What will be the displayed when the following code is executed? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y);

error

Variables of the boolean data type are useful for

evaluating conditions that are either true or false

A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event. A) exception handler B) exception C) default exception handler D) error message

exception

The term "default constructor" is applied to the first constructor written by the author of the class.

false

When a local variable in an instance method has the same name as an instance fielterm-311d, the instance field hides the local variable.

false

One of the design tools used by programmers when creating a model of the program is

pseudocode

Which of the following statements correctly specifies two interfaces?

public class ClassA implements Interface1, Interface2

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

public static void passArray(int [][])

Byte code instructions are

read and interpreted by the JVM

What will be displayed after the following statements are executed? String str = "red$green$blue#orange";

red green blue orange

The call stack is an internal list of all the methods that are currently executing.

t

When an exception is thrown by a method that is executing under several layers of method calls, a stack trace indicates the method executing when an exception occurred and all of the methods that were called in order to execute that method.

t

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

true

The primitive data types only allow a(n) ________ to hold a single value.

variable

This is a value that is written into the code of a program.

variable

If, within one try statement you want to have catch clauses of the following types, in which order should they appear in your program: (1) Exception (2) IllegalArgumentException (3) RuntimeException (4) Throwable A) 1, 2, 3, 4 B) 2, 3, 1, 4 C) 4, 1, 3, 2 D) 3, 1, 2, 4

2, 3, 1, 4

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; }

20

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; }

210

What will be the value of z as a result of executing the following code? int x = 5, y = 28; float z; z = (float) (y / x);

5.0

If a method does not handle a possible checked exception, what must the method have? A) A catch clause in its header B) A try/catch clause in its header C) A try clause in its header D) A throws clause in its header

A throws clause in its header

Look at the following code: FileInputStream fstream = new FileInputStream("MyInfo.dat"); DataInputStream inputFile = new DataInputStream(fstream); This code can also be written as: A) FileInputStream inputFile = new FileInputStream(new DataInputStream("MyInfo.dat")); B) DataInputStream inputFile = new DataInputStream(new FileInputStream("MyInfo.dat")); C) FileInputStream fstream = new DataInputStream("InputFile.txt"); D) DataInputStream inputFile = new DataInputStream("InputFile.txt");

DataInputStream inputFile =new DataInputStream(new FileInputStream("MyInfo.dat"));

All of the exceptions that you will handle are instances of classes that extend this class. A) RunTimeException B) IOException C) Error D) Exception

Exception

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

F

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

F

If a string has more than one character used as a delimiter, we must write a loop to determine the tokens, one for each delimiter character.

False

The String class's valueOf method accepts a string representation as an argument and returns its equivalent integer value.

False

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

False

Assume that the classes BlankISBN, NegativePrice, and NegativeNumberOrdered are exception classes that inherit from Exception. The following code is a constructor for the Book class. What must be TRUE about any method that instantiates the Book class with this constructor? public Book(String ISBNOfBook, double priceOfBook, int numberOrderedOfBook) throws BlankISBN, NegativePrice, NegativeNumberOrdered { if (ISBNOfBook == "") throw new BlankISBN(); if (priceOfBook < 0) throw new NegativePrice(priceOfBook); if (numberedOrderedOfBook < 0) throw new NegativeNumberOrdered(numberOrderedv); ISBN = ISBNOfBook; price = priceOfBook; numberedOrdered = numberOrderedOfBook; } A) It must call the constructor with valid data or a compiler error will occur. B) It must contain an inner class that extends the IOException class. C) It must handle all of the possible exceptions thrown by the constructor or have its own throws clause specifying them. D) All of the above

It must handle all of the possible exceptions thrown by the constructor or have its own throws clause specifying them.

Which of the following statements correctly creates a Scanner object for keyboard input?

Scanner keyboard = new Scanner(System.in);

To compare the contents of two arrays, you must compare the elements of the two arrays. 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

What will be the result of the following statements? FileInputStream fstream = new FileInputStream("DataIn.dat"); DataInputStream inFile = new DataInputStream(fstream); A) The inFile variable will reference an object that is able to read only text data from the Input.dat file. B) The inFile variable will reference an object that is able to read binary data from the Input.dat file. C) The inFile variable will reference an object that is able to write binary data to the Input.dat file. D) The inFile variable will reference an object that is able to read random access data from the Input.dat file.

The inFile variable will reference an object that is able to read binary data from the Input.dat file.

Trying to extract more tokens than exist from a StringTokenizer object will cause an error.

True

Given the following constructor code, which of the statements are TRUE? public Book(String ISBNOfBook, double priceOfBook, int numberOrderedOfBook) { if (ISBNOfBook == "") throw new BlankISBN(); if (priceOfBook < 0) throw new NegativePrice(priceOfBook); if (numberedOrderedOfBook < 0) throw new NegativeNumberOrdered(numberOrderedv); ISBN = ISBNOfBook; price = priceOfBook; numberedOrdered = numberOrderedOfBook; } A) There is an error: a throws clause should be added to the constructor header. B) Classes extending the Exception class should be created for each of the custom exceptions that are thrown in the constructor. C) The calling method must handle the exceptions thrown in the constructor, or have its own throws clause specifying them. D) All of the above

all of the above

Why does the following code cause a compiler error? try { number = Integer.parseInt(str); } catch (IllegalArgumentException e) { System.out.println("Bad number format."); } catch (NumberFormatException e) { System.out.println(str + " is not a number."); } A) Because you can have only one catch clause in a try statement B) Because NumberFormatException inherits from IllegalArgumentException. The code should handle NumberFormatException before IllegalArgumentException C) Because the Integer.parseInt method does not throw a NumberFormatException D) Because the Integer.parseInt method does not throw an IllegalArgumentException

b

In memory, an array of String objects:

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

Under Windows, which of the following statements will open the file InputFile.txt that is in the root directory on the C: drive? A) FileReader freader = new FileReader("C:\InputFile.txt"); B) FileReader freader = new FileReader("C:\InputFile\txt"); C) FileReader freader = new FileReader("/c/InputFile.txt"); D) FileReader freader = new FileReader("C:\\InputFile.txt");

d

A catch clause that uses a parameter variable of the Exception type is capable of catching any exception that extends the Error class.

f

A message dialog is a quick and simple way to ask the user to enter data.

false

A method that gets a value from a class's field but does not change it is known as a mutator method.

false

Both character literals and string literals can be assigned to a char variable.

false

Colons are used to indicate the end of a Java statement.

false

Compiled byte code is also called source code.

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.

false

Java source files end with the .class extension.

false

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

false

The public access specifier for a field indicates that the field may not be accessed by statements outside the class.

false

When the break statement is encountered in a loop, all the statements in the body of the loop that appear after it are ignored, and the loop prepares for the next iteration.

false

An exception's default error message can be retrieved using this method. A) getMessage() B) getErrorMessage() C) getDefaultMessage() D) getDefaultErrorMessage()

getMessage()

Overloading is

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

You use this key word to import a class.

import

When working with the PrintWriter class, which of the following import statements should you have near the top of your program?

import java.io.*;

Which of the following import statements is required to use the StringTokenizer class?

import java.util.StringTokenizer;

The following import statement is required to use the ArrayList class:

import.java.util.ArrayList;

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

inner class.

A(n) ________ is a dialog box that prompts the user for input.

input dialog

Another term for an object of a class is a(n)

instance

When an object is created, the attributes associated with the object are called

instance fields

Methods that operate on an object's fields are called

instance methods.

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?

int number = inputFile.nextInt();

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

length

This is a set of programming language statements that, together, perform a specific task.

procedure

This is a special language used to write computer programs.

programming language

A ________ member's access is somewhere between private and public.

protected

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

str1.equalsIgnoreCase(str2)

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();

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

subscript

If the program does not handle an unchecked exception: A) the exception is ignored B) the program is halted and the default exception handler handles the exception C) the program must handle the exception D) this will cause a compilation error

the program is halted and the default exception handler handles the exception

The Java API provides a class named Math, which contains numerous methods that are useful for performing complex mathematical operations.

true

The ability to catch multiple types of exceptions with a single catch clause is known as multi-catch, and was introduced in Java 7.

true

The term "no-arg constructor" is applied to any constructor that does not accept arguments.

true

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

true

Unlike a console program, a program that uses JOptionPane does not automatically stop executing when the end of the main method is reached.

true

When a class contains an abstract method, you cannot create an instance of the class.

true

When a subclass overrides a superclass method, only the subclass's version of the method can be called with a subclass object.

true

When an "is a" relationship exists between objects, it means that the specialized object has all of the characteristics of the general object, plus additional characteristics that make it special.

true

The boolean expression in an if statement must evaluate to

true or false

A(n) ________ is one or more statements that are executed and can potentially throw an exception.

try block

The sequential search algorithm:

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

Data hiding, which means that critical data stored inside the object is protected from code outside the object, is accomplished in Java by

using the private access specifier on the class fields

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?

while(inputFile.hasNext())

The "has a" relationship is sometimes called a(n) ________ because one object is part of a greater whole.

whole-part relationship

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 will be displayed after the following statements have been executed? int x =15, y = 20, z = 32; x += 12; y /= 6; z-=14; System.out.println("x = " + x + ", y = " + y + ", z = " + z);

x = 27, y = 3, z = 18

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

x = 33, y = 9

What output will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y);

x = 37, y = 5

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}

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}


Related study sets

Computer networking theory midterm

View Set

fluid and electrolyte homework quiz

View Set

Chapter 2: The Production Possibilities Model

View Set

10. Critical Thinking and Creativity

View Set

Astronomy Chapter 22 Neutron Stars and Black Holes

View Set