1/25
Comprehensive practice flashcards covering Java conditional structures, loops, Math and Random classes, programming errors, and debugging techniques.
What is a Boolean expression in Java?
Any code that evaluates to exactly one of two values: true or false.
What is a compound Boolean expression, and which logical operators are used to create one?
An expression that combines two or more simple Boolean expressions using logical operators: || (OR), && (AND), and ! (NOT).
What is a conditional control structure (decision structure)?
A programming feature that evaluates a condition and directs the computer to choose and execute specific blocks of code based on whether the condition is true or false.
What are the three conditional control structures in Java?
if (executes code only if the condition is true), if-else (executes one block if true and an alternative block if false), and if-else if-else (checks multiple conditions in order and executes the first true one).
What is the linear congruential method in the context of Java?
The algorithm used by java.util.Random to generate pseudorandom numbers—numbers that appear random and unpredictable but are generated deterministically.
What is short circuit evaluation?
A feature where the computer stops evaluating a compound Boolean expression as soon as the final outcome is already guaranteed.
How do an accumulator and a counter differ?
An accumulator keeps a running total by adding varying values to itself on each iteration, whereas a counter tracks how many times an event or loop iteration occurs.
What is a switch statement, and why is a break statement required after each case?
A conditional control structure that evaluates an expression (which must evaluate to an integer) against multiple constant case values; a break is required to prevent execution from falling through into subsequent cases.
What return types are produced by Math.pow() and Math.sqrt() in Java?
Both methods return a double.
What range of values is generated by Math.random()?
A random double from 0.0 (inclusive) up to 1.0 (exclusive).
What value range is returned by calling rand.nextInt(n) on an instance of java.util.Random?
A random integer from 0 up to n−1.
How do while, do-while, and for loops differ in execution?
A while loop checks the condition first and may run 0 times; a do-while loop guarantees execution at least once before checking the condition; a for loop is used when the exact number of iterations is known beforehand.
What is a syntax error, and how is it detected?
An error that violates the grammar rules of Java (such as omitting a semicolon); it is detected by the compiler and prevents the program from compiling or running.
What is a logic error (semantic error), and how must it be detected?
An error in syntactically correct code that yields unexpected or incorrect results; because the compiler cannot detect it, it must be found by the programmer through careful testing and source code inspection.
What is a run-time error (exception)?
An error not caught by the compiler that halts program execution at the specific statement that cannot be executed.
What causes an ArithmeticException in Java?
An illegal mathematical operation that cannot be completed, such as integer division by zero.
What causes an InputMismatchException to be thrown by Scanner?
When the user enters input that does not match the expected data type, such as entering a string of text when a numeric type was requested.
What is the difference between testing and debugging?
Testing is a structured activity to verify that a program functions correctly, whereas debugging is the process of locating, analyzing, and resolving bugs to make the program compile and execute properly.
In an IDE debugger, what are breakpoints and what is the Step command?
Breakpoints are designated statements where program execution pauses; the Step command advances execution one statement at a time between breakpoints.
What is the function of the Watch window during debugging?
It displays selected variables and their current values, updating dynamically whenever a watched variable is assigned a new value.
What are the six guidelines of debugging methodology?
What is an off-by-one error?
A common loop error where an iteration occurs one too many or one too few times due to an incorrect Boolean boundary condition.
What is a variable trace?
A table listing the sequential values of variables at points of assignment in the order they occur within a loop, along with program output.
Where should diagnostic println() statements be placed when debugging?
Immediately after a variable is assigned a new value, or directly before and after a condition is evaluated.

In jGRASP, what do the red circular markers shown in the left margin next to lines of code represent?
They represent program stop points (breakpoints) where the debugger suspends program execution.
How does commenting out code assist in debugging?
By temporarily disabling suspicious statements using //, allowing the programmer to isolate the source of an error through a process of elimination.