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