Java Reference
In-Depth Information
at AssertDemo.main(AssertDemo.java:15)
$
Debugging with JDB
Problem
The use of debugging printouts and assertions in your code is still not enough.
Solution
Use a debugger, preferably the one that comes with your IDE.
Discussion
The JDK includes a command-line-based debugger,
jdb
, and all mainstream IDEs include
their own debugging tools. If you've focused on one IDE, learn to use the debugger that it
provides. If you're a command-line junkie, you may want to learn at least the basic opera-
tions of
jdb
.
Here is a buggy program. It intentionally has bugs introduced so that you can see their effects
in a debugger:
starting/Buggy.java
/** This program exhibits some bugs, so we can use a debugger */
public
public class
class
Buggy
Buggy
{
static
static
String name
;
public
public static
static
void
void
main
(
String
[]
args
) {
int
int
n
=
name
.
length
();
// bug # 1
System
.
out
.
println
(
n
);
name
+=
"; The end."
;
// bug #2
System
.
out
.
println
(
name
);
// #3
}
}
Here is a session using
jdb
to find these bugs: