Unit 1 · Basics of Computer Programming

1.4.4Self-check and practice

Self-check questions

Write your answers first, then open the answers to check them.

  1. Name the three types of error and give an example of each.
  2. List the boundary values for the grade program and explain why they are tested.
  3. What is a breakpoint, and how does stepping through code help you find a logic error?
Show answers
  1. ErrorWhen it appearsExample
    Syntax errorThe compiler rejects the codeA missing semicolon or a misspelt keyword
    Runtime errorThe program crashes while runningInteger division by zero; calling a method on null
    Logic errorThe program runs but the answer is wrong< instead of <=, so the last value is missed
  2. Boundary 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.

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

  1. Trace the algorithm for the largest of three numbers with inputs (4, 9, 7) and (5, 5, 2).
  2. Write the Java version of the grade program and test it with every case in the test table in 1.4.2.
  3. 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.