Java Reference
In-Depth Information
The name “debugger” Errors in computer programs are commonly known as “bugs.” Thus
programs that help in the removal of errors are known as “debuggers.”
It is not entirely clear where the term “bug” comes from. There is a famous case of what is known
as “the first computer bug”—a real bug (a moth, in fact)—which was found inside the Mark II com-
puter by Grace Murray Hopper, an early computing pioneer, in 1945. A logbook still exists in the
National Museum of American History of the Smithsonian Institute that shows an entry with this
moth taped into the topic and the remark “first actual case of a bug being found.” The wording,
however, suggests that the term “bug” had been in use before this real one caused trouble in the
Mark II.
To find out more, do a web search for “first computer bug”—you will even find pictures of the
moth!
Debuggers vary widely in complexity. Those for professional developers have a large
number of functions useful for sophisticated examination of many facets of an applica-
tion. BlueJ has a built-in debugger that is much simpler. We can use it to stop our program,
step through it one line of code at a time, and examine the values of our variables. Despite
the debugger's apparent lack of sophistication, this is enough to give us a great deal of
information.
Before we start experimenting with the debugger, we will take a look at the example we will
use for debugging: a simulation of an e-mail system.
3.12.1
The mail-system example
We start by investigating the functionality of the mail-system project. At this stage, it is not
important to read the source, but mainly to execute the existing project to get an understand-
ing of what it does.
Exercise 3.33 Open the mail-system project, which you can find in the topic's sup-
port material. The idea of this project is to simulate the act of users sending mail items to
each other. A user uses a mail client to send mail items to a server, for delivery to another
user's mail client. First create a MailServer object. Now create a MailClient object
for one of the users. When you create the client, you will need to supply a MailServer
instance as a parameter. Use the one you just created. You also need to specify a user-
name for the mail client. Now create a second MailClient in a similar way, with a dif-
ferent username.
Experiment with the MailClient objects. They can be used for sending mail items from one
mail client to another (using the sendMailItem method) and receiving messages (using the
getNextMailItem or printNextMailItem methods).
 
Search WWH ::




Custom Search