Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Use the Java Debugger to Determine the Causes of Errors

Although the Java Virtual Machine frees programmers from many low-level tasks like garbage collection, it can't protect them from mistakes in design and logic. This article explores the Java Debugger, which you can use to trace through a running program and determine the causes of any errors.


advertisement
Debugging is an art that every successful programmer needs to master sooner rather than later. The sad truth is that program bugs appear almost as soon as you start coding. Although a Java compiler always will detect syntax errors, often code that is syntactically correct is not logically correct. These sorts of problems may require the help of a debugger.

Sun's Java Development Kit (JDK) includes a debugger called JDB (Java Debugger), a command-line application under which you can execute the programs you need to inspect. With JDB, you can inspect variables while a program is running, set breakpoints to halt the execution of a program at a certain point, and execute code line by line (known as single-stepping). You can see just how the contents of variables change after each statement of program code, and you can precisely trace the execution of a program--even as it branches to other functions or iterates through loops.

JDB can be used to debug graphical programs and applets as well. An important thing to note, though, is that the programs you debug must be compiled with the -g flag. This causes the Java compiler to insert additional debugging information into the resulting Java class file. (See the Sidebar: Reverse Engineering to Peek at Java Class Source Code for an examination of a command that disassembles Java classes so you can explore the original source code behind it.)



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap