Engineering Software Correctness

Part 1: Dealing with Common Errors


This lab is the first of a series of three labs that deal with the overarching issue of "software correctness." Being able to assert that a program you write is "correct" is a necessity. We will explore different ways of defining "correctness" and determining to what extent we need to be able to guarantee our software. Many things have been written on this subject, but we will focus on the basic, lower-level concepts that all programmers have to deal with at some point or another: debugging and testing.

In this part of the series, Dealing with Common Errors, we will tackle some practical issues when programming with Java, specifically learning to read and interpret error messages Java provides (we'll leave the times Java doesn't provide error messages for the next section, which will deal with unit testing), as well as common techniques for diagnosing problems. We will also make use of a very basic debugging technique to help us identify problem spots.

Goals:

REQUIRED READING: A Beginner's Guide to Java Debugging


Once you've read the above tutorial, you should be prepared to complete the following exercises.

Download each Java file + history file pair, play back the interactions history one at a time and debug all errors that occur.

  1. MyInts: a class with some simple integer manipulations. You only need to worry about fixing the Exceptions - don't worry if the class doesn't seem to do anything terribly useful (it doesn't).
  2. Name: a simple class that implements Comparable, which contains a first and last name
  3. LinkedList: a generic implementation of a linked list similar to the one in java.util. You may need to make code changes that involve a decision of how certain methods function. As long as you do something reasonable (if you are unsure what qualifies as "reasonable" as your TA) and the error is gone, that's fine.
  4. CHALLENGE! ViewWeb: a class that reads a URL and prints it out to the screen. No actual error messages result from this code when executing the interactions. However, you will notice that the program does not produce output correctly.

    Your goal is to:
    a) identify the problem, i.e. why no output is being produced sometimes but not others, and
    b) try to fix it such that it will produce output.
    Please note:
    (a) is doable solely using debugging techniques described in the above guide.
    (b) will require exploring and experimenting with the API a little bit, specifically in the java.io and java.net packages.

Here is a ZIP file of all the above files, included for convenience.