您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)

 

Content Index

Content Page # 8

Learning how to debug

Learning how to debug each kind of error takes practice. You will get this practice since most programs you write when you begin programming will contain all three kinds of error, and you will need to debug them to get your programs to work. Don't feel you are wasting time if it takes 10 minutes (or whatever) to identify, location and correct an error. Such an activity means you not only have learnt to debug that particular error, you are also much less likely to write a program containing that error in the future. You can improve your learning of debugging, and the writing of error free programs by making notes each time you debug an error. Such notes will help you understand the error and Java's error messages, and help you learn how to write programs that do not contain that error in the future. Also, if you have notes on each error you have debugged, when a similar error message occurs again, you have your own notes to guide the debugging of the new error.

The steps in debugging are often:

      identify that there is an error, and what kind of error it is -- either from compiler error messages, or incorrect program behavior
      locate the error -- find out which part of your program has the error. This is a form of detective work, locating the class, method or variable, and eventually statement(s) that are causing the problem
      understand the error -- work out what the problem is, and how changing program statements will solve the problem
      fix the error -- try out alternative changes to the program, recompile (and run if it was a logic error) and test to see if the error has been fixed

What can make debugging difficult is that there may be many error in a program the first time it is compiled, so you may have 5, or 10 or 20 Java error messages. Often a single error can lean to multiple error messages, and the Java compiler may not always correctly suggest the line or method of your program where the error is located. Obviously, if the program has errors in syntax, since it is not a valid set of Java statements, the Java compiler has trouble working out which part of which statement is ungrammatical.

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg