Chapter 9 - Debugging – what goes wrong and how to fix it Flashcards

1
Q

describe
regression errors

A

An error found in older code when developing new code.

this can occur when legacy code does not work with new data or was never properly tested to begin with.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

decsribe
Compilation errors

A

An error detected by acompilerwhen code iscompiled.

Nobytecode (.class)is generated if these are present.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

describe
IndexOutOfBoundsException

A

created when we try and access an index that is out of bounds such as on an ArrayList

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the
basic format specifiers
in formatting strings?

A

these include:
1. %c for a Unicode character
2. %d for an integer
3. %e for scientific notation
4. %f for a decimal (floating-point) number
5. %s for a string
6. %x for hexadecimal numbers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what are 4 ways to
test input and output data

A

methods include:
1. documenting
2. positive testing
3. negative testing
4. boundary testing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a
Template String
in formatting strings?

A

this is a string that contains format specifiers, where the format specifiers will be replaced by a given input and will follow the rules of the format specifier.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

describe
Syntax Error

A

An error that occurs when the source code does not follow the syntax rules of the programming language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

describe the debugging method
Manual Walkthrough

A

A process of going through a section of code line by line to understand how each line affects the state of the object or other parts of the application.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

describe
positive testing

A

Using known and valid inputs to check that code produces expected outputs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

think of 4 possible fixes for the
“Cannot Find Symbol” Error

A

fixes for this error inclue:
1. Fix the spelling of the variable name.
2. Add a local variable to a method or constructor.
3. Add a parameter to a method or constructor.
4. Add a field to the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

describe
NumberFormatException

A

created to indicate that a method that converts a string to one of the numeric types has been passed an argument with an inappropriate format

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

these include:
1. %c for a Unicode character
2. %d for an integer
3. %e for scientific notation
4. %f for a decimal (floating-point) number
5. %s for a string
6. %x for hexadecimal numbers.

A

What are the
basic format specifiers
in formatting strings?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

describe
StackOverflowError

A

created when a program repeatedly calls methods until there is no stack space left to store the state of all the method invocations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

these include:
1. System.out.printf()
2. String.format()

A

which two
options are available in java to format strings

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

describe
Semantic Error

A

An error that is caused by violating higher-level relationships between parts of code, rather than incorrect syntax.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

methods include:
1. documenting
2. positive testing
3. negative testing
4. boundary testing

A

what are 4 ways to
test input and output data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

describe
NullPointerException

A

created when you try to call a method using a reference variable whose value isnull

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

what are 2 approaches that try and
prevent the misuse of code by programmers

A

two approaches that prevent this are:
1. Design by Contract
2. Defensive Code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

fixes for this error inclue:
1. Fix the spelling of the variable name.
2. Add a local variable to a method or constructor.
3. Add a parameter to a method or constructor.
4. Add a field to the class.

A

think of 4 possible fixes for the
“Cannot Find Symbol” Error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Errors that only become apparent when a program is run, and have not been detected beforehand.

theseerrors can be caused by logical errors or conditions outside of the control of the programmer.

A

describe
Runtime errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

describe
Boundary Testing

A

Testing with values at and near the extreme values of data fields and collection sizes.

can prevent an error known as an “off-by-one error”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
A

ignore

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

think of 6 possible examples
semantic errors

A

examples of this include:
1. Unreachable statements: return x + y; y++;
2. Using an incompatible type of argument in a method call
3. Using an incompatible type of operand with an operator
4. Failing to initialize a local variable before it is first used.
5. Return types not defined correctly
6. Missing variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

points include:
1. Occur during the execution of the bytecode
2. Can occur soon after execution or go unnoticed for years
3. Can be detected by JVM or programmer, but some may not signal their presence
4. Result from logical errors, misuse of library code, or failure to take into account software usage
5. May also occur due to reasons out of the programmer’s control such as deleted files, internet failure, JVM failure, or timing errors with the larger system.

A

think of 5 points about
runtime errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

An error that occurs when the source code does not follow the syntax rules of the programming language.

A

describe
Syntax Error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

this is a string within a template string that defines rules of how it will be replaced by a variable.

A

What is a
Format Specifier
in formatting strings?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

this is a string that contains format specifiers, where the format specifiers will be replaced by a given input and will follow the rules of the format specifier.

A

What is a
Template String
in formatting strings?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

An error found in older code when developing new code.

this can occur when legacy code does not work with new data or was never properly tested to begin with.

A

describe
regression errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

what are two common
compile time errors

A

these include:
1. syntax errors
2. semantic errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

A method of locating a bug by gradually narrowing down its source using print statements.

A

describe the debugging method
Wolf Fencing

31
Q

give 3 examples of
syntax errors

A

examples of this include:
1. Wrong order of tokens: new ArrayList()<>;
2. Missing tokens: hello world"; or int x = 55
3. Mismatched tokens: int y = (10 / 2) * (3 + 4) + 6);

32
Q

Using known invalid inputs to check that the code responds appropriately.

A

describe
Negative Testing

33
Q

describe a
logical error

A

Result in incorrect behavior of the program due to incorrect implementation by the programmer.

34
Q

Result in incorrect behavior of the program due to incorrect implementation by the programmer.

A

describe a
logical error

35
Q

think of 5 points about
runtime errors

A

points include:
1. Occur during the execution of the bytecode
2. Can occur soon after execution or go unnoticed for years
3. Can be detected by JVM or programmer, but some may not signal their presence
4. Result from logical errors, misuse of library code, or failure to take into account software usage
5. May also occur due to reasons out of the programmer’s control such as deleted files, internet failure, JVM failure, or timing errors with the larger system.

36
Q

describe
ArithmeticException

A

created when an exceptional arithmetic condition has occurred

for example, when division by zero has occurred

37
Q

examples of this include:
1. incorrect if statement
2. assigning incorrect value to a variable
3. incorrect argument value
4. incorrect value returned from a method
5. incorrect expression calculation.

A

try and think of 5 examples of a
logical error

38
Q

try and think of 5 examples of a
logical error

A

examples of this include:
1. incorrect if statement
2. assigning incorrect value to a variable
3. incorrect argument value
4. incorrect value returned from a method
5. incorrect expression calculation.

39
Q

An error that is caused by violating higher-level relationships between parts of code, rather than incorrect syntax.

A

describe
Semantic Error

40
Q

describe
Design by Contract

A

A concept that requires programmers to follow a “contract” of only using valid arguments to prevent errors and unexpected behavior.

if the programmer does not comply then it is there fault for any errors

41
Q

What is a
Format Specifier
in formatting strings?

A

this is a string within a template string that defines rules of how it will be replaced by a variable.

42
Q

A process of going through a section of code line by line to understand how each line affects the state of the object or other parts of the application.

A

describe the debugging method
Manual Walkthrough

43
Q

examples of this include:
1. Unreachable statements: return x + y; y++;
2. Using an incompatible type of argument in a method call
3. Using an incompatible type of operand with an operator
4. Failing to initialize a local variable before it is first used.
5. Return types not defined correctly
6. Missing variables

A

think of 6 possible examples
semantic errors

44
Q

describe
Runtime errors

A

Errors that only become apparent when a program is run, and have not been detected beforehand.

theseerrors can be caused by logical errors or conditions outside of the control of the programmer.

45
Q

An error detected by acompilerwhen code iscompiled.

Nobytecode (.class)is generated if these are present.

A

decsribe
Compilation errors

46
Q

created when an exceptional arithmetic condition has occurred

for example, when division by zero has occurred

A

describe
ArithmeticException

47
Q

describe an
Off-by-One Error

A

A logical error in which code is off by one unit

example:
a comparison operator that checks “<” when “<=” was required

48
Q

created to indicate that a method that converts a string to one of the numeric types has been passed an argument with an inappropriate format

A

describe
NumberFormatException

49
Q

these include:
1. syntax errors
2. semantic errors

A

what are two common
compile time errors

50
Q

describe the debugging method
Wolf Fencing

A

A method of locating a bug by gradually narrowing down its source using print statements.

51
Q

which two
options are available in java to format strings

A

these include:
1. System.out.printf()
2. String.format()

52
Q

An approach that attempts to prevent errors and unexpected behavior through misuses.

A

describe
Defensive Code

53
Q

the rule for this is:
“the number and type of the format specifiers must match the argument values given”

A

what is the rule for when multiple format specifiers are used in a string template

54
Q

two approaches that prevent this are:
1. Design by Contract
2. Defensive Code

A

what are 2 approaches that try and
prevent the misuse of code by programmers

55
Q

describe
StringIndexOutOfBoundsException

A

created when a program tries to access a part of a string using an index outside the string’s limits

56
Q

examples of this include:
1. Wrong order of tokens: new ArrayList()<>;
2. Missing tokens: hello world"; or int x = 55
3. Mismatched tokens: int y = (10 / 2) * (3 + 4) + 6);

A

give 3 examples of
syntax errors

57
Q

describe
Negative Testing

A

Using known invalid inputs to check that the code responds appropriately.

58
Q

when performing this:
1. Consider printing hard copies of the code and walking away from the computer
2. Make notes about what each line of code is doing
3. Don’t delve into method calls until you’ve noted the current line of code

A

what 3 things should be kept in mind when performing a
manual walkthrough

59
Q

what is the rule for when multiple format specifiers are used in a string template

A

the rule for this is:
“the number and type of the format specifiers must match the argument values given”

60
Q

A logical error in which code is off by one unit

example:
a comparison operator that checks “<” when “<=” was required

A

describe an
Off-by-One Error

61
Q

Using known and valid inputs to check that code produces expected outputs.

A

describe
positive testing

62
Q

created when a program tries to access a part of a string using an index outside the string’s limits

A

describe
StringIndexOutOfBoundsException

63
Q

Testing with values at and near the extreme values of data fields and collection sizes.

can prevent an error known as an “off-by-one error”

A

describe
Boundary Testing

64
Q

describe the
“Cannot Find Symbol” Error

A

this is an error that occurs when a variable identifier is not found.

65
Q

this is an error that occurs when a variable identifier is not found.

A

describe the
“Cannot Find Symbol” Error

66
Q

describe
ArrayIndexOutOfBoundsException

A

created when a program tries to access an array with an index outside the array’s limits

67
Q

what 3 things should be kept in mind when performing a
manual walkthrough

A

when performing this:
1. Consider printing hard copies of the code and walking away from the computer
2. Make notes about what each line of code is doing
3. Don’t delve into method calls until you’ve noted the current line of code

68
Q

created when a program repeatedly calls methods until there is no stack space left to store the state of all the method invocations.

A

describe
StackOverflowError

69
Q

A concept that requires programmers to follow a “contract” of only using valid arguments to prevent errors and unexpected behavior.

if the programmer does not comply then it is there fault for any errors

A

describe
Design by Contract

70
Q

created when you try to call a method using a reference variable whose value isnull

A

describe
NullPointerException

71
Q

created when we try and access an index that is out of bounds such as on an ArrayList

A

describe
IndexOutOfBoundsException

72
Q

created when a program tries to access an array with an index outside the array’s limits

A

describe
ArrayIndexOutOfBoundsException

73
Q

describe
Defensive Code

A

An approach that attempts to prevent errors and unexpected behavior through misuses.