chapter 4 ( fill-in the blanks / Explanations )

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

You save text files containing Java source code using the file extension ____.

.java

If String movie = new String("West Side Story");, the value of movie.indexOf(′s′) is _____.

2

The assignment operator in Java is ____.

=

The "equal to" relational operator is ____.

==

Identify the false statement. a. Character, String, and StringBuilder are useful built-in classes for working with text data. b. A String is a simple data type that can hold text data. c. Programmers want to compare the values of Strings more frequently than they want to compare their memory addresses.

A String is a simple data type that can hold text data.

Identify the false statement. a. An application or class that instantiates objects of another prewritten class is a class client. b. A class is an instantiation of many objects. c. Objects gain their attributes and methods from their classes.

A class is an instantiation of many objects.

Identify the false statement. a. A class's instance variables override locally declared variables with the same names that are declared within the class's methods. b. You cannot declare the same variable name more than once within a block, even if a block contains other blocks. c. A variable ceases to exist, or goes out of scope, at the end of the block in which it is declared.

A class's instance variables override locally declared variables with the same names that are declared within the class's methods.

Identify the false statement. a. You can create an input dialog box using the showInputDialog() method; the method returns a String that represents a user's response. b. You can use methods from the Java classes Integer and Double when you want to convert a dialog box's returned values to numbers. c. A confirm dialog box can be created using the showConfirmDialog() method in the JOptionPane class; a confirm dialog box displays the options Accept, Reject, and Escape.

A confirm dialog box can be created using the showConfirmDialog() method in the JOptionPane class; a confirm dialog box displays the options Accept, Reject, and Escape.

Identify the false statement. a. A default constructor is one that is automatically created. b. When you write a constructor, it can be written to receive parameters or not. c. If a class's only constructor requires an argument, you must provide an argument for every object of the class that you create.

A default constructor is one that is automatically created.

Identify the false statement. a. As with integers, you can perform the mathematical operations of addition, subtraction, multiplication, and division with floating-point numbers. b. Java supports two floating-point data types: float and double. The double data type requires more memory and can hold more significant digits. c. A floating-point constant, such as 5.6, is a float by default.

A floating-point constant, such as 5.6, is a float by default.

Identify the false statement. a. A method header always contains a return type, an identifier, and a parameter list within parentheses. b. Arguments are used in method calls; they are passed to parameters in method headers. c. A class can contain any number of methods, and each method can be called any number of times.

A method header always contains a return type, an identifier, and a parameter list within parentheses.

Identify the false statement. a. When a method is declared with public access, methods in other classes can call it. b. Not all methods return a value, but every method requires a return type. c. A method header is also called an implementation.

A method header is also called an implementation.

Identify the false statement. a. Any class can contain an unlimited number of methods. b. A method is usually written within another method. c. During one program execution, a method might be called any number of times.

A method is usually written within another method.

Identify the false statement. a. The return type for a method can be any type used in Java, including int, double, and void. b. You cannot place a method within another method, but you can call a method from within another method. c. A method's declared return type must match the type of the value used in the parameter list.

A method's declared return type must match the type of the value used in the parameter list.

The Java ____ contains information about how to use every prewritten Java class, including lists of all the methods you can use with the classes.

API

Identify the false statement. a. Syntax errors are compile-time errors. b. When you compile a class, you create a new file with the same name as the original file but with a .class extension. c. After you write and save an application, you can compile the bytecode to create source code.

After you write and save an application, you can compile the bytecode to create source code.

Identify the false statement. a. A variable declaration is a statement that reserves a named memory location and includes a data type, an identifier, an optional assignment operator and assigned value, and an ending semicolon. b. An item's data type determines what legal identifiers can be used to describe variables and whether the variables can occupy memory. c. A variable is a named memory location that you can use to store a value; it can hold only one value at a time, but the value it holds can change.

An item's data type determines what legal identifiers can be used to describe variables and whether the variables can occupy memory.

Identify the false statement. a. Assume that myName is a String defined as "molly". The value of myName.indexOf('M') is -1. b. Assume that myName is a String defined as "molly". The value of myName.toUpperCase() is "Molly". c. Assume that myName is a String defined as "molly". The value of myName.length() is "5".

Assume that myName is a String defined as "molly". The value of myName.toUpperCase() is "Molly".

____ describes the relationship between classes when an object of one class is a data field within another class.

Composition

Identify the false statement. a. A nested class resides within another class. b. Exposition describes the relationship between classes when an object of one class is a data field within another class. c. When you use an object as a data member of another object, you must remember to supply values for the contained object if it has no default constructor.

Exposition describes the relationship between classes when an object of one class is a data field within another class.

Identify the false statement. a. When you write a constructor, it must have the same name as the class it constructs, and it cannot have a return type. b. In Java, you cannot write a default constructor; it must be supplied for you automatically. c. The automatically supplied default constructor sets all numeric fields to 0, character fields to Unicode '\u0000', Boolean fields to false, and fields that are object references to null.

In Java, you cannot write a default constructor; it must be supplied for you automatically.

Identify the false statement. a. In the method header public static void main(String[] args), the word static means that a method is accessible and usable, even though no objects of the class exist. b. In the method header public static void main(String[] args), the word void means that the main() method is an empty method. c. In the method header public static void main(String[] args), the word public is an access specifier.

In the method header public static void main(String[] args), the word void means that the main() method is an empty method.

Identify the false statement. a. When you overload Java methods, you write multiple methods with a shared name. b. When you overload Java methods, the methods are called using different arguments. c. Instead of overloading methods, it is preferable to write methods with unique identifiers.

Instead of overloading methods, it is preferable to write methods with unique identifiers.

Java does not execute instructions on a computer directly, but rather on the ____.

Java Virtual Machine

Identify the false statement. a. Java packages are available only if you explicitly name them within your program. b. The creators of Java have produced hundreds of classes for you to use in your programs. c. The implicitly imported java.lang package contains fundamental Java classes.

Java packages are available only if you explicitly name them within your program.

Identify the false statement. a. A Boolean variable can hold only one of two values—true or false. b. Java supports six relational operators that are used to make comparisons: =, <, >, =<, =>, and =! c. An expression that contains a relational operator has a Boolean value.

Java supports six relational operators that are used to make comparisons: =, <, >, =<, =>, and =!

Identify the false statement. a. Java programs that are embedded in a Web page are called applets, while stand-alone programs are called Java applications. b. Java was developed to be architecturally neutral, which means that anyone can build an application without extensive study. c. After you write a Java program, the compiler converts the source code into a binary program of bytecode.

Java was developed to be architecturally neutral, which means that anyone can build an application without extensive study.

Identify the false statement. a. Javadoc comments begin with a forward slash and two asterisks ( /** ) and end with an asterisk and a forward slash ( */ ); they are used to generate documentation with a program named javadoc. b. Line comments start with two forward slashes ( // ) and end with two backslashes ( \\ ); they can extend across as many lines as needed. c. Block comments start with a forward slash and an asterisk ( /* ) and end with an asterisk and a forward slash ( */ ); they can extend across as many lines as needed.

Line comments start with two forward slashes ( // ) and end with two backslashes ( \\ ); they can extend across as many lines as needed.

In each Two Truths and a Lie, two of the given statements are true, and one is false. Identify the false statement. a. Unlike a low-level programming language, a high-level programming language allows you to use a vocabulary of reasonable terms instead of the sequences of on and off switches that perform the corresponding tasks. b. Logic errors are fairly easy to find because the software that translates a program finds all the logic errors for you. c. A syntax error occurs when you misuse a language; locating and repairing all syntax errors is part of the process of debugging a program.

Logic errors are fairly easy to find because the software that translates a program finds all the logic errors for you.

Identify the false statement. a. Methods declared as static receive a this reference that contains a reference to the object associated with them. b. A final static field's value is shared by every object of a class. c. Methods declared as static are called class methods.

Methods declared as static receive a this reference that contains a reference to the object associated with them.

Identify the false statement. a. Polymorphism is the ability to create classes that share the attributes and methods of existing classes, but with more specific features. b. An instance of a class is a created object that possesses the attributes and methods described in the class definition. c. Encapsulation protects data by hiding it within an object.

Polymorphism is the ability to create classes that share the attributes and methods of existing classes, but with more specific features.

Identify the false statement. a. Static methods are instance methods. b. The keyword static is used with classwide methods, but not for methods that "belong" to objects. c. When you create a class from which objects will be instantiated, most methods are nonstatic because they are associated with individual objects.

Static methods are instance methods.

The method parseInt() converts a(n) _____.

String to an integer

For an alternative to the String class, and so you can change a String's contents, you can use _____.

StringBuilder

If a class is named Student, the class constructor name is____.

Student()

To create interactive programs that accept input from a user, you can use ____.

System.in

Identify the false statement. a. System.in refers to the standard input device, which normally is the keyboard. b. When a user types data followed by the Enter key, the Enter key character is left in the keyboard buffer after Scanner class methods retrieve the other keystrokes. c. System.in is more flexible than System.out because it can read all the basic Java data types.

System.in is more flexible than System.out because it can read all the basic Java data types.

Identify the false statement. a. The Character class method isLowerCase() returns the lowercase version of any uppercase character. b. Character is a class, but char is a simple data type. c. If a char variable holds the Unicode value for the Tab key, isWhitespace() would be true and isLetterOrDigit() would be false.

The Character class method isLowerCase() returns the lowercase version of any uppercase character.

Identify the false statement. a. In Java, operator precedence dictates that multiplication, division, and remainder always take place prior to addition or subtraction in an expression. b. The arithmetic operators are examples of unary operators, which are so named because they perform one operation at a time. c. Floating-point arithmetic might produce imprecise results.

The arithmetic operators are examples of unary operators, which are so named because they perform one operation at a time.

Identify the false statement. a. Usually, you want each instantiation of a class to have its own nonstatic data fields, but each object does not need its own copy of most methods. b. When you use a nonstatic method, the compiler accesses the correct object's field because you implicitly pass an object reference to the method. c. The this reference is supplied automatically in classes; you cannot use it explicitly.

The this reference is supplied automatically in classes; you cannot use it explicitly.

Identify the false statement. a. To compile a file named MyProgram.java, you type java MyProgram, but to execute the program you type java MyProgram.java. b. When you compile a program, sometimes one error in syntax causes multiple error messages. c. In Java, if a class is public, you must save the class in a file with exactly the same name and a .java extension.

To compile a file named MyProgram.java, you type java MyProgram, but to execute the program you type java MyProgram.java.

Identify the false statement. a. When you compare Strings with the == operator, you are comparing their memory addresses, not their values. b. To create a String object, you must use the keyword new and explicitly call the class constructor. c. When you compare Strings with the equals() method, you are comparing their values, not their memory addresses.

To create a String object, you must use the keyword new and explicitly call the class constructor.

Identify the false statement. a. An escape sequence always begins with a backslash followed by a character; the pair represents a single character. b. To store a string of characters, you use a data structure called a Text; string constants are written between parentheses. c. You use the char data type to hold any single character; you place constant character values within single quotation marks.

To store a string of characters, you use a data structure called a Text; string constants are written between parentheses.

Which of the following is not an option that can be displayed with a confirm dialog box? a. Yes b. Try Again c. Cancel d. No

Try Again

Identify the false statement. a. When you declare a primitive variable or instantiate an object from a class, you provide both a type and an identifier. b. Unlike a primitive variable, an instantiated object cannot be passed into or returned from a method. c. The address of an instantiated object can be assigned to a declared reference of the same type.

Unlike a primitive variable, an instantiated object cannot be passed into or returned from a method.

Identify the false statement. a. When it is part of the same program as void myMethod (int age, String name), the following method would be ambiguous: String myMethod (int zipCode, String address) b. When it is part of the same program as void myMethod (int age, String name), the following method would be ambiguous: void myMethod (int x, String y) c. When it is part of the same program as void myMethod (int age, String name), the following method would be ambiguous: void myMethod (String name, int age)

When it is part of the same program as void myMethod (int age, String name), the following method would be ambiguous: void myMethod (String name, int age)

Identify the false statement. a. When you create a String, you have the option of omitting the keyword new, but when you initialize a StringBuilder object, you must use the keyword new, the constructor name, and an initializing value between the constructor's parentheses. b. When you create a StringBuilder object with an initial value of "Juan", its capacity is 16. c. If a StringBuilder named myAddress contains "817", then myAddress.append(" Maple Lane"); alters myAddress to contain "817 Maple Lane".

When you create a StringBuilder object with an initial value of "Juan", its capacity is 16.

Identify the false statement. a. An object name is a reference; it holds a memory address. b. When you declare an object, you give it a name and set aside enough memory for the object to be stored. c. When you don't write a constructor for a class, Java creates one for you; the name of the constructor is always the same as the name of its class.

When you declare an object, you give it a name and set aside enough memory for the object to be stored.

Identify the false statement. a. A class header contains an optional access specifier, the keyword class, and an Identifier. b. When you instantiate objects, each has its own copy of each static data field in the class. c. Most fields in a class are private, and most methods are public.

When you instantiate objects, each has its own copy of each static data field in the class.

Identify the false statement. a. Summing a double, int, and float results in a double. b. You can explicitly override the unifying type imposed by Java by performing a type cast; type casting forces a value of one data type to be used as a value of another type. c. When you perform arithmetic operations with operands of unlike types, you must make an explicit conversion to a unifying type.

When you perform arithmetic operations with operands of unlike types, you must make an explicit conversion to a unifying type.

Identify the false statement. a. A variable of type int can hold any whole number value from approximately negative two billion to positive two billion. b. You can use the data types byte or short to hold larger values than can be accommodated by an int. c. When you assign a value to an int variable, you do not type any commas; you type only digits and an optional plus or minus sign to indicate a positive or negative integer.

You can use the data types byte or short to hold larger values than can be accommodated by an int.

Identify the false statement. a. A dialog box is a GUI object resembling a window in which you can place messages you want to display. b. You use an append statement when you want to access a built-in Java class that is contained in a group of classes called a package. c. Different methods can require different numbers of arguments.

You use an append statement when you want to access a built-in Java class that is contained in a group of classes called a package.

The method public static boolean testValue(int response) returns ____.

a boolean value

Which of the following is a correct call to a method declared as public static void aMethod(char code)? a. void aMethod(); b. aMethod('Q'); c. void aMethod('V'); d. aMethod(char 'M');

aMethod('Q');

A(n) ____ data type is a type whose implementation is hidden and accessed through its public methods.

abstract

Using a method name to contain or encapsulate a series of statements is an example of ____.

abstraction

The toString() method converts a(n) _____ to a String. a. char b. float c. int d. all of the above

all of the above

Which of the following is not a type of nested class? a. inner b. local c. anonymous d. ambiguous

ambiguous

Which of the following elements is not required in a variable declaration?

an assigned value

An escape sequence always begins with a(n) ____.

backslash

Assuming you have declared balance to be a variable of type int, which of the following is a valid assignment statement in Java? a. balance = 9,000; b. balance = 9000; c. balance = 9000.5; d. balance = '9000';

balance = 9000;

The code between a pair of curly braces in a method is a ____.

block

The actual length of the _____ is the capacity of the StringBuilder object.

buffer

Which of the following data types can store a value in the least amount of memory?

byte

A constructor ____ overloaded. a. must be b. cannot be c. can be d. is always automaticall

can be

A constructor ____ parameters. a. must receive b. cannot receive c. can receive a maximum of 10 d. can receive

can receive

Which assignment is correct in Java? a. char aChar == 'W'; b. char aChar = 5.5; c. char aChar = '*'; d. char aChar = "W";

char aChar = '*';

Methods that do not have a this reference because they have no object associated with them are called ____ methods.

class

A program or class that instantiates objects of another prewritten class is a(n) ____.

class client

Variables that are shared by every instantiation of a class are ____.

class variables

Non-executing program statements that provide documentation are called program ____.

comments

After you write and save a Java application file, you ____ and then ____ it.

compile, interpret

A ____ translates high-level language statements into machine code.

compiler

Joining Strings with a '+' is called _____.

concatenation

When data cannot be changed while a program is running, the data is ____.

constant

Which of the following is a floating-point data type that Java supports? a. bit b. double c. single d. scientific

double

A(n) ____ is a data type that consists of a list of values.

enumeration

The method that determines whether two String objects are equivalent, regardless of case, is _____.

equalsIgnoreCase()

The String class replace() method replaces _____.

every occurrence of a character in a String with another character

Objects contain methods and data items, which are also known as ____.

fields

If you attempt to add a float, an int, and a byte, the result will be a(n) ____.

float

A String is an example of an object that can't be changed, also known as _____.

immutable

The term that programmers use to describe objects that cannot be changed is _____.

immutable

When you perform arithmetic with values of diverse types, Java ____.

implicitly converts the values to a unifying type

Using a(n) ____ statement, Java allows you to access built-in classes that are contained in a group of classes called a package.

import

The principle used in creating private access is sometimes called ____ and is an important component of object-oriented programs.

information hiding

An object is a(n) ____ of a class, or one tangible example of a class.

instantiation

The method with the declaration public static int aMethod() has a method type of ____.

int

The difference between int and Integer is _____.

int is a primitive type; Integer is a class

The remainder operator ____.

is also called the modulus operator

The first position in a String _____.

is position zero

The command to execute a compiled Java application is ____.

java

The Character class is defined in _____.

java.lang

The ____ package is implicitly imported into every program you write.

java.lang

Java supports three types of comments: ____, ____, and javadoc.

line, block

A sequence of characters enclosed within double quotation marks is a _____.

literal string

The most basic circuitry-level computer language, which consists of on and off switches, is ____.

machine language

A(n) ____ is a program module that contains a series of statements that carry out a task.

method

If a class's only constructor requires an argument, you ____ for every object of the class that you create.

must provide an argument

Methods that set or change field values are called ____ methods.

mutator

Nonambiguous, overloaded methods must have the same ____.

name

When a block exists within another block, the blocks are ____.

nested

Java is architecturally ____.

neutral

To allocate the needed memory for an object, you must use the ____ operator.

new

To create a String object, you can use the keyword _____ before the constructor call, but you are not required to use this format.

new

Unlike when you create a String, when you create a StringBuilder, you must use the keyword _____.

new

A String variable that does not yet hold a memory address is known as a(n) _____ String.

null

If you use the automatically-supplied default constructor when you create an object, ____.

numeric fields are set to 0 (zero)

An instance of a class is a(n) ____.

object

Envisioning program components as objects that are similar to concrete objects in the real world is the hallmark of ____.

object-oriented programming

If you create a class that contains one method and then instantiate two objects, you usually store ____ for use with the objects.

one copy of the method

In Java, ____ means writing multiple methods in the same scope that have the same name but different parameter lists.

overloading

Java classes are stored in a folder or ____.

package

All method declarations contain ____.

parentheses

Arguments to methods always appear within ____.

parentheses

Most class data fields are ____.

private

The individual operations used in a computer program are often grouped into logical units called ____.

procedures

When you run your program you don't see evidence of the changes you just made to it. You realize that you forgot to ____ the program.

recompile

A String variable name is a _____ which is a variable that holds a memory address.

reference

A(n) ____ statement causes a method to end and the program's logic to return to the calling method.

return

Which of the following could be the last legally coded line of a method declared as public static int getVal(double sum)? a. return 2.3; b. Any of these could be the last coded line of the method. c. return; d. return 77;

return 77;

Which of the following statements determines the square root of a number and assigns it to the variable s? a. s = Math.sqrt(number); b. s = sqrt(number); c. number = Math.sqrt(s); d. number = sqrt(s);

s = Math.sqrt(number);

Which of the following is not a primitive data type in Java? a. byte b. int c. boolean d. sector

sector

All Java programming statements must end with a ____.

semicolon

A method is declared as public static void showResults(double d, int i). Which of the following is a correct method call? a. Two of these are correct b. showResults(4, 99.7); c. showResults(12.2, 67); d. showResults(double d, int i);

showResults(12.2, 67);

A method's ____ is the combination of the method name and the number, types, and order of arguments.

signature

The compiler determines which version of a method to call by the method's ____.

signature

The term ____ refers to the mathematical accuracy of a value.

significant digits

The values of an object's attributes also are known as its ____.

state

The method that extracts a string from within another string is _____.

substring()

According to the rules of operator precedence, when division occurs in the same arithmetic statement as ____, the division operation always takes place first.

subtraction

The rules of a programming language constitute its ____.

syntax

A boolean variable can hold ____.

the value true or false

If you declare a variable as an instance variable within a class and you declare and use the same variable name within a method of the class, then within the method ____.

the variable used inside the method takes precedence

The reference to an object that is passed to any object's nonstatic method is called the ____.

this reference

Which of the following is not a commonly used Character method? a. toLowerCase() b. isDigit() c. toUpper() d. isWhiteSpace()

toUpper()

The Scanner class contains methods that retrieve values, referred to as ____, from an input device.

tokens

You use a ____ to explicitly override an implicit type.

type cast

Named computer memory locations are called ____.

variables

If a method is written to receive a double parameter, and you pass an integer to the method, then the method will ____.

work correctly; the integer will be promoted to a double


संबंधित स्टडी सेट्स

Chapter 3 Test Review Part 2-Spanish

View Set

Unit 20. Vocab. A. Choose the correct word.

View Set

Ap Human 3A Quiz (from Barron's 9th Edition)

View Set

ATI Introduction to Health Assessment Test

View Set

Chapter 16 reading quiz questions

View Set

Words of similar meaning - Adjectives

View Set

ALL Chapters 1-5 Strategic Management Exam Practice

View Set

Ch 2 Test Review Criminal Justice Molenar

View Set