Debugging in Java

A software bug is a mistake in a program. Debugging is to find and correct the mistakes (introduced by yourself). Programmers usually spend 20% of time for coding, and 80% of time for debugging.

In 1996, the European Space Agency’s US$1 billion prototype Ariane 5 rocket was destroyed less than a minute after launch. The bug is that, a data conversion from 64-bit floating point value to 16-bit signed integer value to be stored in a variable representing horizontal bias caused a processor trap (operand error) because the floating point value was too large to be represented by a 16-bit signed integer.

An easy way for debugging is to add System.out.print() or println() to print out the values of variables. In fact, many softwares use this approach to generate log files; and when error happens, the log files will be useful for identifying the location and reason of the error.

A debugger allows us to control and observe the working process as the program runs. A debugger usually provides the following functionalities.

  • Set breakpoints
  • Display the values of variables
  • Step into/over/return from a method
  • Execute the next statement
  • Continue execution until the next breakpoint or exit

Comments

comments