Self-check questions
Write your answers first, then open the answers to check them.
- Name the three types of error and give an example of each.
- List the boundary values for the grade program and explain why they are tested.
- What is a breakpoint, and how does stepping through code help you find a logic error?
Show answers
Error When it appears Example Syntax error The compiler rejects the code A missing semicolon or a misspelt keyword Runtime error The program crashes while running Integer division by zero; calling a method on nullLogic error The program runs but the answer is wrong <instead of<=, so the last value is missedBoundary values are on each edge of every range: 0, 49, 50, 64, 65, 74, 75 and 100 (and just outside the valid range: −1 and 101). Mistakes such as writing
>instead of>=only show up at these edges, so testing the values on both sides of each edge catches them.A breakpoint is a marker on a line where the debugger pauses the program. You can then step one line at a time while the variables panel shows every value. Compare the real values with your trace table: the first line where they differ is where the logic error is.
Practice exercises
- Trace the algorithm for the largest of three numbers with inputs (4, 9, 7) and (5, 5, 2).
- Write the Java version of the grade program and test it with every case in the test table in 1.4.2.
- Introduce one syntax error, one runtime error and one logic error on purpose and note how the IDE reports each.
End of Unit 1. Test yourself with the Unit 1 questions in the multiple-choice and structured question banks, tick the outcomes in the topic checklist, then go on to the next unit.