Section 1

Preview this deck

Java performs automatic garbage collection. True or False?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

1

Favorites

0

Last updated

6 years ago

Date created

Mar 14, 2020

Cards (246)

Section 1

(50 cards)

Java performs automatic garbage collection. True or False?

Front

True

Back

How do you create a single comment?

Front

//

Back

What is a software development environment?

Front

is a set of tools used to create, organize, modify, test, and debug a program. It is software that helps you develop software.

Back

Java is an object-oriented programming language. True or False?

Front

True

Back

What is the syntax of a language?

Front

determines how words and symbols can be put together in valid ways.

Back

The end-of-line block style aligns opening and closing braces vertically. True or False?

Front

False

Back

What is syntax coloring? A. Displaying each method of a program in a different color B. Wrapping program output in colored boxes C. Displaying program output in particular colors D. Showing certain elements of program code in different colors

Front

D. Showing certain elements of program code in different colors

Back

What is system.out sometimes referred to as?

Front

The console window

Back

The Java Development Kit (JDK) is an example of an integrated development environment (IDE). True or False?

Front

False

Back

What software tool is used to translate Java source code into Java bytecode? A. editor B. interpreter C. Java Virtual Machine (JVM) D. compiler

Front

D. Compiler

Back

What is an editor, a complier, and interpreter?

Front

You modify and edit the code in the editor, the complier complies the code to make sure there are no errors, and an interpreter helps run the program.

Back

How do you create a multi-line comment?

Front

/* begins with */ ends with

Back

When does a logic error occur?

Front

when a program doesn't produce the desired results.

Back

Java source code cannot be executed directly by a computer. True or False?

Front

True

Back

Java is a general-purpose programming language. True or False?

Front

True

Back

In a programming language, a syntactically valid statement has only one meaning. True or False?

Front

True

Back

What is the semantics of a language?

Front

provide the meaning.

Back

Which of the following statements is true? A. The body of a Java class is enclosed in square brackets: [ ] B. Blank lines in a Java program will be displayed in the output. C. The body of a Java method is enclosed in curly braces: { } D. The println method is called through the System.in object.

Front

C. The body of a java method is enclosed in curly braces { }

Back

What are three errors that you will determine when using java?

Front

Syntax errors, Runtime errors, Logic errors

Back

When does a runtime error occur?

Front

while the program is executing and causes it to terminate abnormally. Ex: dividing by zero

Back

When it comes to programming style, consistency is crucial. True or False?

Front

True

Back

The main method of a Java program must have which of the following method headers? A. private abstract void main() B. public static int main() C. public abstract void main(String[] args) D. public static void main(String[] args)

Front

D. Public static void main (String[] args)

Back

What is an overloaded operator?

Front

An operator that performs multiple types of operations

Back

What is the "+" symbol used for?

Front

To perform string concatenation

Back

A comment in a Java program is ignored by the compiler. True or False?

Front

True

Back

What is a natural language? A. A programming language that uses English-like terms. B. A programming language that feels natural to the user. C. A language used to describe algorithms. D. A language that humans use to communicate, such as English.

Front

D. A language that humans use to communicate, such as English

Back

The slogan "Write Once, Run Anywhere" is used to promote what? A. The Java Development Kit (JDK) B. Java's robust error handling C. Java's cross-platform benefits D. The Eclipse development environment

Front

C. Java's cross-platform benefits

Back

What output does the following code produce? System.out.print("Total: " + 100 + 20);

Front

Total: 10020

Back

What issue must be addressed when printing a long character string? A. The println method has a maximum number of characters it can accept. B. The string must be subdivided into sections of 50 characters or less. C. The print method cannot print character strings. D. A character string literal cannot span across multiple lines.

Front

D. A character string literal cannot span across multiple lines

Back

What is method overloading?

Front

A technique that allows a method to accept different parameters

Back

The Java Virtual Machine is software. True or False?

Front

True

Back

Java was created by a development team led by James Gosling. True or False?

Front

True

Back

Sun Microsystems was purchased by?

Front

Oracle - 2010

Back

What does the following line of code do? System.out.println("Your age in 7 years: " + (19 + 7)); A. Prints the string, moves to a new line, then prints the sum of 19 and 7. B. Prints the string, then adds the numbers and prints the result. C. Adds 19 to 7, concatenates the result to the string, then prints it. D. Concatenates 19 to the string, then concatenates 7 to the string, then prints it.

Front

C. Adds 19 to 7, concatenates the result to the string, then prints it.

Back

What were some of the features promoted by JAVA?

Front

Platform Independence, Applets, Object Orientation, Garbage Collection

Back

What result is printed by the following code? System.out.println(15 + 30);

Front

45

Back

What is the main method?

Front

Is a special method that's called automatically when a Java program is executed

Back

What is testing?

Front

is the process of evaluating your program with the goal of discovering errors.

Back

A typical Java compiler produces which type of output? A. Java source code B. Unicode C. JDK code D. Java bytecode

Front

D. Java Bytecode

Back

What is the method header?

Front

The first line of the method ex: public static void

Back

Which of the following statements is true? A. The println statement is a call to a method. B. The println statement sends text output to the editor. C. A println statement must be the first statement in a Java program. D. The name println is pronounced "print long."

Front

A. The println statement is a call to method

Back

What is a program specification?

Front

is a set of requirements that must be satisfied by a program

Back

What is the difference between print and println?

Front

Print prints the statement on the same line, and println completely prints a statement to another line

Back

What output does the following code produce? System.out.print("apple"); System.out.println("banana"); System.out.println("orange");

Front

Applebanana orange

Back

Java programs cannot be run on a web page. True or False?

Front

False

Back

What is debugging?

Front

When you determine you have an error and must figure out how to fix your error

Back

What is the syntax of a language? A. The rules that determine how words and symbols can be combined. B. A specification that lists a program's requirements. C. A list of errors that can occur in a program. D. The meaning of a language element.

Front

A. The rules that determine how words and symbols can be combined.

Back

A multi-line Java comment begins with a double slash (//). True or False?

Front

False

Back

What does the term case sensitive mean? A. The difference between upper-case and lower-case letters matters. B. A Java program is enclosed in, and executed relative to, a program case. C. Each case of a Java println statement must be unique. D. A Java program must be encased in a human-readable comment.

Front

A. The difference between upper-case and lower-case letter matters

Back

Java throws an ________ when a runtime error occurs?

Front

exception

Back

Section 2

(50 cards)

What is an identifier?

Front

A name you make up when writing a program ex: names of variables, methods, and classes

Back

The byte data type represents a true or false value. True or False?

Front

False

Back

Which of the following will produce a runtime error? A. Misspelling a word in the output. B. Dividing by zero. C. Computing the wrong answer. D. Omitting a necessary semicolon in a program.

Front

B. Dividing by zero

Back

What is a programming convention?

Front

A convention is a guideline that programmers have agreed to follow regarding names, spacing, and other issues related to program style. Conventions are not part of the official language, but they make the code much easier to read

Back

What is the input and output?

Front

Input: keyboard, mouse, joystick Output: screen, printer, speakers Both: Pendrive, CD, Webcam, fax, touch screen

Back

What are the 5 parts of the von Neumann architecture?

Front

control unit, arithmetic logic unit, memory, input and output.

Back

Classes in the Java API are organized into packages. True or False?

Front

True

Back

Which of the following is NOT a valid Java identifier? A. place1 B. 1stPlace C. first_place D. FIRST_PLACE

Front

B. 1stPlace - cannot begin with a number

Back

The float and long data types both represent floating-point values. True or False?

Front

False - float and double represent floating

Back

What package is the string apart of?

Front

Java.lang

Back

What is a program?

Front

A step by step series of instructions that tells the hardware what to do

Back

What is the arithmetic logic unit?

Front

is the brain of a computer system. Within its main processor called the central processing unit (CPU), it performs mathematical, logic and comparison operations.

Back

What package is the random and scanner apart of?

Front

java.util

Back

What is the Java API? A. A large library of classes B. A set of data conversion techniques C. A set of program testing routines D. A graphical interface to a Java program

Front

A. a large library of classes

Back

A numeric literal is an explicit number used in a program. True or False?

Front

True

Back

What does a variable declaration do?

Front

It establishes the variable's name and the data type ex: int count

Back

Internally, an upper-case letter ('A') is treated the same as its lower-case version ('a'). True or False?

Front

False

Back

Which of the following is NOT a Java primitive type? A. boolean B. double C. int D. number

Front

D. number

Back

Characters in Java are represented using the ASCII character set. True or False?

Front

False - uses unicode

Back

The term hertz can be used to describe a computer's speed. True or False?

Front

True

Back

A program that runs without generating a runtime error will produce correct results. True or False?

Front

False - could produce incorrect results

Back

What is debugging? A. The process of evaluating a program to discover errors. B. The process of translating a program into a valid executable version. C. The process of mapping programming language syntax to semantics. D. The process of determining the root cause of a problem and fixing it.

Front

D. The process of determining the root cause of a problem and fixing it

Back

The int and short data types both represent integers. True or False?

Front

True

Back

What are the 8 primitive data types?

Front

4 integer: byte, short, int, long, 2 floating: float, double 1 character: char 1 boolean: boolean (True or False)

Back

Numeric primitive values in Java are signed. True or False?

Front

True - either positive or negative

Back

What is computer architecture?

Front

the design of a computer system that shows how all of the hardware elements are hooked together and exchange information via a set of wires called a bus.

Back

What does an import statement do? A. Puts a class into a package. B. Reads data from an input source. C. Merges the separate elements of a program into one unit. D. Identifies the package in which a class can be found.

Front

D. Identifies the package in which a class can be found. - An import statement helps the compiler resolve the references you make to a class in your code.

Back

What does a double and floating hold for size?

Front

float = 32 double = 64

Back

What is the control unit?

Front

is the heart of a computer system. It orchestrates the execution of computer programs by managing the cycle which controls the execution of instructions. It also coordinates the interactions of other components of the system.

Back

Using the Java API in a program is a rare occurrence. True or False?

Front

False

Back

What is an assignment statement and assignment operator?

Front

Assignment operator is = Assignment statement stores a value in a variable ex: length = 42; variable = expression

Back

Which of the following identifiers follows the convention for naming Java variables? A. TotalValue B. total_value C. totalValue D. TOTALVALUE

Front

C. totalValue

Back

What are the steps in the instruction cycle?

Front

1. Fetch 2. Decode 3. Execute 4. Store

Back

What is a variable?

Front

a name used to refer to a data value or an object.

Back

What is the standard class library for Java called?

Front

Java API - application programming interface

Back

John von Neumann is known for the observation that the number of transistors that fit on a computer chip doubles every year. True or False?

Front

False

Back

What size can a byte, short, int, and long hold?

Front

Byte = 8 Short = 16 Int = 32 Long = 64

Back

There are exactly six primitive data types in Java. True or False?

Front

False - 8

Back

What components are part of the von Neumann model? A. control unit, arithmetic logic unit, memory, input and output B. flash memory, hard disks and network storage C. keyboard, mouse, touchscreen and joystick D. fetch, decode, execute and store E. hardware, software, data and programs

Front

A. control unit, arithmetic logic unit, memory, input and output

Back

The assignment operator has higher precedence than the arithmetic operators. True or False?

Front

False

Back

Which of the following is NOT a valid variable declaration in Java? A. double total; B. String greeting = "Hi there!"; C. float height = 20.0, length = 30.5; D. int first = true;

Front

D. int first = true;

Back

If the compiler produces errors, it will not generate an executable version of the program. True or False?

Front

True

Back

Full documentation about the Java API can be found online. True or False?

Front

True

Back

A widening conversion converts a primitive value to a larger primitive type. True or False?

Front

True

Back

Which of the following will produce a syntax error? A. Misspelling a word in the output. B. Computing the wrong answer. C. Dividing by zero. D. Omitting a necessary semicolon in a program.

Front

D. Omitting a necessary semicolon in a program

Back

What is the memory unit?

Front

is made up of a main data storage area called random access memory (RAM) and other memory components that are responsible for storing and retrieving program data and instructions.

Back

Information in secondary memory is lost if the power is turned off. True or False?

Front

False - Secondary memory like a hard drive is nonvolitile, meaning it retains its information when power is lost.

Back

A type cast is used to change the data type of a variable. True or False?

Front

False

Back

What are the two categories of data types in Java? A. integers and character strings B. objects and character strings C. primitive data and object references D. numbers and characters

Front

C. primitive data and object references

Back

What does hardware refer to?

Front

refers to the physical components, such as the monitor, mouse, keyboard, disk drives and system circuit boards which include the main processor, memory, graphics processor, and sound card

Back

Section 3

(50 cards)

A constant is created using the final modifier. True or False?

Front

True - The value of a variable declared with the final modifier cannot be changed.

Back

Which line of code is equivalent to the following? depth += 50 * offset; A. depth = depth + (50 * offset); B. offset = depth + (50 * offset); C. offset = depth + 50 * offset; D. depth = (depth + 50) * offset;

Front

A. depth = depth + (50 * offset);

Back

What value is assigned to the integer variable num by the following statement if the current value of num is 4? num = num * 2; A. 2 B. 4 C. 6 D. 8

Front

D. 8

Back

The field width in a printf format specifier determines the total number of characters to be used to print the value. True or False

Front

True

Back

If the current value of the integer variable num1 is 2 and the current value of the double variable num2 is 3.0, what value will be stored in num2 after the following line of code is executed? num2 /= num1 * num2; A. 0.0 B. 0.5 C. 1.0 D. 1.5

Front

B. 0.5

Back

What does the increment operator do?

Front

++ increments by 1

Back

If either or both operands to the division operator (/) are floating-point values, then the result will be a floating-point value. True or False?

Front

True - And if both are integers, it performs integer division.

Back

If the current value of the integer variable num is 4, what value will be stored in num after the following line of code is executed? num += 2; A. 2 B. 4 C. 6 D. 8

Front

C. 6

Back

The Math.PI constant represents pi to 15 decimal places. True or False

Front

True

Back

A printf format specifier of %.3f will print a floating-point value truncated to 3 decimal places. True or False

Front

False -The value is rounded, not truncated.

Back

What is the result of the expression Math.max(6, 17)? A. 0 B. 6 C. 17 D. 23

Front

C. 17

Back

What will happen if the variable total holds 5 when the following code is executed? if (total > 8) System.out.println("collywobbles"); A. The word collywobbles is not printed and an exception is thrown. B. The word collywobbles is not printed, but an error message is. C. The word collywobbles is printed and then processing continues. D. The word collywobbles is not printed and processing continues.

Front

D.The word collywobbles is not printed and processing continues.

Back

The first parameter to the printf method is the format string. True or False

Front

True

Back

When is an if statement used?

Front

used to decide which programming statement to execute next. That is, it determines if it will execute the statement(s) in the body of the if statement, or if it will skip it and continue

Back

What output is printed by the following code if it is executed when appetizer is 3 and entree is 12? if (appetizer > 1) if (entree < 7) System.out.println("ketchup"); else System.out.println("mustard"); else if (appetizer < 0) System.out.println("mayonnaise"); else System.out.println("relish"); A. ketchup B. mustard C. mayonnaise D. relish E. salsa F. None of the above

Front

B. Mustard

Back

Why do we use constants?

Front

1. Constants convey more meaning than literals. 2. They prevent inadvertent programming errors. 3. They make maintenance tasks easier and safer.

Back

If both operands to the remainder operator (%) are positive, a divisor of n will produce a result in the range 1 to n. True or False?

Front

False - It will produce a result in the range 0 to n-1.

Back

What is a boolean expression?

Front

True or false expression that evaluates

Back

Which of the following is NOT a constant declared in the Java API? A. Integer.MAX_VALUE B. Conversions.KILOMETERS_PER_MILE C. Math.E D. Math.PI

Front

B. Conversions.KILOMETERS_PER_MILE -There is no such constant in the Java API (and no class called Conversions for that matter).

Back

What happens to the current value of the integer variable size when the following statement is executed? size = 12; A. Nothing. This will cause a syntax error. B. The current value is stored in the next available memory location. C. The current value is overwritten by the new value. D. There can be no current value in size.

Front

C. The current value is overwritten by the new value.

Back

If the variable num contains a positive integer, what are the only two possible results of the following expression? num % 2 A. 0 and 1 B. 1 and 2 C. -1 and 1 D. 0 and 2

Front

A. 0 and 1 - 2 either divides the number evenly or there is 1 left over.

Back

Suppose the integer variable hours contains a value that represents a number of hours. Which of the following expressions will compute how many 24-hour periods are represented by that value, without worrying about any leftover hours. A. hours / 24 B. hours % 24 C. hours / 24 + 1 D. hours % 24 + 1

Front

A. hours / 24

Back

A runtime error occurs when a printf field width is insufficient to display a value. True or False

Front

False

Back

The Math class contains a constant that represents the value pi to several digits. True or False?

Front

True

Back

The methods of the Math class are called through the class name because they are abstract. True or False

Front

False - They are called through the class because the methods are static.

Back

What does this % mean?

Front

remainder

Back

Constants make maintenance tasks easier. True or False?

Front

True

Back

Given the following declarations, which assignment statement would cause the compiler to issue an error? int num1 = 5, num2 = 3500; double num3 = 7.29; A. num2 = num3; B. num3 = num2; C. num2 = num1; D. num3 = num1;

Front

A. num2 = num3 - A double value cannot be assigned to an integer variable without a cast.

Back

If the current value of the integer variable size is 2, what value will be stored in size after the following line of code is executed? size *= 3; A. 2 B. 3 C. 5 D. 6

Front

D. 6

Back

Java constants cannot be created for floating-point values. True or False?

Front

False - You can make a constant out of any data type in Java.

Back

The expression x^y raises the value x to the power y. True or False?

Front

False

Back

What does the decrement operator do?

Front

-- decrements by 1

Back

The result of a relational operator can be assigned to a boolean variable. True or False

Front

True

Back

Of the options given, what values of the variables height, size, and width would cause the following code to set the variable weight to 100? if (height < size) { weight = 50; if (width < 20) System.out.println("short"); } else { if (width > 100) weight = 100; System.out.println("tall"); } A. height = 12, size = 20, width = 200 B. height = 15, size = 25, width = 50 C. height = 20, size = 12, width = 90 D. height = 15, size = 10, width = 110

Front

D.height = 15, size = 10, width = 110

Back

What is the result of the expression Math.pow(3, 3)? A. 0 B. 6 C. 9 D. 27

Front

D. 27

Back

What is wrong with the following code? if (count > 5) if (sum < MAX) System.out.println("cattywampus"); else System.out.println("snickersnee"); A. One output statement can never be executed. B. A second else clause is required. C. The indentation does not properly reflect the processing. D. It contains at least one invalid condition.

Front

C.The indentation does not properly reflect the processing.

Back

The arithmetic operators have a lower precedence than the relational operators. True or False

Front

False

Back

The format method of the String class accepts the same parameters as the printf method. True or False

Front

True

Back

If the current value of the integer variable count is 2, what value will be stored in count after the following line of code is executed? count += count * 3; A. 2 B. 3 C. 6 D. 8

Front

D. 8

Back

What is the result of the following Java expression? 7 / 2 A. 0 B. 1 C. 3 D. 3.5

Front

C. 3

Back

A printf format specifier changes the value in the corresponding parameter. True or False

Front

False

Back

A constant should not be declared with public visibility True or False?

Front

False -It's ok for a constant to be public because it's value cannot be changed.

Back

The printf method accepts a variable number of parameters. True or False

Front

True

Back

What is the result of the expression Math.floor(12.843)? A. 0 B. 10.0 C. 12.0 D. 13.0

Front

C. 12.0

Back

If both operands to the remainder operator (%) are positive, a divisor of n will produce a result in the range 1 to n. True or False?

Front

False

Back

Which of the following identifiers follow the naming convention for a Java constant? A. Max_Penalties B. MAX_PENALTIES C. MAXPENALTIES D. maxPenalties

Front

B. MAX_PENALITIES - Java constants should be in all upper case letters with underscores between words.

Back

The expression count++ can stand as a statement on its own. True or False?

Front

True

Back

What is the result of the following Java expression? 43 % 5 A. 3 B. 4 C. 8 D. 8.6

Front

A. 3 is leftover

Back

What is the result of the expression Math.round(8.25)? A. 8 B. 9 C. 8.2 D. 8.3

Front

A. 8

Back

Which of the following statements is true? A. An if statement is an example of a repetition statement. B. The body of an if statement must be enclosed in braces. C. The condition of an if statement must be a boolean expression. D. An if statement must contain an else clause.

Front

C. The condition of an if statement must be a boolean expression

Back

Section 4

(50 cards)

An import statement should be written inside a class but before any methods. True or False

Front

False - should be written above the class

Back

If A and B are both false, then the expression A && B is false. True or False

Front

True

Back

Which statement would produce the following output? Eeny Meeny Miny Moe A. System.out.println("Eeny
\tMeeny
Miny
\tMoe"); B. System.out.println("Eeny\t
Meeny\tMiny\t
Moe"); C. System.out.println("Eeny\t\tMeeny\tMiny\t\tMoe"); D. System.out.println("Eeny
\tMeeny
\tMiny
\tMoe");

Front

A. System.out.println("Eeny
\tMeeny
Miny
\tMoe"); - \t is a horizontal tab and
is a newline charcter (which sends the output to the next line).

Back

In a program, a class must always be referred to using its fully qualified name. True or False

Front

False - The import statement allows us to avoid always using the fully qualified name.

Back

The Java keyword new is a method that can be called to create objects. True or False

Front

False - The keyword new is an operator, not a method.

Back

What output would be produced when the following code is executed? String state = "Mississippi"; System.out.println(state.replace("is", "was")); A. Mwasswasswaspi B. Mwaswasippi C. Mwasswassippi D. Mwassissippi

Front

C. Mwasswassippi

Back

The classes of the java.util package are automatically imported into every Java program. True or False

Front

False - The only package automatically imported is java.lang

Back

A String method can be called through a string literal. True or False

Front

True - This is fine since a string literal represents the object.

Back

A static import let's you refer to a static method without using its class name. True or False

Front

True - Though it may mask the source of the method.

Back

An entire package can be imported using one import statement. True or False

Front

True - Using the wildcard * character.

Back

When reading input using a Scanner object, if the type of input does not match the expected type, the compiler will issue an error message. True or False

Front

False - This type of problem cannot be detected during compilation. It is a runtime error.

Back

A method declaration includes parentheses after the method name, even if the method takes no parameters. True or False

Front

True -That's how the compiler knows you're declaring a method.

Back

An object must be created when its object reference variable is declared. True or False

Front

False - can be separate activities

Back

A String object cannot be created with a new operator. True or False

Front

False - You can use the new operator, but often a string literal will suffice.

Back

A constructor of a class has the same name as the class. True or False

Front

True - It is called when the object is created.

Back

What does the ^ result produce?

Front

Will be false if there are 2 false statements or true if one is true. But if both are true then false

Back

If A is true and B is false, then the expression A || B is true. True or False

Front

True

Back

Which statement would produce the following output? "Oom Pah Pah Oom Pah Pah," that's how it goes. A. System.out.println("
Oom Pah Pah Oom Pah Pah,
that's how it goes."); B. System.out.println("\qOom Pah Pah Oom Pah Pah,\q that's how it goes."); C. System.out.println(""Oom Pah Pah Oom Pah Pah," that's how it goes."); D. System.out.println("\"Oom Pah Pah Oom Pah Pah,\" that's how it goes.");

Front

D. System.out.println("\"Oom Pah Pah Oom Pah Pah,\" that's how it goes."); - The \" escape sequences are needed to print the quotation marks.

Back

What operator is used to perform string concatenation in Java? A. + B. & C. * D. @

Front

A. +

Back

When reading input using a Scanner object, each input value must be on its own line. True or False

Front

False - Depending on what types of values are being read, they might be on the same input line.

Back

The String class is part of the java.util package. True or False

Front

False - apart of the java.lang

Back

The return type of a method must either be a Java primitive type or void. True or False

Front

False - A method could also return an object.

Back

It is usually not a good idea to explicitly return a true or false literal value in a method that returns a boolean. True or False

Front

True - It's better to return the boolean expression, which evaluates to true or false.

Back

If A is false, then the B operand in the expression A || B is not evaluated. True or False

Front

False - Since A is false, the truth value of an || expression won't be known until B is evaluated

Back

When a method is called, the type and value of each argument are included in parentheses. True or False

Front

False -The types of the arguments are only included in the method declaration, not when calling it.

Back

What are the four boolean operators?

Front

! - not && - and || - or ^ - exclusive or

Back

What is a backlash character? \

Front

which is sometimes called the escape character. When the compiler encounters a backslash character in a string literal, it knows to treat what follows in a special manner. The idea is that when the backslash is encountered we are breaking away, or escaping, from the standard meaning.

Back

What should you pass to the Scanner constructor if you want to create a Scanner object that reads input typed at the keyboard. A. System.in B. Console.out C. Keyboard.in D. System.out

Front

A. System.in - It represents the standard input stream.

Back

A variable can be declared inside the body of a method. True or False

Front

True - Such variables are local data, and cease to exist when the method returns.

Back

If the type of the expression in a return statement does not match the return type of the method, the compiler will issue an error message. True or False

Front

True - The method's return type and the type of the value returned must match.

Back

An import statement tells the compiler which class you're referring to in a program. True or False

Front

True - The package and class names together uniquely identify the class

Back

Given the following declaration, which expression would produce the substring "ledge"? String words = "Knowledge is power."; A. words.substring(4, 9); B. words.substring(5, 10); C. words.substring(4, 8); D. words.substring(5, 9)

Front

A. words.substring(4, 9); - start at 0!

Back

The next and nextLine methods of the Scanner class both read and return character strings. True or False

Front

True - They differ by how much text is read.

Back

The exclusive or operator (^) produces results that are opposite to the regular or operator (||). True or False

Front

False - only different when there both are true

Back

What does the && result produce?

Front

Will only be true if both variables are true

Back

What does the || result produce?

Front

Will only be true if one of the variables is true.

Back

What is the output of the following statement? System.out.println("He said \"Avada Kedavra\""); A. He said \\"Avada Kedavra\\" B. He said \"Avada Kedavra\" C. He said "Avada Kedavra" D. He said 'Avada Kedavra' E. No output. This statement contains a syntax error.

Front

C. He said "Avada Kedavra"

Back

A method that has a return type of void does not have to have a return statement. True or False

Front

True - The method automatically returns when the end of the method body is reached.

Back

If a String variable called greeting contains the characters "hello", what does the following expression do? greeting.toUpperCase() A. Returns a new string containing the characters "Hello" B. Converts the characters in the greeting object to "Hello". C. Returns a new string containing the characters "HELLO" D. Converts the characters in the greeting object to "HELLO".

Front

C. Returns a new string containing the characters "HELLO"

Back

What do the characters in a Unicode escape sequence represent? A. The hexadecimal code for a particular Unicode character B. the ASCII code for the equivalent Unicode character C. a range of Unicode characters D. the set of characters terminating in a particular Unicode character

Front

A. The hexadecimal code for a particular Unicode character - They are the code of a single character expressed as a hexadecimal number.

Back

Two classes can have the same name if they are in different packages. True or False

Front

True - That way each class name doesn't have to be unique

Back

The less than operator (<) should not be used to compare floating-point values. True or False

Front

False

Back

The relational operators can be used to put String objects in alphabetical order. True or False

Front

False

Back

The not operator (!) requires two operands. True or False

Front

False - only one (Unary)

Back

Which of the following literals is NOT valid? A. '
' B. '"' C. "\"
" D. ""
""

Front

D. ""
"" -This is not valid because the double quotes inside the string literal must be represented using escape sequences.

Back

If a String variable called pioneer contains the characters "Grace Murray Hopper", what is the result of the following expression? pioneer.length() A. 17 B. 18 C. 19 D. 20

Front

C. 19 - count spaces! start at 1

Back

By default, what characters are used to separate input tokens when reading input using a Scanner object? A. spaces, tabs, and newline characters B. colons C. semicolons D. periods

Front

A. spaces, tabs, and newline characters - Collectively, they are called white space.

Back

What does
do?

Front

creates a new line ex: (Batman

Robin); Batman Robin

Back

If a String variable called address contains the characters "123 Main Street", what is the result of the following expression? address.indexOf('3') A. -1 B. 2 C. 3 D. That expression would cause an error.

Front

B. 2 - character 3 is at number 2 because start at 0

Back

Attempting to follow a null reference will cause an exception to be thrown. True or False

Front

True -

Back

Section 5

(46 cards)

A for loop could always be written as an equivalent while loop. True or False

Front

True - A for loop is more appropriate in some situations, but the same result can always be produced with a while loop.

Back

It's impossible for the user to guess the target value in one guess. True or False

Front

False - possible but highly unlikely

Back

If gen refers to a Random object, the following expression will produce a value in what range? gen.nextInt(12) - 2 A. 1 to 10 B. -2 to 9 C. 0 to 10 D. -2 to 10

Front

B. -2 to 9 - The call to nextInt produces a value between 0 and 11, then subtracting 2 shifts it into the range -2 through 9.

Back

If the value of num is 7 and the value of max is 10, what is the value of num after the following statement is executed? num = (max < num) ? max : max - num; A. 3 B. 4 C. 7 D. 10

Front

A. 3 - The difference between max and num is assigned to num because the condition is false.

Back

The inner loop will stop immediately if the string is determined not to be a palindrome. True or False

Front

True - The boolean variable palindrome keeps track of that.

Back

If gen refers to a Random object, the following expression will produce a value in what range? gen.nextInt(10) + 5 A. 10 to 15 B. 0 to 15 C. 5 to 14 D. 5 to 10

Front

C. 5 to 14 - The call to nextInt produces a value from 0 to 9, then adding 5 shifts it into the range 5 to 14.

Back

The Unicode character set represents over 65,000 characters. True or False

Front

True - They include math symbols, asian ideograms, and emoticons among many others.

Back

The number of times the while loop will be executed can be calculated before the loop begins. True or False

Front

False - It depends on how long it takes the user to guess the target value.

Back

Each value of a case can be a constant, variable, or expression. True or False

Front

False - The value of each case can only be a constant (literal or named constant).

Back

The body of a while loop may never execute. True or False

Front

True - The condition is checked first, and if it's false right away, the body of the loop is never executed.

Back

There is no way to stop an infinite loop. True or False

Front

False - The program must be interrupted by pressing Ctrl-C or Ctrl-Break or by closing the run window.

Back

The increment section of the for loop header always adds 1 to the loop control variable. True or False

Front

False - Although its called the increment section, you can update the control variable in any way you'd like.

Back

A break statement is used at the end of each case of a switch statement to keep processing from continuing into the next case. True or False

Front

True - The break statement causes processing to jump out of the switch statement.

Back

If the value of weight is 7, what does the following statement print? System.out.println("The weight is " + ((weight % 2 == 0) ? "even" : "odd")); A. The weight is even B. The weight is odd C. The weight is void D. The weight is null

Front

B. The weight is odd - The condition is false so "odd" is concatenated to the output.

Back

After the following line of code is executed, the value stored in the variable num will be in what range? num = (int) (Math.random() * 25); A. 1 to 24 B. 1 to 25 C. 0 to 24 D. 0 to 25

Front

C. 0 to 24 - The int cast truncates the result to the range 0 to 24.

Back

What does the following for loop do? for (int num = 3; num <= 30; num += 3) System.out.println(num); A. Prints the sum of the numbers from 3 to 30. B. Prints the numbers from 3 to 30 (3, 4, 5, etc.) C. Prints the sum of the multiples of 3 between 3 and 30. D. Prints the multiples of 3 between 3 and 30 (3, 6, 9, etc.)

Front

D. Prints the multiples of 3 between 3 and 30 (3, 6, 9, etc.) - Each increment portion of the loop adds 3 on each iteration.

Back

If gen refers to a Random object, the following expression will produce a value in what range? gen.nextInt(30) A. 0 to 30 B. 1 to 29 C. 0 to 29 D. 1 to 30

Front

C. 0 to 29 - A call to nextInt(N) returns a value in the range zero to N-1

Back

The expression in a switch statement can be an int or double value. True or False

Front

False - A switch expression cannot be a floating-point value (like a double).

Back

The nested if statement in this program had to be written to check for the correct guess last. True or False

Front

False - The logic of the if statement could be written to check any of the possibilities in any order.

Back

Switch statements can only test equality; they cannot make relational comparisons like greater than (>). True or False

Front

True - A switch sees which case value matches its expression.

Back

Going from left to right, what are the three sections of a for loop header? A. increment, condition, initialization B. condition, increment, initialization C. initialization, condition, increment D. condition, initialization, increment E. initialization, increment, condition F. increment, initialization, condition

Front

C. initialization, condition, increment

Back

What should you pass to the Scanner constructor if you want to create a Scanner object that reads input typed at the keyboard. A. System.in B. Console.out C. Keyboard.in D. System.out

Front

A. System.in

Back

The body of a for loop is always executed at least once. True or False

Front

False - Like a while loop, if the condition is false initially, the body is never executed.

Back

In some cases, a sentinel value can be used to signal the end of input. True or False

Front

True - Each input value is compared to the sentinel value to know when the loop should terminate.

Back

Which of the following is NOT a repetition statement in Java? A. if statement B. while statement C. for statement D. for-each statement E. do-while statement F. They are all repetition statements.

Front

A. if statement - The if statement is a conditional statement, not a loop.

Back

If gen refers to a Random object, which of the following expressions would produce a value in the range 1 to 10? A. gen.nextInt(1) + 11 B. gen.nextInt(10) + 1 C. gen.nextInt(1) + 10 D. gen.nextInt(11) + 1

Front

B. gen.nextInt(10) + 1 - 0 to 9 plus 1 yields 1 to 10

Back

A character encoding is the list of all characters used by a programming language. True or False

Front

False - That's a character set. A character encoding defines how characters are stored in memory.

Back

What output is printed by the following code? String str = "Refactor Java"; int index = 0; int num = 0; while (index < str.length()) { if (str.charAt(index) == 'a') num++; index++; } System.out.println("Num: " + num); A. Num: 0 B. Num: 3 C. Num: 10 D. Num: 13 E. No output because the code contains an infinite loop.

Front

B. Num: 3 - The variable num represents the number of 'a' characters in the string.

Back

Using a while loop to check each input value for correctness is a form of input validation. True or False

Front

True - The loop won't allow processing to proceed until a valid value is entered.

Back

What is ASCII? A. A technique for ordering Unicode characters. B. A subset of Unicode containing primarily English characters and basic symbols. C. A technique for representing Unicode characters in memory. D. A set of non-printable Unicode characters. E. None of the above.

Front

B. A subset of Unicode containing primarily English characters and basic symbols. - ASCII stands for American Standard Code for Information Interchange.

Back

The control variable must be declared in the for loop header. True or False

Front

False - It often is, but might also be declared previously.

Back

A potential palindrome is evaluated by comparing characters at both ends and working inwards. True or False

Front

True - The indexes left and right determine which characters are compared.

Back

The string "i prefer pi" would be considered a palindrome by the original version of the program. True or False

Front

False - Even though it's in all lower case letters, the spaces would throw it off.

Back

What value is printed by the following code? int count = 0; for (int i = 0; i < 5; i++) count += 3; System.out.println(count); A. 0 B. 5 C. 12 D. 15 E. 18

Front

D. 15 - The loop repeats five times, adding three to count each time.

Back

Java uses the Unicode character set to represent characters. True or False

Front

True - Java was one of the first languages to adopt Unicode.

Back

What number is printed by the following code? int num = 20; switch (num) { case 1: num = num + 1; break; case 12: num = num + 1; num = num * 2; case 20: num = num * 2; case 25: num = num + 1; break; case 999: num = 20; break; default: num = 999; } System.out.println(num); A. 20 B. 21 C. 40 D. 41 E. 88 F. 999

Front

D. 41 - It starts at case 20, falls through into case 25, then breaks out of the switch.

Back

What does the following statement print? System.out.println((count < 0) ? "Invalid" : count); A. The value of count, or "Invalid" if count is positive. B. The value of count, or "Invalid" if count is negative. C. Zero, or "Invalid" if count is negative. D. Zero, or "Invalid" if count is positive.

Front

B. The value of count, or "Invalid" if count is negative. - Either a string or a number is sent to the println method.

Back

A switch statement can always be rewritten as a series of nested if statements. True or False

Front

True - Each if statement would correspond to a case in the switch statement.

Back

What output is produced by the following code? for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) System.out.print("*"); System.out.println(); } A. *** ** * ** * B. ** * * * ** C. *** *** *** *** *** D. * ** * ** ***

Front

C. *** *** *** *** *** The inner loop prints one line of 5 asterisks, which the outer loop repeats 5 times.

Back

What is the role of the seed value of a random number generator? A. It's the maximum number of values that can be produced by the generator. B. It's the maximum value that can be generated by that object. C. It's the minimum value of any range produced by the generator. D. It's a number that is the basis of the calculated pseudorandom numbers.

Front

D. It's a number that is the basis of the calculated pseudorandom numbers. - It's the starting point of a series of complex calculations.

Back

In the Palindromes program, the inner loop evaluates one string to see if it is a palindrome. True or False

Front

True - The outer loop allows multiple strings to be evaluated.

Back

This program would still work if the initial value of guess were set to -1 instead of -999. True or False

Front

True - The value only needs to be outside of the target range.

Back

What string is printed by the following code if it is executed when the value of finger is 3? switch (finger) { case 1: System.out.println("Thumb"); break; case 2: System.out.println("Index finger"); break; case 3: System.out.println("Middle finger"); break; case 4: System.out.println("Ring finger"); break; case 5: System.out.println("Pinky"); break; default: System.out.println("Not a finger!"); } A. Thumb B. Index finger C. Middle finger E. Ring finger F. Pinky G. Not a finger!

Front

C. Middle finger - Processing jumps to the matching case value (3), and then breaks out of the switch.

Back

Which assignment statement is functionally equivalent to the following if statement? if (num1 > total) num1 = total; else num1 = 0; A. num1 = (total > 0) ? 0 : total; B. num1 = (num1 > 0) ? total : 0; C. num1 = (num1 > total) ? total : 0; D. num1 = (num1 > total) ? 0 : total;

Front

C. num1 = (num1 > total) ? total : 0; - One or the other value is assigned to num1.

Back

What causes an infinite loop? A. A loop condition that is always false. B. A loop body that is never executed. C. A loop control variable that is repeatedly modified. D. A loop condition that is never false.

Front

D. A loop condition that is never false. - If the logic in the loop body never makes the condition false, it is called an infinite loop.

Back

What technique is used to put Unicode characters and strings in order? A. alphabetical ordering B. ASCII ordering C. character encoded ordering D. lexicographic ordering

Front

D. lexicographic ordering - It uses the numeric order of the character set.

Back