SwingTopDebugging Tips

Debugging Tips

As your labs become more complicated and your knowledge of the syntax of Java grows, you will discover that the type of errors you spend most of your time dealing with will change. The problems caused by errors involving the rules of Java grammar will decrease and the problems caused by subtle logical difference between what you told the computer to do and what you meant to tell it will increase.

The process of removing such logical errors is called debugging. In recognition of its growing importance we want to give you four tips on how to approach it. The first two are ways to avoid complicated debugging problems in the first place, the third is a deep, guiding principle that us useful in debugging, and the last is a simple but very handy practical technique.

  1. Plan ahead.
  2. Write and test your programs incrementally.
  3. Localize the problem. We looked at the following program and saw how to find where the errors were and how to fix it. Demo: BadBasketball
  4. The use of "System.out.println" to print out vaiues while the program is executing. It can be used like:
        System.out.println("Print this line of text");
    
    or
    System.out.println("Score in Big Hoop test is " + score);
    
    Be prepared to use this trick while working on upcoming labs. It can be quite helpful.

SwingTopDebugging Tips