|
This book is a tutorial on debugging techniques for both the beginning and intermediate programmer. For the beginning programmer, it is meant to be a companion book to any introduction to programming in Java. The ideal use of the volume is for the student to take it to the computer lab for quick reference when writing and debugging Java programs. For the intermediate programmer, particularly one with some experience in other languages, this guide provides a quick, up-to-speed primer in Java debugging with a series of examples of common syntax and semantic errors and how they can be detected and corrected. The motivation for the book came as a result of innumerable sessions in the computer lab with introductory programming classes at the University of Michigan. Unfortunately, many beginning programmers subscribe to the "programming by blind faith" method, writing a complete program, then hoping that it will run correctly the first time without their doing any intermediate testing, and then panicking when the program crashes or generates bad data that cannot be explained. Each time they come to us with "What do I do now?" we go back to the program together to look over the basic logic and then start inserting traces to check the intermediate results and localize the sources of error. We have come to the conclusion that students need a short, clear debugging guide as a valuable addition to their programming skillssomething they can easily carry with them and that will supplement their textbooks on introductory programming. Chapter 1 is a short motivational chapter that summarizes the sources of errors in computer programs. Chapter 2 describes the most common syntactic and semantic programming errors, with illustrative examples, and explains how to correct them. Chapter 3 shows the student how to use output statements (System.out. println) to trace variables in Java programs and how tracing can easily be inserted into his or her own programs. Several examples are given to illustrate how tracing can help find bugs, especially when a program runs without any runtime errors, but the results are incorrect. Tracing also is useful for finding errors quickly when the program crashes with an error message or just hangs up, leaving the programmer with no option but to kill the program and reboot the computer, over and over, until the bug is found. Chapter 4 illustrates how to use a debugger effectively as a follow-on to the tracing method set forth in Chapter 3. Most compilers come with debuggers now, and students need to be able to use them at some point during their first course in programming and in all subsequent programming courses or work activities. Differences among the commonly used debuggersSun ONE Studio 4, Borland JBuilder 5 Professional, and Microsoft Visual J++are described in detail. We strongly recommend that students learn to use both tracing and the debugger as alternative approaches. The appendices give a summary of the most common bugs found in first Java programs and a checklist of techniques for error detection and prevention. WHO SHOULD READ THIS BOOK? Beginning programmers will like this book because it is a quick read with many simple examples, both numeric and nonnumeric. The book should save them many frustrating hours of debugging time when they apply the tracing and system debugger techniques illustrated in Chapters 3 and 4. Furthermore, anyone using the book can easily read any chapter independently of the others. This independence should also appeal to more experienced programmers who want to review their knowledge of debugging without having to wade through all the fundamentals. Instructors in introductory programming classes will want to recommend the book to their students because it will enable the students to be much more self-sufficient in debugging, greatly reducing the time they need for individual counseling regarding their programs. HOW TO USE THE BOOK Beginning programmers should peruse Chapters 1 and 2 to get an overview of the basic types of errors that programmers make. Chapter 3 has a self-contained discussion of how to use tracing in your programs with a minimum of effort. Chapter 4 can be read later, when you feel that you need more debugging options, especially for larger programs. |