CIS 35A: Introduction to Java Programming

Home | Green Sheet | Lectures | Assignments | FAQ

Java

Java Programming
Test and debug

Debugger is a program that facilitates debugging. You can use a debugger to

  • Execute a single statement at a time.
  • Trace into or stepping over a method.
  • Set breakpoints.
  • Display variables.
  • Display call stack.
  • Modify variables.

How to test and debug an application

  • To test an application, you run it to make sure that it works properly no matter what data you enter. The goal is to find the errors (or bugs) in the application.
  • To debug an application, you find and fix the causes of the bugs.
  • One type of bug leads to a runtime error (or runtime exception) that causes the program to end prematurely.
  • Even if an application runs to completion, the results may be incorrect due to logical errors.

Debugging tips

  • For a runtime error, go to the line in the source code that was running when the program crashed. That should give you a good idea of what caused the error.
  • For incorrect output, figure out how the source code produced that output. Then, fix the code and test the application again.

A runtime error that occurred while testing the invoice application

Incorrect output produced by the Test Score application.

Previous