Chapter 9 - Debugging – what goes wrong and how to fix it Flashcards
describe
regression errors
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.
decsribe
Compilation errors
An error detected by acompilerwhen code iscompiled.
Nobytecode (.class)is generated if these are present.
describe
IndexOutOfBoundsException
created when we try and access an index that is out of bounds such as on an ArrayList
What are the
basic format specifiers
in formatting strings?
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.
what are 4 ways to
test input and output data
methods include:
1. documenting
2. positive testing
3. negative testing
4. boundary testing
What is a
Template String
in formatting strings?
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.
describe
Syntax Error
An error that occurs when the source code does not follow the syntax rules of the programming language.
describe the debugging method
Manual Walkthrough
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.
describe
positive testing
Using known and valid inputs to check that code produces expected outputs.
think of 4 possible fixes for the
“Cannot Find Symbol” Error
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.
describe
NumberFormatException
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
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.
What are the
basic format specifiers
in formatting strings?
describe
StackOverflowError
created when a program repeatedly calls methods until there is no stack space left to store the state of all the method invocations.
these include:
1. System.out.printf()
2. String.format()
which two
options are available in java to format strings
describe
Semantic Error
An error that is caused by violating higher-level relationships between parts of code, rather than incorrect syntax.
methods include:
1. documenting
2. positive testing
3. negative testing
4. boundary testing
what are 4 ways to
test input and output data
describe
NullPointerException
created when you try to call a method using a reference variable whose value isnull
what are 2 approaches that try and
prevent the misuse of code by programmers
two approaches that prevent this are:
1. Design by Contract
2. Defensive Code
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.
think of 4 possible fixes for the
“Cannot Find Symbol” Error
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.
describe
Runtime errors
describe
Boundary Testing
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”
think of 6 possible examples
semantic errors
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
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.
think of 5 points about
runtime errors
An error that occurs when the source code does not follow the syntax rules of the programming language.
describe
Syntax Error
this is a string within a template string that defines rules of how it will be replaced by a variable.
What is a
Format Specifier
in formatting strings?
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.
What is a
Template String
in formatting strings?
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.
describe
regression errors
what are two common
compile time errors
these include:
1. syntax errors
2. semantic errors
A method of locating a bug by gradually narrowing down its source using print statements.
describe the debugging method
Wolf Fencing
give 3 examples of
syntax errors
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);
Using known invalid inputs to check that the code responds appropriately.
describe
Negative Testing
describe a
logical error
Result in incorrect behavior of the program due to incorrect implementation by the programmer.
Result in incorrect behavior of the program due to incorrect implementation by the programmer.
describe a
logical error
think of 5 points about
runtime errors
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.
describe
ArithmeticException
created when an exceptional arithmetic condition has occurred
for example, when division by zero has occurred
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.
try and think of 5 examples of a
logical error
try and think of 5 examples of a
logical error
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.
An error that is caused by violating higher-level relationships between parts of code, rather than incorrect syntax.
describe
Semantic Error
describe
Design by Contract
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
What is a
Format Specifier
in formatting strings?
this is a string within a template string that defines rules of how it will be replaced by a variable.
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.
describe the debugging method
Manual Walkthrough
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
think of 6 possible examples
semantic errors
describe
Runtime errors
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.
An error detected by acompilerwhen code iscompiled.
Nobytecode (.class)is generated if these are present.
decsribe
Compilation errors
created when an exceptional arithmetic condition has occurred
for example, when division by zero has occurred
describe
ArithmeticException
describe an
Off-by-One Error
A logical error in which code is off by one unit
example:
a comparison operator that checks “<” when “<=” was required
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
describe
NumberFormatException
these include:
1. syntax errors
2. semantic errors
what are two common
compile time errors
describe the debugging method
Wolf Fencing
A method of locating a bug by gradually narrowing down its source using print statements.
which two
options are available in java to format strings
these include:
1. System.out.printf()
2. String.format()
An approach that attempts to prevent errors and unexpected behavior through misuses.
describe
Defensive Code
the rule for this is:
“the number and type of the format specifiers must match the argument values given”
what is the rule for when multiple format specifiers are used in a string template
two approaches that prevent this are:
1. Design by Contract
2. Defensive Code
what are 2 approaches that try and
prevent the misuse of code by programmers
describe
StringIndexOutOfBoundsException
created when a program tries to access a part of a string using an index outside the string’s limits
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);
give 3 examples of
syntax errors
describe
Negative Testing
Using known invalid inputs to check that the code responds appropriately.
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
what 3 things should be kept in mind when performing a
manual walkthrough
what is the rule for when multiple format specifiers are used in a string template
the rule for this is:
“the number and type of the format specifiers must match the argument values given”
A logical error in which code is off by one unit
example:
a comparison operator that checks “<” when “<=” was required
describe an
Off-by-One Error
Using known and valid inputs to check that code produces expected outputs.
describe
positive testing
created when a program tries to access a part of a string using an index outside the string’s limits
describe
StringIndexOutOfBoundsException
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”
describe
Boundary Testing
describe the
“Cannot Find Symbol” Error
this is an error that occurs when a variable identifier is not found.
this is an error that occurs when a variable identifier is not found.
describe the
“Cannot Find Symbol” Error
describe
ArrayIndexOutOfBoundsException
created when a program tries to access an array with an index outside the array’s limits
what 3 things should be kept in mind when performing a
manual walkthrough
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
created when a program repeatedly calls methods until there is no stack space left to store the state of all the method invocations.
describe
StackOverflowError
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
describe
Design by Contract
created when you try to call a method using a reference variable whose value isnull
describe
NullPointerException
created when we try and access an index that is out of bounds such as on an ArrayList
describe
IndexOutOfBoundsException
created when a program tries to access an array with an index outside the array’s limits
describe
ArrayIndexOutOfBoundsException
describe
Defensive Code
An approach that attempts to prevent errors and unexpected behavior through misuses.