COSC 237.002: Introduction to Computer Science II

Spring 2008 - Notes on Using Dr. Java

Course Home Page

Note: if you are having trouble running Dr. Java with Java 6, try the latest release from Rice University's Dr. Java update page. Recent releases seem to have fixed these problems.

Unsurprisingly, the Dr. Java web site is the definitive resource on this software tool. You might find their quick start guide particularly useful.

This document does not claim to or intend to supercede those notes. Instead, the goal here is to provide a short one-page cheat sheet on the Dr.Java features that we'll make the most use of.

The main novel feature of Dr. Java is the interactions pane. If you click on the interactions tab on the bottom pane of the screen, you'll see a Java interpreter window: type any Java code at this line, press return, and the result will be printed on the screen.

Later in the semester, we will use the interactions pane with our own code.

To create a simple (one-claas) java program, follow these steps:

  1. Start Dr. Java
  2. Press the "New" button in the toolbar. This will lead to a blank screen in the right-hand editor pane, and a line labelled "(Untitled)" will appear in the left-hand column.
  3. Type your code into the editor pane.
  4. Save your code in a file. Note that the name of your file must match the name of your class: if you have created a file with class "Foo", the file should be named "Foo.java".
  5. Press the "Compile" button. Error messages will be printed in the "Compiler Output" tab of the bottom pane. If you click on an error message, the cursor in the editor pane will be moved to the appropriate point in your code.

    You might also find it useful to configure Dr. Java to display line numbers. To do this, select "Preferences" from the "Edit" menu. Select the "Display Options" category, and then check the box next to "Show All Line Numbers".

  6. When your code compiles correctly, press "Run" to run it.

Please note that when you open a file, you might need to select "All Files" from the dialog - we will not be using the "dj0" or quot;dj2" extensions that might come up in the file chooser window.

To use the debugger, go to the "Debugger" menu and select the "Debug Mode" checkbox. You can set breakpoints by putting the cursor on a line and selecting the "Toggle Breakpoint on Current Line" choice on the "Debugger" menu. When a breakpoint is set, running the program in debug mode will cause the program to stop when you hit the line with the breakpoint. You can examine the values of any variable at that point in time by typing the variable name into the "watch" matrix in the debugger pane.

If you want to see the system documentation - known as Javadoc - for any of the built-in Java classes, put your cursor over the class name and select "Tools\Open Java API Javadoc for Word under Cursor" The relevant Javadoc will appear in a web page. You can also select the "Open Java API Javadoc" to search the Javadoc for any class.