Ch. 7 - Arrays and the ArrayList Class, Ch. 1 - Introduction to Computers and Java, Ch. 2 - Java Fundamentals, Ch. 3 - Decision Structures, Ch. 4 - Loops and Files, Ch. 5 - Methods, Ch. 6 - A First Look at Classes, Ch. 8 - A Second Look at Classes an...

Ace your homework & exams now with Quizwiz!

If you have defined a class named SavingsAccount with a public static data member named numberOfAccounts, and created a SavingsAccount object referenced by the variable account20, which of the following will assign numberOfAccounts to numAccounts?

numAccounts = SavingsAccount.numberOfAccounts;

Which of the following professions use the computer as a tool?

All of the above

When an array is passed to a method:

All of the above (A reference to the array is passed, It is passed just as an object, & The method has direct access to the original array)

In Java, it is possible to write a method that will return:

All of the above (A whole number, A monetary value, A string of characters, A reference to an object)

The major components of a typical computer system consist of:

All of the above (CPU, I/O devices, main memory, secondary storage)

What does the following statement do? double[] array1 = new double[10];

All of the above (Declares array1 to be a reference to an array of double values, Creates an instance of an array of 10 double values, & Will allow valid subscripts in the range of 0 - 9)

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

All of the above (Design, Testing, Debugging)

Which of the following is a secondary storage device?

All of the above (Hard drives, floppy disks, USB drives)

If you prematurely terminate an if statement with a semicolon, the compiler will:

All of the above (Not display an error message, Assume you are placing a null statement there)

Which of the following are classes from the Java API?

All of the above (Scanner, Random, PrintWriter)

A for loop normally performs which of these steps?

All of the above (initializes a control variable to a starting value, tests the control variable by comparing it to a maximum/minimum value and terminate when the variable reaches that value, & updates the control variable during each iteration)

Breaking a program down into small manageable methods:

All of the above (makes problems more easily solved, allows for code reuse, simplifies programs)

Local variables:

All of the above: (are hidden from other methods, may have the same name as local variables in other methods, lose the values stored in them between calls to the method in which the variable is declared)

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 will be returned from the following method? public static float[] getValue(int x)

An array of float values

Look at the following statement. import java.util.Scanner; This is an example of:

An explicit import

Each repetition of a loop is known as what?

An iteration

Which one of the following is the not equal operator?

!=

Which of the following will format .1278 to display as 12.8%?

##0.0%

Which of the following is the correct boolean expression to test for: int x being a value less than or equal to 500 or greater than 650, and int y not equal to 1000?

((x <= 500 || x > 650) && !(y == 1000))

Which of the following is the correct boolean expression to test for: int x being a value between, but not including, 500 and 650, or int y not equal to 1000?

((x > 500 && x < 650) || (y != 1000))

Which of the following is not a valid comment statement?

**/ comment 3 /**

In UML diagrams, this symbol indicates that a member is public.

+

The increment operator is:

++

In UML diagrams, this symbol indicates that a member is private:

-

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

.java

In Java, the beginning of a comment is marked with:

//

By default, Java initializes array elements with what value?

0

Java automatically stores this value in all uninitialized static member variables:

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

Which of the following will format 12.78 to display as 012.8?

000.0

Look at the following declaration: enum Tree { OAK, MAPLE, PINE } What is the ordinal value of the MAPLE enum constant?

1

If str1 and str2 are both Strings, which of the following expressions will correctly determine whether they are equal? (1) (str1 == str2) (2) str1.equals(str2) (3) (str1.compareTo(str2) == 0)

2 and 3

If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2? (1) (str1 < str2) (2) (str1.equals(str2) < 0) (3) (str1.compareTo(str2) < 0)

3

What is the result of the following expression? 10 + 5 * 3 - 20

5

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

7

What is the result of the following expression? 25 / 4 + 4 * 10 % 3

7

What is the result of the following expression? 25 - 7 * 3 + 12 / 3

8

A byte is a collection of:

8 bits

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

When writing the documentation comments for a method, you can provide a description of each parameter by using a:

@param tag

One or more objects may be created from a:

Class

A Java program must have at least one of these:

Class definition

In your textbook the general layout of a UML diagram is a box that is divided into three sections. The top section has the _______; the middle section holds _______; the bottom section holds _______.

Class name; attributes or fields; methods

In Java, it is standard practice to capitalize the first letter of:

Class names

CRC stands for:

Class, Responsibilities, Collaborations

In the cookie cutter metaphor, think of the ________ as a cookie cutter and ________ as the cookies.

Class; objects

In the programming process which of the following is not involved in defining what the program is to do:

Compile code

A loop that executes as long as a particular condition exists is called a:

Conditional loop

In memory, an array of String objects:

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

A loop that repeats a specific number of times is known as a:

Counter-controlled loop

____________ results in only the object's methods being able to directly access and make the changes to the object's data.

Data hiding

Variables are classified according to their:

Data type

To create a method you must write its:

Definition

This is an item that separates other items.

Delimiter

Which one of the following would contain the translated Java byte code for a program named Demo?

Demo.class

In a @return tag statement the description:

Describes the return value

The process of breaking a problem down into smaller pieces is sometimes called:

Divide and conquer

What is wrong with the following method call? displayValue (double x);

Do not include the data type in the method call

Which one of the following methods would you use to convert a string to a double?

Double.ParseDouble

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

Encapsulation

Variables of the boolean data type are useful for:

Evaluating true/false conditions

TRUE/FALSE: A Java program will not compile unless it contains the correct line numbers.

False

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

False

TRUE/FALSE: A sorting algorithm is used to locate a specific item in a larger collection of data.

False

TRUE/FALSE: All Java statements end with semicolons.

False

TRUE/FALSE: An array can hold multiple values of several different data types simultaneously.

False

TRUE/FALSE: An important style rule you should follow when writing if statements is to line up the conditionally executed statement with the if statement.

False

TRUE/FALSE: Assuming that pay has been declared a double, the following statement is valid. pay = 2,583.44;

False

TRUE/FALSE: Both character literals and string literals can be assigned to a char variable.

False

TRUE/FALSE: Class names and key words are examples of variables.

False

TRUE/FALSE: Colons are used to indicate the end of a Java statement.

False

TRUE/FALSE: Compiled byte code is also called source code.

False

TRUE/FALSE: If a class has a method named finalize, it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.

False

TRUE/FALSE: If a[] and b[] are two integer arrays, the expression a == b compares the array contents.

False

TRUE/FALSE: In Java the variable named total is the same as the variable named Total.

False

TRUE/FALSE: In a for statement, the control variable can only be incremented.

False

TRUE/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

TRUE/FALSE: In the for loop, the control variable cannot be initialized to a constant value and tested against a constant value.

False

TRUE/FALSE: In the method header the static method modifier means the method is available to code outside the class.

False

TRUE/FALSE: In the method header, the method modifier public means that the method belongs to the class, not a specific object.

False

TRUE/FALSE: Instance methods should be declared static.

False

TRUE/FALSE: Java is a case-insensitive language.

False

TRUE/FALSE: Java limits the number of dimensions that an array may have to 15.

False

TRUE/FALSE: Java source files end with the .class extension.

False

TRUE/FALSE: Only constants and variables may be passed as arguments to methods.

False

TRUE/FALSE: Programs never need more than one path of execution.

False

TRUE/FALSE: The contents of a variable cannot be changed while the program is running.

False

TRUE/FALSE: The do-while loop is a pre-test loop.

False

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

False

TRUE/FALSE: The public access specifier for a field indicates that the attribute may not be accessed by statements outside the class.

False

TRUE/FALSE: The term "default constructor" is applied to the first constructor written by the author of a class.

False

TRUE/FALSE: The this key word is the name of a reference variable that is available to all static methods.

False

TRUE/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

TRUE/FALSE: When testing for character values, the switch statement does not test for the case of the character.

False

TRUE/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

TRUE/FALSE: When two Strings are compared using the compareTo method, the cases of the two strings are not considered.

False

TRUE/FALSE: You can declare an enumerated data type inside of a method.

False

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

Fields private

A class specifies the ________ and ________ that a particular type of object has.

Fields; methods

Which of the following will open a file named MyFile.txt and allow you to read data from it?

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

Which of the following will open a file named MyFile.txt and allow you to append data to its existing contents?

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

This is a boolean variable that signals when some condition exists in the program:

Flag

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

Garbage collection

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

Hardware

The term for the relationship created by object aggregation is:

Has a

A constructor:

Has the same name as the class

Overloading means multiple methods in the same class:

Have the same name, but different parameter lists

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

Identifiers can contain spaces.

Quite often you have to use this statement to make a group of classes available to a program.

Import

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

In order to avoid having stale data

In Java, you do not use the new operator when you use an:

Initialization list

____________ is the process of inspecting data given to the program by the user and determining if it is valid.

Input validation

Another term for an object of a class is:

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

A search algorithm:

Is a way to locate a specific item in a larger collection of data

A deep copy of an object:

Is an operation that copies an aggregate object, and all the objects it references.

The computer can do such a wide variety of tasks because:

It can be programmed

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 following package is automatically imported into all Java programs.

Java.lang

Which of the following cannot be used as identifiers in Java?

Key words

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

Literal

This is a control structure that causes a statement or group of statements to repeat.

Loop

This variable controls the number of times that the loop iterates.

Loop control variable

Each different type of CPU has its own:

Machine language

Suppose you are at an operating system command line, and you are going to use the following command to compile a program: javac MyClass.java Before entering the command, you must:

Make sure you are in the same directory or folder where MyClass.java is located

This part of a method is a collection of statements that are performed when the method is executed.

Method body

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

Methods

Which of the following does NOT describe a valid comment in Java?

Multi-line comments, start with **/ and end with /**

The switch statement is a:

Multiple alternative decision structure

This is a variable whose content is read only and cannot be changed during the program's execution.

Named constant

Which of the following values can be passed to a method that has an int parameter variable?

None of the above (float, double, long)

Assuming the following declaration exists: enum Tree { OAK, MAPLE, PINE } What will the following code display? System.out.println(Tree.OAK);

OAK

The original name for Java was:

Oak

This is a software entity that contains data and procedures.

Object

A UML diagram does not contain:

Object names

Most programming languages that are in use today are:

Object-oriented

You cannot use the == operator to compare the contents of:

Objects

When a field is declared static, there will be:

Only one copy of the field in memory

The lifetime of a method's local variable is:

Only while the method is executing

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

Ordinal

This is a group of related classes.

Package

A special variable that holds a value being passed into a method is called what?

Parameter

In the header, the method name is always followed by this:

Parentheses

Which of the following is included in a method call?

Parentheses

A constructor is a method that:

Performs initialization or setup operations.

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

Post-test loop

When you are working with a ____________, you are using a storage location that holds a piece of data.

Primitive variable

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

Software refers to:

Programs

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

Pseudocode

This is a cross between human language and a programming language.

Pseudocode

Byte code instructions are:

Read and interpreted by the JVM

This type of operator determines whether a specific relationship exists between two values:

Relational

Which of the following is not part of a method call?

Return type

Syntax is:

Rules that must be followed when writing a program

This is a sum of numbers that accumulates with each iteration of a loop.

Running total

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

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

Scanner keyboard = new Scanner(System.in);

Which of the following is not a part of the method header?

Semicolon

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

Semicolons

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

Sentinel

Before entering a loop to compute a running total, the program should first do this.

Set the accumulator where the total will be kept to an initial value, usually zero

____________ works like this: If the expression on the left side of the && operator is false, the expression the right side will not be checked.

Short-circuit evaluation

Character literals are enclosed in _____; string literals are enclosed in _____.

Single quotes; Double quotes

Another term for programs is:

Software

The term ___________ typically refers to the device that displays console output.

Standard output device

An object's ____________ is simply the data that is stored in the object's fields at any given moment.

State

Instance methods do not have this key word in their headers:

Static

Static methods can only operate on ____________ fields.

Static

Java allows you to create objects of this class in the same way you would create primitive variables.

String

Which of the following is not a primitive data type?

String

When the (+) operator is used with strings, it is known as the:

String concatenation operator

Which of the following statements will create a reference, str, to the String, "Hello, World"?

String str = "Hello, World";

Which of the following is a valid Java statement?

String str = "John Doe";

Java was developed by:

Sun Microsystems

Variables are:

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

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

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

In most editors, you are indenting by one level each time that you press this key:

Tab

To document the return value of a method, use this in a documentation comment.

The @return tag

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 returned from a method, if the following is the method header? public Rectangle getRectangle()

The address of an object of the class Rectangle

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

A program is a sequence of instructions stored in:

The computer's memory

Internally, the central processing unit (CPU) consists of two parts:

The control unit and the arithmetic & logic unit (ALU)

The header of a value-returning method must specify this.

The data type of the return value

When a computer is running a program, the CPU is engaged in a process formally known as:

The fetch/decode/execute cycle

The scope of a public instance field is:

The instance methods and methods outside the class

The scope of a private instance field is:

The instance methods of the same class

A static field is created by placing:

The key word static after the access field specifier and before the field's data type

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

When a reference variable is passed as an argument to a method:

The method has access to the object that the variable references

When an object is passed as an argument to a method, what is passed into the method's parameter variable?

The object's memory address

When you pass an argument to a method, be sure that the argument's data type is compatible with:

The parameter variable's data type

The phrase divide and conquer is sometimes used to describe:

The process of breaking a problem down into smaller pieces

If you attempt to perform an operation with a null reference variable:

The program will terminate

Application software refers to:

The programs that make the computer useful to the user

A class's responsibilities include:

The things a class is responsible for doing & for knowing (Both)

In a UML diagram to indicate the data type of a variable, enter:

The variable name followed by a colon and the data type

The only limitation that static methods have is:

They cannot refer to non-static members of the class

Two or more methods in a class may have the same name as long as:

They have different parameter lists

If the following is from the method section of a UML diagram, which of the following statements is true? + equals(object2:Stock) : boolean

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

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

This is a public method with a parameter of data type double and does not return a value

The purpose of validating the results of the program is:

To determine whether the program solves the original problem

Look at the following declaration: enum Tree { OAK, MAPLE, PINE } What is the fully-qualified name of the PINE enum constant?

Tree.PINE

TRUE/FALSE: A class is not an object, but a description of an object.

True

TRUE/FALSE: A class's static methods do not operate on the fields that belong to any instance of the class.

True

TRUE/FALSE: A constructor is a method that is automatically called when an object is created.

True

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

True

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

True

TRUE/FALSE: A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.

True

TRUE/FALSE: A parameter variable's scope is the method in which the parameter is declared.

True

TRUE/FALSE: A single copy of a class's static field is shared by all instances of the class.

True

TRUE/FALSE: A sorting algorithm is a technique for scanning through an array and rearranging its contents in some specific order.

True

TRUE/FALSE: A value-returning method can return a reference to a non-primitive type.

True

TRUE/FALSE: A variable's scope is the part of the program that has access to the variable.

True

TRUE/FALSE: Although the dollar sign is a legal identifier character, you should not use it because it is normally used for special purposes.

True

TRUE/FALSE: An ArrayList object automatically expands in size to accommodate the items stored in it.

True

TRUE/FALSE: An access specifier indicates how the class may be accessed.

True

TRUE/FALSE: An enumerated data type is actually a special type of class.

True

TRUE/FALSE: 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

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

True

TRUE/FALSE: An object can store data.

True

TRUE/FALSE: Any items typed on the command-line, separated by space, after the name of the class are considered to be one or more arguments that are to be passed into the main method.

True

TRUE/FALSE: Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.

True

TRUE/FALSE: Application software refers to programs that make the computer useful to the user.

True

TRUE/FALSE: Because the && operator performs short-circuit evaluation, your boolean expression will usually execute faster if the subexpression that is most likely false is on the left of the && operator.

True

TRUE/FALSE: Because the || operator performs short-circuit evaluation, your boolean expression will generally be evaluated faster if the subexpression that is most likely to be true is on the left.

True

TRUE/FALSE: Both instance fields and instance methods are associated with a specific instance of a class, and they cannot be used until an instance of the class is created.

True

TRUE/FALSE: Constants, variables, and the values of expressions may be passed as arguments to a method.

True

TRUE/FALSE: Declaring an array reference variable does not create an array.

True

TRUE/FALSE: Each byte is assigned a unique number known as an address.

True

TRUE/FALSE: Encapsulation refers to the combining of data and code into a single object.

True

TRUE/FALSE: Enum constants have a toString method.

True

TRUE/FALSE: 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

TRUE/FALSE: If the compiler encounters a statement that uses a variable before the variable is declared, an error will result.

True

TRUE/FALSE: 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

TRUE/FALSE: If you write a toString method to display the contents of an object, object1, for a class, Class1, then the following two statements are equivalent: System.out.println(object1); System.out.println(object1.toString());

True

TRUE/FALSE: In a switch statement, each of the case values must be unique.

True

TRUE/FALSE: Instance methods do not have the key word static in their headers.

True

TRUE/FALSE: Java does not limit the number of dimensions that an array may have.

True

TRUE/FALSE: Java provides a set of simple unary operators designed just for incrementing and decrementing variables.

True

TRUE/FALSE: Logical errors are mistakes that cause the program to produce erroneous results.

True

TRUE/FALSE: Methods are commonly used to break a problem into small manageable pieces.

True

TRUE/FALSE: Named constants are initialized with a value, that value cannot be changed during the execution of the program.

True

TRUE/FALSE: No statement outside the method in which a parameter variable is declared can access the parameter by its name.

True

TRUE/FALSE: Objects in an array are accessed with subscripts, just like any other data type in an array

True

TRUE/FALSE: Once an array is created, its size cannot be changed.

True

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

True

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

True

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

True

TRUE/FALSE: The String[] args parameter in the main method header allows the program to receive arguments from the operating system command-line.

True

TRUE/FALSE: The computer is a tool used by so many professions that it cannot be easily categorized.

True

TRUE/FALSE: The do-while loop must be terminated with a semicolon.

True

TRUE/FALSE: The expression in a return statement can be any expression that has a value.

True

TRUE/FALSE: The if/else statement will execute one group of statements if its boolean expression is true or another group if its boolean expression is false.

True

TRUE/FALSE: The java.lang package is automatically imported into all Java programs.

True

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

True

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

True

TRUE/FALSE: The while loop has two important parts: (1) a boolean expression that is tested for a true or false value, and (2) a statement or block of statements that is repeated as long as the expression is true.

True

TRUE/FALSE: To compare the contents of two arrays, you must compare the elements of the two arrays.

True

TRUE/FALSE: Two general categories of methods are void methods and value returning methods.

True

TRUE/FALSE: Unicode is an international encoding system that is extensive enough to represent ALL the characters of ALL the world's alphabets.

True

TRUE/FALSE: When an array of objects is declared, but not initialized, the array values are set to null.

True

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

True

TRUE/FALSE: When an object reference is passed to a method, the method may change the values in the object.

True

TRUE/FALSE: When an object's internal data is hidden from outside code and access to that data is restricted to the object's methods, the data is protected from accidental corruption.

True

TRUE/FALSE: When the continue 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.

True

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

True

TRUE/FALSE: 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

TRUE/FALSE: Without programmers, the users of computers would have no software, and without software, computers would not be able to do anything.

True

TRUE/FALSE: You can use the PrintWriter class to open a file for writing and write data to it.

True

TRUE/FALSE: You must have a return statement in a value-returning method.

True

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

True or False

This is an international coding system that is extensive enough to represent all the characters of all the world's alphabets:

Unicode

In Java, when a character is stored in memory, it is actually stored as a:

Unicode number

This type of loop allows the user to decide the number of iterations.

User controlled loop

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

This type of method performs a task and sends a value back to the code that called it.

Value-returning

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

Variable

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

Variable

In Java, ___________ must be declared before they can be used.

Variables

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

Key words are:

Words that have a special meaning in the programming language

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

Write a copy method that will make a field by field copy of object1 data members into obejct2 data members

To compare two objects in a class:

Write an equals method that will make a field by field compare of the two objects

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

Writing the code

To display the output on the next line, you can use the println method or use this escape sequence in the print method.

\n

To do a case insensitive compare which of the following could be used to test the equality of two strings, str1 and str2?

a & b *(str1.equalsIgnoreCase(str2)) & (str1.compareToIgnoreCase(str2) == 0)*

In a general sense, a method is:

a collection of statements that performs a specific task

Every Java application program must have:

a method named "main"

When an object, such as a String, is passed as an argument, it is:

actually a reference to the object that is passed

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

add

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

add

Which of the following is not a benefit derived from using methods in programming?

all of the above are benefits (problems are more easily solved, simplifies programs, & code reuse)

All @param tags in a method's documentation comment must:

appear after the general description of the method

Values stored in local variables

are lost between calls to the method in which they are declared

Enclosing a group of statements inside a set of braces creates a:

block of statements

Methods are commonly used to:

break a problem down into small manageable pieces

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?

control is returned to method C

When an argument value is passed to a method, the receiving parameter variable is:

declared in the method header inside the parentheses

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

diskOut.println("Calvin");

Given the following method header, which of the method calls would be an error? public void displayValues(double x, int y)

displayValue(a,b); // where a is a short and b is a long

Given the following method header, which of the method calls would be an error? public void displayValues(int x, int y)

displayValue(a,b); // where a is a short and b is a long

This type of loop is ideal in situations where you always want the loop to iterate at least once.

do-while loop

A declaration for an enumerated type begins with this key word:

enum

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

final

Which of the following is valid?

float w; w = 1.0*f*;

This type of loop is ideal in situations where the exact number of iterations is known.

for loop

The _________ statement is used to make simple decisions in Java.

if

Which of the following correctly tests the char variable chr to determine whether it is not equal to the character B?

if (chr != 'B')

If chr is a character variable, which of the following if statements is written correctly?

if (chr == 'a')

When using the PrintWriter class, which of the following import statements would you write near the top of your program?

import java.io.*;

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

infinite loop

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

Assume that the following method header is for a method in class A. public void displayValue(int value) Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method?

int x = 7; displayValue(x);

A sentinel value _________ and signals that there are no more values to be entered.

is a special value that cannot be mistaken as a member of the list

When an argument is passed to a method,

its value is copied into the method's parameter variable

Which of the following will run the compiled program ReadIt?

java ReadIt

The ArrayList class is in this package.

java.util

To compile a program named First, use the following command:

javac First.java

Which of the following commands will compile a program called ReadIt?

javac ReadIt.java

You should always document a method by writing comments that appear:

just before the method's definition

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

length

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

long[]

Which Scanner class method reads an int?

nextInt()

Which Scanner class method reads a String?

nextLine()

When a method tests an argument and returns a true or false value, it should return:

A boolean value

You cannot use the fully-qualified name of an enum constant for this.

A case expression

If you attempt to use a local variable before it has been given a value,

A compiler error will occur

If the this variable is used to call a constructor:

A compiler error will result, if it is not the first statement of the constructor

The whole-part relationship created by object aggregation is more often called:

A has a relationship

A runtime error is usually the result of:

A logical error

What is stored by a reference variable?

A memory address

When a method's return type is a class, what is actually returned to the calling program?

A reference to an object of that class

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

A reference to the String "ghi"

A computer program is:

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

A ragged array is:

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

RAM is usually:

A volatile type of memory, used only for temporary storage

In all but rare cases, loops must contain within themselves:

A way to terminate

Look at the following statement. import java.util.*; This is an example of:

A wildcard import

Local variables can be initialized with:

Any of the above (constants, parameter values, the results of an arithmetic operation)

A value-returning method must specify this as its return type in the method header.

Any valid data type

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

Are highly portable

Values that are sent into a method are called ____________.

Arguments

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

These operators use two operands:

Binary

Which of the following statements will create a reference, str, to the string, "Hello, world"? (1) String str = new String("Hello, world"); (2) String str = "Hello, world";

Both 1 & 2

Computer programming is:

Both an art and a science

Any method that calls a method with a throws clause in its header must:

Both handle the potential exception and have the same throws clause

An operating system can be categorized according to:

Both the number of users that can be accommodated, and the number of tasks they can perform at one time

If you are using a block of statements, don't forget to enclose all of the statements in a set of:

Braces

A block of code is enclosed in a set of:

Braces { }

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

Braces { }

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

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

public static void passArray(int [][])

Given the declaration double r;, which of the following statements is invalid?

r = 2.9X106;

This ArrayList class method deletes an item from an ArrayList.

remove

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

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

subscript

You can use this method to determine whether a file exists.

the File class's exists method

A parameter variable's scope is:

the method in which the parameter is declared

In an if/else statement, if the boolean expression is false,:

the statement or block following the else is executed

A Boolean expression is one that is either:

true or false

A flag may have the values:

true or false

The expression tested by an if statement must evaluate to:

true or false

This type of method performs a task and then terminates.

void

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()) { ... }

Which of the following are pre-test loops?

while, for

Which of the following expressions will determine whether x is less than or equal to y?

x <= y

If x has been declared an int, which of the following statements is invalid?

x = 1,000; *NO COMMAS!*


Related study sets

American History Chapter 12 Guided Readings

View Set

Chapter 29 Trauma Systems and Mechanism of Injury

View Set

English to Spanish (1) - ER, IR, and AR Verbs: Present Tense of Regular

View Set

Level 1 Antiterrorism Awareness Training (JS-US007)

View Set

Patients at Risk- HESI Case Study (Evolve)

View Set

Earth Science - ESC1000C Module 1 Quiz

View Set

Clinical Psychology- Exam 1 (PSY 406)

View Set

143 Mod 4 - Hypersensitivity Reactions (PRACTICE QUESTIONS)

View Set

#2 Prepware Test Questions A&P Math

View Set

UVM PSYS 001 Rudiger Exam 3 Spring 2020

View Set

Government - Unit 3 - Civil Liberties and Civil Rights

View Set

Chapter 20 Software Development Security

View Set