|
Page 1 of 7 The creators of IntelliJ IDEA claim that it's the most intelligent Java IDE out there. IntelliJ IDEA is said to be obsessed with helping developers achieve their best and enjoy their work – consistently, sustainably, over time. There are 1000s of IDEA users who would vouch for that claim and who use IDEA as their preferred IDE rather than NetBeans, Eclipse or any of the other more well known IDE.
Manning recently released the book "IntelliJ IDEA In Action" and the following is an excerpt from the book. It deals with the different kind of errors encountered during development and how best to use IntelliJ IDEA to debug your Java J2EE applications. Although some portions of the excerpt are IntelliJ specific, there's a lot of info about debugging techniques and best practices, which could be useful irrespective of which IDE you use.
Adapted
from: IntelliJ IDEA in Action,
written by Fields, Saunders
and Belyaev
ISBN: 1932394443
Reprinted by permission of
Manning Publications Co.
Debugging
applications
In
this chapter…
* Running
programs under the IDEA debugger
*
Managing
breakpoints and monitoring runtime values
* Working
with threads and the call stack
*
Configuring
the debugger
We’d
all like to think that we never make mistakes. No matter how good a
developer you are, if you write programs then you also write
bugs—it’s an unavoidable fact of life. The question isn’t
whether you’ll need to debug your program, but how you plan on
going about doing it. Many beginning programmers rely on System.out.println() to show them what’s happening inside their program, but more
sophisticated developers understand the benefits of using a debugging
tool. The debugger included with IDEA is a powerful, easy-to-use tool for examining a running program to
determine what’s happening (or not happening) behind the
scenes. After reading this chapter, you’ll never need to rely
on print statements again.
In
this section, we’ll introduce the basic concepts of using a
symbolic debugger to analyze Java programs. If you’re familiar
with using such tools, and you just want to understand how the IDEA debugger works, feel free to skim ahead to the next section.
We
must start with some bad news: A debugger can neither find nor fix
bugs. If it could, we’d all have a lot more free time. No,
you’ll need to find the bugs on your own, either through
testing or pure luck (if you call getting big nasty stack traces
lucky). Although the debugger won’t fix bugs for you, it’s
immensely helpful in tracking them down and understanding what you
must do to fix them.
A debugger is essentially a tool that can tell you what’s
going on inside the Java VM as your program is executing. It lets you start your program and
then walk through it, method by method or line by line, using a
process known as stepping through the code. Executing your
code this way lets you slow things down and monitor your
application’s progress. Each step of the way, you can examine
the state and contents of your application’s variables and
object references. The process can answer burning questions like,
“What is the value of the variable x at the start of this method?”, “Where did that null
pointer exception come from?”, and “How did I get here?”
Once
you suspect a bug is lurking in your code, it’s time to bring
out the debugger. Before you begin hunting down bugs, it’s
important to know exactly what you’re looking for and to have
an idea where you may find it. In the wild, you’ll encounter
several different species of bugs, and the debugger can help you
track down all of them.
<< Start < Previous 1 2 3 4 5 6 7 Next > End >>
|