Java Programming Fundamentals
- 131Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
131 questions
- 1The software development environment for building Java applications that includes a compiler and other tools is the_____.
Hint
It is commonly abbreviated JDK.
Answer
Java development kit
Explanation
The Java development kit provides tools for developing Java applications, including the Java compiler and a Java Runtime environment.
- 2The compiler included with the JDK translates Java source code into_____before the program runs.
Hint
This intermediate representation can run on different operating systems with a suitable runtime.
Answer
Java bytecode
Explanation
During compilation, the Java compiler converts source code into Java bytecode.
- 3The software component that translates Java bytecode into native code for the operating system is the_____.
Hint
Its abbreviation is JVM.
Answer
Java Virtual Machine
Explanation
The Java Virtual Machine loads bytecode and converts it into native code that the underlying operating system can execute.
- 4The Java Runtime environment contains the_____that executes Java bytecode.
Hint
It is the runtime component that translates bytecode for the operating system.
Answer
Java Virtual Machine
Explanation
The Java Runtime environment includes the Java Virtual Machine, which executes Java bytecode.
- 5Java applications are described as_____because bytecode can run on different operating systems that have a Java Runtime environment.
Hint
The phrase means that the program is not tied to one operating system.
Answer
platform independent
Explanation
The JVM translates platform-independent Java bytecode into native code for the operating system in use.
- 6The command used to invoke the Java compiler from a terminal is_____.
Hint
It is written as a short command followed by the source file name.
Answer
Java C
Explanation
The tutorial demonstrates compiling a source file from the terminal by invoking the compiler with the command Java C and the Java file as an argument.
- 7After compilation, the Java source file main.java is represented by a bytecode file named_____.
Hint
Compiled Java bytecode files use the class extension.
Answer
main.class
Explanation
Compiling main.java creates main.class, which contains the bytecode representation of the source file.
- 8The core Java platform used in the course, containing libraries Java developers need to learn, is_____.
Hint
It is abbreviated Java SE.
Answer
Java standard edition
Explanation
Java standard edition is the core Java platform and includes libraries used across Java development.
- 9The Java edition described as supporting very large-scale and distributed systems is_____.
Hint
It is built on top of Java standard edition.
Answer
Java Enterprise Edition
Explanation
Java Enterprise Edition adds libraries for large-scale, fault-tolerant, distributed, multi-tiered software.
- 10The Java edition described as a subset of Java standard edition for mobile devices is_____.
Hint
It includes libraries specific to mobile devices.
Answer
Java micro Edition
Explanation
Java micro Edition is a subset of Java standard edition designed for mobile devices.
- 11The Java edition used in smart cards is_____.
Hint
Its name refers to the small card-based devices it supports.
Answer
Java card
Explanation
Java card is the edition of Java used for smart cards.
- 12A command-line application runs from the command line and, unlike a GUI application, does not have a_____.
Hint
This is commonly abbreviated GUI.
Answer
graphical user interface
Explanation
A command-line application is run from the command line and does not provide a graphical user interface.
- 13A block of code that performs a task is called a_____.
Hint
It is a reusable unit of code, such as one that sends an email or validates input.
Answer
function
Explanation
A function is a block of code designed to perform a task.
- 14In Java, the value type specified before a method name is its_____.
Hint
It indicates what kind of value the method gives back, if any.
Answer
return type
Explanation
A method declaration begins with a return type that specifies the type of value returned by the method.
- 15The reserved keyword used as a method return type when the method returns nothing is_____.
Hint
It means the method does not provide a return value.
Answer
void
Explanation
A method with the return type void does not return a value.
- 16The descriptive identifier that tells readers what a method is for is its_____.
Hint
For example, a method that sends an email could be called sendEmail.
Answer
name
Explanation
A method should have a descriptive name that clearly identifies its purpose.
- 17Values passed into a method are received through its_____.
Hint
They are the named placeholders listed inside the method's parentheses.
Answer
parameters
Explanation
Parameters provide a way to pass values to a method when it is called.
- 18The curly braces following a method declaration enclose the method's_____.
Hint
This is the body that carries out the method's task.
Answer
actual Java code
Explanation
The method body, enclosed in curly braces, contains the Java statements that perform its work.
- 19In the Java style shown, the opening brace for a method is placed on the_____where the method is defined.
Hint
It is not moved to a new line as is conventional in some other languages.
Answer
same line
Explanation
The tutorial's Java formatting convention places the left brace on the same line as the method declaration.
- 20The method that acts as the entry point and is called when a Java program runs is the_____method.
Hint
Every Java program needs at least one of these methods.
Answer
main
Explanation
When a Java program is executed, its main method is called and the code inside it runs.
- 21A container used to organize one or more related functions is a_____.
Hint
In Java, functions defined inside this container are called methods.
Answer
class
Explanation
A class groups related methods and helps organize a program's code.
- 22A function that belongs to a class is called a_____.
Hint
In Java, class members of this kind are not usually referred to simply as standalone functions.
Answer
method
Explanation
A method is a function that is part of a class.
- 23The special keyword that controls whether other classes and methods can access a class or method is an_____.
Hint
Public and private are examples.
Answer
access modifier
Explanation
An access modifier determines whether other classes and methods can access a class or method.
- 24The access modifier most commonly used for classes and methods in the tutorial is_____.
Hint
It allows access from other parts of the program.
Answer
public
Explanation
The tutorial notes that public is the access modifier used most of the time for class and method declarations.
- 25The Java naming convention in which the first letter of every word in a class name is uppercase is_____.
Hint
A class name such as Main follows this convention.
Answer
Pascal naming convention
Explanation
Pascal naming convention capitalizes the first letter of every word in a class name.
- 26The Java naming convention in which the first word starts lowercase and later words begin with uppercase letters is_____.
Hint
A method name such as sendEmail follows this convention.
Answer
camel naming convention
Explanation
Camel naming convention keeps the first word lowercase and capitalizes the first letter of each later word.
- 27A Java source file uses the file extension_____.
Hint
The compiled bytecode file uses a different extension.
Answer
.java
Explanation
Java source files have the .java extension; compiled bytecode is stored in class files.
- 28In Java, a statement is terminated with a_____.
Hint
This punctuation mark appears at the end of many Java statements.
Answer
semicolon
Explanation
Java statements are terminated with semicolons.
- 29A package groups related_____so that code can be organized as an application grows.
Hint
It organizes the containers that hold methods.
Answer
classes
Explanation
Packages group related classes, helping organize applications that may contain many classes.
- 30A package creates a_____for classes, allowing classes with the same name to exist in different packages.
Hint
It helps prevent naming conflicts.
Answer
namespace
Explanation
Packages create namespaces, so classes with the same name can be distinguished by their packages.
- 31The base package for a Java project is conventionally based on the company's domain name written in_____.
Hint
The domain components are arranged from the broadest part toward the more specific part.
Answer
Reverse
Explanation
By convention, a project's base package uses the company's domain name in reverse order; an actual registered domain is not required.
- 32A method marked static in the program's entry point is required for the_____.
Hint
The tutorial says to remember this requirement even before learning static methods in detail.
Answer
main method
Explanation
The main method in a Java program should be static so it can serve as the program's entry point.
- 33The group of basic value types such as integers, characters, and booleans is called the_____types.
Hint
These types store simple values directly.
Answer
primitive
Explanation
Primitive types are used to store simple values such as numbers, boolean values, and individual characters.
- 34Types used to store complex objects, such as dates or messages, are called_____types.
Hint
Their variables refer to objects in memory rather than holding the objects' actual values.
Answer
reference
Explanation
Reference types are used for complex objects and store references to those objects.
- 35The primitive type that occupies one byte and can store whole-number values from negative 128 through 127 is_____.
Hint
It is suitable for small whole-number values, such as a person's age in the example.
Answer
byte
Explanation
A byte uses one byte of memory and supports values from negative 128 to 127.
- 36The primitive type that occupies two bytes and stores whole numbers up to about 32,000 is_____.
Hint
It has a larger range than byte but a smaller range than int.
Answer
short
Explanation
A short uses two bytes of memory and can store values up to about 32,000.
- 37The four-byte primitive type used for whole numbers up to about two billion is_____.
Hint
In Java code its keyword is int.
Answer
integer
Explanation
An integer uses four bytes of memory and stores whole numbers up to about two billion.
- 38The eight-byte whole-number type used for values larger than the int range is_____.
Hint
A large integer literal assigned to it may need an L suffix.
Answer
long
Explanation
A long uses eight bytes and can store larger whole numbers than an integer.
- 39The primitive type that uses four bytes for decimal numbers and requires an F suffix for a decimal literal is_____.
Hint
It uses less memory than double.
Answer
float
Explanation
A float uses four bytes, and a decimal literal must be marked with F when assigned as a float.
- 40The eight-byte primitive type commonly used to store decimal numbers is_____.
Hint
It is the default type Java assigns to decimal literals.
Answer
double
Explanation
A double uses eight bytes and is the default type for numbers written with a decimal point.
- 41The primitive type for a single character, written with single quotes, is_____.
Hint
It can represent one character, unlike a string.
Answer
char
Explanation
A char stores a single character and is written using single quotes.
- 42The primitive type that stores either true or false is_____.
Hint
It represents a two-valued logical choice.
Answer
boolean
Explanation
A boolean stores one of the two values true or false.
- 43The underscore separator used to make large numeric literals more readable does not change the number's value; it only improves_____.
Hint
It makes groups of digits easier to scan.
Answer
readability
Explanation
Java permits underscores between digits in large numbers to make the literal easier to read.
- 44Words such as public, static, void, class, and package are reserved Java_____.
Hint
They cannot be reused as variable, class, or method names.
Answer
keywords
Explanation
Reserved keywords have special meaning in Java and cannot be used as identifiers for variables, classes, or methods.
- 45A variable is initialized when it is given its_____value.
Hint
This happens when the variable is first assigned a value.
Answer
initial
Explanation
Initialization means assigning a variable its initial value, which should happen before the variable is read.
- 46The final keyword makes a variable's value unchangeable after it is initialized, so the variable acts as a_____.
Hint
The tutorial names the constant PI using capital letters.
Answer
constant
Explanation
A final variable cannot be assigned a new value after initialization, so it is used as a constant.
- 47By convention, Java constants are named using_____.
Hint
This naming style visually distinguishes constants from ordinary variables.
Answer
all capital letters
Explanation
The convention shown is to write constant names in all capital letters.
- 48When a primitive variable is assigned to another primitive variable, the stored_____is copied, so the variables are independent.
Hint
Changing one variable afterward does not alter the other.
Answer
value
Explanation
Primitive variables are copied by value, so assigning one to another gives each variable an independent value.
- 49When a reference variable is assigned to another reference variable, the_____to the object is copied.
Hint
Both variables can then point to the same object.
Answer
reference
Explanation
Reference variables hold and copy a reference to an object, rather than copying the object itself.
- 50An object created from a class is an_____of that class.
Hint
The class serves as a blueprint for creating it.
Answer
instance
Explanation
A class defines a template or blueprint, and an object created from it is an instance of that class.
- 51The new operator is used to allocate memory when creating an object of a_____.
Hint
Primitive variables do not require this explicit allocation in the examples.
Answer
reference type
Explanation
Creating an object of a reference type uses new to allocate memory for that object.
- 52A string is a sequence of_____.
Hint
For example, a word is made of several of these units.
Answer
characters
Explanation
A string represents textual data as a sequence of characters.
- 53Although a string literal can be assigned without using new, String is still a_____.
Hint
The shorter syntax is a convenient way to create an object, not evidence that String is primitive.
Answer
reference type
Explanation
Java provides shorthand initialization for strings, but strings remain reference types.
- 54Strings in Java are_____, so operations that appear to modify one return a new string instead.
Hint
Their original contents cannot be changed in place.
Answer
immutable
Explanation
A string cannot be mutated; methods such as replace and toLowerCase return new string objects.
- 55The plus operator can be used to_____two strings into one.
Hint
This means joining the strings together.
Answer
concatenate
Explanation
The plus operator concatenates strings by joining their text.
- 56The String method that returns the number of characters in a string is_____.
Hint
It is useful for checking whether user input exceeds a character limit.
Answer
length
Explanation
The length method returns the number of characters in a string.
- 57The String method that returns the position of the first occurrence of a character or substring is_____.
Hint
It returns zero when the match begins at the first character.
Answer
index of
Explanation
The index of method finds the first occurrence of the requested character or text; if it is absent, the result is negative one.
- 58When index of cannot find the requested text, it returns_____.
Hint
This result can be used to detect that a string does not contain the search text.
Answer
negative 1
Explanation
The index of method returns negative 1 when the requested character or substring is not present.
- 59The String method that returns a new string with specified text replaced is_____.
Hint
It takes a target and replacement value.
Answer
replace
Explanation
The replace method returns a new string in which occurrences of the target are replaced; it does not change the original string.
- 60The String method that removes whitespace from the beginning and end of a string is_____.
Hint
It is useful for cleaning up text entered in a form.
Answer
trim
Explanation
The trim method removes extra whitespace at the start and end of a string.
- 61In a Java string, the escape sequence used to include a double quote character is a backslash followed by_____.
Hint
Escaping prevents the quote from being interpreted as the end of the string.
Answer
double quote
Explanation
A backslash before a double quote allows that quote to appear inside a string literal.
- 62To represent a literal backslash in a Java string, use the escape sequence consisting of two_____.
Hint
The first backslash escapes the second one.
Answer
backslashes
Explanation
Two backslashes in the source string produce one backslash in the resulting text.
- 63The escape sequence used to insert a new line in a Java string is backslash followed by_____.
Hint
It is written as the newline escape sequence.
Answer
n
Explanation
The escape sequence backslash n inserts a line break into a string.
- 64The escape sequence used to insert a tab in a Java string is backslash followed by_____.
Hint
It is written as the tab escape sequence.
Answer
t
Explanation
The escape sequence backslash t inserts a tab into a string.
- 65An array is used to store a_____of items, such as numbers or messages.
Hint
The items are stored together and accessed by index.
Answer
list
Explanation
Arrays store a list of items of a particular type.
- 66The first element of a Java array is accessed using index_____.
Hint
Array indexing begins before one, not at one.
Answer
zero
Explanation
Java arrays use zero-based indexing, so the first element is at index zero.
- 67Once created, a Java array has a_____length; items cannot be added or removed from it.
Hint
Use a collection when the number of elements needs to change.
Answer
fixed
Explanation
Arrays have a fixed size after creation. Collections can be used when items need to be added or removed.
- 68For an integer array, elements that are not explicitly initialized default to_____.
Hint
This is the default value for an uninitialized integer element.
Answer
0
Explanation
Unassigned elements in an integer array are initialized to zero by default.
- 69The Arrays method that produces a readable string representation of a one-dimensional array is_____.
Hint
It converts the array into a string for printing.
Answer
toString
Explanation
Arrays.toString returns a string representation of a one-dimensional array.
- 70The Arrays method used to print a multidimensional array's nested contents is_____.
Hint
It handles the nested arrays rather than displaying only an object reference.
Answer
deepToString
Explanation
Arrays.deepToString provides a readable representation of a multidimensional array.
- 71The Arrays method used to arrange an array's items in sorted order is_____.
Hint
It orders the values rather than merely formatting them.
Answer
sort
Explanation
Arrays.sort sorts the contents of an array.
- 72The arithmetic operator that returns the remainder of a division is the_____.
Hint
It is useful for checking whether one number is divisible by another.
Answer
modulus operator
Explanation
The modulus operator returns the remainder after division; a zero remainder means the number is evenly divisible.
- 73When both operands of division are whole numbers in Java, the result is a_____.
Hint
A fractional part is discarded rather than automatically producing a decimal result.
Answer
whole number
Explanation
Division of two whole-number values produces a whole-number result; convert an operand to a floating-point type to get a decimal result.
- 74An expression is a piece of code that produces a_____.
Hint
For example, a comparison expression produces true or false.
Answer
value
Explanation
An expression evaluates to a value, which may be numeric, textual, or boolean.
- 75In an arithmetic expression, the values that operators act on are called_____.
Hint
In the expression 10 plus 3, these are 10 and 3.
Answer
operands
Explanation
Operands are the values used by arithmetic operators.
- 76The increment operator increases a variable's value by_____.
Hint
It is the short form for adding one.
Answer
1
Explanation
Applying the increment operator increases the value of its variable by one.
- 77With postfix increment in an assignment, the old value is copied first and the variable is incremented_____.
Hint
The increment happens after the assignment receives the value.
Answer
afterward
Explanation
Postfix increment supplies the current value to the expression before increasing the variable.
- 78With prefix increment in an assignment, the variable is incremented before its new value is copied to the assignment target, so the increment occurs_____.
Hint
The updated value is the one used by the expression.
Answer
first
Explanation
Prefix increment changes the variable before its value is used in the surrounding expression.
- 79The compound assignment operator += expresses the same update as adding a value and assigning the result back to the variable; it is an_____assignment operator.
Hint
It is a shorter form of an arithmetic update.
Answer
augmented
Explanation
An augmented, or compound, assignment such as x += 2 is equivalent to x = x + 2.
- 80In arithmetic precedence, multiplication and division are evaluated before addition and_____.
Hint
These two operations have the lower priority in the example.
Answer
subtraction
Explanation
Multiplication and division have higher precedence than addition and subtraction.
- 81Parentheses can be used to change the order in which arithmetic operations are_____.
Hint
An expression inside parentheses is handled before lower-priority operations outside them.
Answer
evaluated
Explanation
Parentheses have the highest priority and can force an expression to be evaluated first.
- 82Automatic conversion to a wider compatible type, when it does not risk losing data, is called_____casting.
Hint
The programmer does not have to write the conversion explicitly.
Answer
implicit
Explanation
Implicit casting happens automatically when a value can be converted to a wider type without data loss.
- 83A conversion written explicitly by the programmer, such as placing int in parentheses before a value, is called_____casting.
Hint
This form makes the requested type conversion visible in the code.
Answer
explicit
Explanation
Explicit casting directs Java to convert a value to a specified compatible type and may lose data.
- 84Converting a decimal value to an integer can discard the fractional part, so this conversion can involve data_____.
Hint
The digits after the decimal point may not be retained.
Answer
loss
Explanation
Explicitly converting a floating-point value to an integer removes its fractional part and therefore can lose data.
- 85The wrapper class method used to convert a string containing a whole number to an int is Integer dot_____.
Hint
The method name indicates the target primitive type.
Answer
parseInt
Explanation
Integer.parseInt converts a numeric string to an int; related wrapper classes provide parsing methods for other numeric types.
- 86The Double wrapper class method used to convert a decimal numeric string to a double is_____.
Hint
Use this instead of parsing a decimal value as an integer.
Answer
parseDouble
Explanation
Double.parseDouble parses a string as a double, including a value with a fractional part.
- 87The Math method that rounds a floating-point value to a whole-number result is_____.
Hint
Its result type depends on whether the input is a float or a double.
Answer
round
Explanation
Math.round rounds a floating-point number; it returns an int for a float argument and a long for a double argument.
- 88The Math method that returns the smallest integer greater than or equal to a number is_____.
Hint
For example, the result for 1.1 is 2.
Answer
ceil
Explanation
Math.ceil returns the ceiling value, the smallest integer greater than or equal to the input, represented as a double.
- 89The Math method that returns the largest integer less than or equal to a number is_____.
Hint
For example, the result for 1.1 is 1.
Answer
floor
Explanation
Math.floor returns the largest integer less than or equal to the input, represented as a double.
- 90The Math method that returns the greater of two values is_____.
Hint
It compares two supplied values and selects the larger one.
Answer
max
Explanation
Math.max returns the greater of its two arguments and has overloads for different numeric types.
- 91The Math method that returns a pseudorandom double between zero and one is_____.
Hint
Multiplying its result by 100 scales the range to zero through 100.
Answer
random
Explanation
Math.random returns a random floating-point value between zero and one; scaling and converting can produce other ranges.
- 92To read input from the terminal using Scanner, pass the system field_____.
Hint
The corresponding output field used for printing is System.out.
Answer
System.in
Explanation
A Scanner constructed with System.in reads input from the terminal.
- 93The Scanner method that reads one whitespace-separated token is_____.
Hint
Repeated calls read successive tokens, not necessarily a whole line.
Answer
next
Explanation
Scanner.next reads one token at a time, so a name containing spaces requires more than one call or a different method.
- 94The Scanner method that reads the entire line, including spaces, is_____.
Hint
Use it when input may contain a full name or other text with spaces.
Answer
nextLine
Explanation
Scanner.nextLine reads the full line entered by the user, including spaces and tabs.
- 95To prompt without automatically moving the cursor to the next line, use the Scanner tutorial's output method named_____.
Hint
Unlike its line-ending counterpart, it does not append a new line.
Answer
print
Explanation
The print method displays a prompt without adding a newline, allowing the user's input to appear beside it.
- 96The Java class used to format numbers as currency or percentages is_____.
Hint
It is defined in the text package and supplies formatting methods.
Answer
NumberFormat
Explanation
NumberFormat provides methods for displaying numeric values in formats such as currency and percent.
- 97Because NumberFormat is abstract, an instance for currency formatting is obtained with its_____.
Hint
This factory method creates and returns a suitable NumberFormat object.
Answer
getCurrencyInstance
Explanation
An abstract class cannot be instantiated with new; getCurrencyInstance supplies a NumberFormat instance configured for currency.
- 98The NumberFormat factory method that supplies an object for percent formatting is_____.
Hint
It returns a formatter that displays a value such as 0.1 as 10 percent.
Answer
getPercentInstance
Explanation
getPercentInstance creates a NumberFormat object configured to format numeric values as percentages.
- 99A factory method followed immediately by another method call on its returned object is an example of method_____.
Hint
The calls are connected rather than stored in separate intermediate variables.
Answer
chaining
Explanation
Method chaining calls a method on the object returned by a previous method call.
- 100Replacing unexplained numeric literals with named final variables helps avoid_____numbers.
Hint
Named constants make the purpose of values like 12 or 100 clear to readers.
Answer
magic
Explanation
Using descriptive constants instead of magic numbers improves code clarity and makes the intent of values explicit.
- 101Operators such as == and != used to compare primitive values are called_____operators.
Hint
They determine whether values are equal, unequal, greater, or smaller.
Answer
comparison
Explanation
Comparison operators compare primitive values and produce boolean results.
- 102An expression that evaluates to either true or false is a_____expression.
Hint
The result can be used as the condition of an if statement or loop.
Answer
boolean
Explanation
A boolean expression produces a boolean value, true or false.
- 103The logical operator && returns true only when_____conditions are true.
Hint
If either side is false, the complete expression is false.
Answer
both
Explanation
The logical AND operator evaluates to true only if both boolean conditions are true.
- 104The logical operator represented by two vertical bars returns true if at least_____condition is true.
Hint
It combines alternatives rather than requiring both conditions.
Answer
one
Explanation
The logical OR operator evaluates to true when at least one of its conditions is true.
- 105The logical operator ! reverses a boolean value and is called logical_____.
Hint
Applying it to false produces true.
Answer
not
Explanation
Logical NOT negates a boolean value, changing true to false or false to true.
- 106The clause that supplies a condition for an alternative path when the preceding if condition is false is_____.
Hint
It allows a program to test another condition before the final fallback.
Answer
else if
Explanation
An else if clause tests another condition when earlier conditions in an if statement are false.
- 107The final fallback clause in an if structure, used when none of its earlier conditions match, is_____.
Hint
It does not require a condition of its own.
Answer
else
Explanation
The else clause runs when none of the preceding if or else if conditions is true.
- 108The operator that selects one of two values according to a condition uses a question mark and a_____.
Hint
Its structure is condition, question mark, first value, then this punctuation and the alternative value.
Answer
colon
Explanation
The ternary operator has a condition and two possible values separated by a question mark and a colon.
- 109A switch statement uses a_____clause to run when none of its listed cases matches.
Hint
It acts as the switch statement's fallback case.
Answer
default
Explanation
The default clause is executed when no case value matches the switch expression.
- 110In a switch statement, the statement that exits the switch after a matching case is_____.
Hint
Without it, execution can continue into later cases.
Answer
break
Explanation
A break statement exits the switch block and prevents execution from falling through to subsequent cases.
- 111When several conditions overlap, placing the most_____condition first prevents a broader condition from taking precedence.
Hint
For example, test divisibility by both 3 and 5 before divisibility by just 5.
Answer
specific
Explanation
In the FizzBuzz example, the condition for divisibility by both numbers must come before the less specific individual divisibility checks.
- 112A for loop is especially useful when the number of repetitions is known_____.
Hint
Its initialization, condition, and update are collected in the loop header.
Answer
ahead of time
Explanation
A for loop is a good choice when the number of iterations is known in advance.
- 113The three parts of a for loop header are the counter initialization, loop condition, and counter_____.
Hint
This often increments or decrements the loop variable after an iteration.
Answer
update
Explanation
A for loop header initializes its counter, checks a condition, and updates the counter between iterations.
- 114A while loop is especially useful when the number of repetitions is not known_____.
Hint
For example, the user may decide when to stop by entering a particular word.
Answer
ahead of time
Explanation
A while loop is suitable when repetition continues until a condition changes and the number of iterations is not known beforehand.
- 115A do-while loop checks its condition after running its body, so its body executes at least_____.
Hint
This distinguishes it from a while loop whose condition is false at the start.
Answer
once
Explanation
Because a do-while loop tests its condition after the body, it always executes the body at least once.
- 116The statement that immediately terminates a loop is_____.
Hint
It exits the loop rather than skipping only the current iteration.
Answer
break
Explanation
The break statement stops execution of the current loop.
- 117The statement that skips the rest of the current loop iteration and moves to the next one is_____.
Hint
It does not terminate the loop entirely.
Answer
continue
Explanation
The continue statement moves control to the beginning of the next loop iteration.
- 118A loop whose condition is always true can run indefinitely unless it contains a_____.
Hint
The loop needs a way to stop when its exit condition is reached.
Answer
break statement
Explanation
A while true loop continues indefinitely unless a break statement provides a way to exit it.
- 119A for-each loop is designed to iterate over arrays or_____.
Hint
These are groups of items that can be traversed one at a time.
Answer
collections
Explanation
For-each loops provide a concise way to iterate over arrays and collections.
- 120Unlike a traditional for loop, a for-each loop does not directly provide the index of each_____.
Hint
It supplies the current element through its loop variable.
Answer
item
Explanation
A for-each loop gives access to each element but not its index; use a traditional for loop when the index is needed.
- 121A for-each loop traverses elements only in the_____direction.
Hint
A traditional for loop can be adjusted to move from the end toward the beginning.
Answer
forward
Explanation
The for-each loop moves forward through its array or collection and does not directly support reverse iteration.
- 122A mortgage calculator converts the annual interest rate, expressed as a percent, to a decimal rate by dividing by_____.
Hint
A percentage must be converted before it is used as a decimal interest rate.
Answer
100
Explanation
The annual rate is divided by 100 to convert its percentage representation to a decimal rate.
- 123To obtain the monthly interest rate from the annual decimal rate, divide by the number of_____in a year.
Hint
The calculator uses 12 of these in one year.
Answer
months
Explanation
The annual interest rate is divided by 12 to convert it to a monthly interest rate.
- 124The number of monthly mortgage payments is the number of loan years multiplied by 12, the number of_____in a year.
Hint
Each year contributes 12 monthly payments.
Answer
months
Explanation
The payment count is calculated by multiplying the loan period in years by 12 months per year.
- 125In the mortgage formula, the Math method used to raise a value to a specified power is_____.
Hint
It accepts a base and an exponent.
Answer
pow
Explanation
The Math.pow method raises its first argument to the power specified by its second argument.
- 126Mortgage input validation can keep asking the same question by placing the prompt and check inside an infinite_____.
Hint
A break statement exits it when the entered value is valid.
Answer
loop
Explanation
An infinite loop can repeatedly prompt the user until a valid value is entered, then break when validation succeeds.
- 127A variable declared inside a code block is scoped to that_____, so it cannot be accessed outside it.
Hint
Move the declaration outward if later code needs to use the variable.
Answer
block
Explanation
A variable's scope is limited to the block in which it is declared; code outside that block cannot access it.
- 128Descriptive variable names improve code readability by making each variable's_____clear.
Hint
Names such as monthlyInterest convey more than names such as m1.
Answer
purpose
Explanation
Meaningful names help readers understand what variables represent and what the code does.
- 129A programming guideline abbreviated DRY means_____.
Hint
It encourages avoiding duplicated code or expressions.
Answer
don't repeat yourself
Explanation
DRY stands for don't repeat yourself, a principle that discourages unnecessary duplication in code.
- 130In choosing between solutions, programming often involves_____because every solution has strengths and weaknesses.
Hint
A solution may reduce duplication but make code more nested, for example.
Answer
trade-offs
Explanation
Programming and problem solving involve trade-offs; one implementation may improve one quality while making another worse.
- 131Code that is clean and expressive is generally easier to_____and maintain.
Hint
It is written for human readers as well as for the computer.
Answer
understand
Explanation
Clean, expressive code helps people understand a program and makes it easier to maintain.

Ask anything
We've read this whole study set, so questions about it get the best answers.