Java Control Structures, Math, Errors, and Debugging Techniques

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/25

flashcard set

Earn XP

Description and Tags

Comprehensive practice flashcards covering Java conditional structures, loops, Math and Random classes, programming errors, and debugging techniques.

26 Terms

1
New cards

What is a Boolean expression in Java?

Any code that evaluates to exactly one of two values: true or false.

2
New cards

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).

3
New cards

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.

4
New cards

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).

5
New cards

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.

6
New cards

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.

7
New cards

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.

8
New cards

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.

9
New cards

What return types are produced by Math.pow() and Math.sqrt() in Java?

Both methods return a double.

10
New cards

What range of values is generated by Math.random()?

A random double from 0.00.0 (inclusive) up to 1.01.0 (exclusive).

11
New cards

What value range is returned by calling rand.nextInt(n) on an instance of java.util.Random?

A random integer from 00 up to n−1n - 1.

12
New cards

How do while, do-while, and for loops differ in execution?

A while loop checks the condition first and may run 00 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.

13
New cards

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.

14
New cards

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.

15
New cards

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.

16
New cards

What causes an ArithmeticException in Java?

An illegal mathematical operation that cannot be completed, such as integer division by zero.

17
New cards

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.

18
New cards

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.

19
New cards

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.

20
New cards

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.

21
New cards

What are the six guidelines of debugging methodology?

  1. Make sure all variables are initialized before use.
  2. Don't stop at one bug.
  3. Initialize constants in the DATA DIVISION; initialize variables with executable code.
  4. Watch for off-by-one errors.
  5. Test programs at their boundary values.
  6. Program defensively.
22
New cards

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.

23
New cards

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.

24
New cards

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.

25
New cards
<p>In jGRASP, what do the red circular markers shown in the left margin next to lines of code represent?</p>

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.

26
New cards

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.