CS 1110 Introduction to Computing using Java    Fall 2010  
9367 TR 09:05 Hollister B14 Instructors: David Gries and Lillian Lee  
9369 TR 11:15 Hollister B14 Grade: letter or S/U.   Credits: 4
 

DrJava

The Java programming environment used in CS1110 is DrJava, a free Integrated Development Environment (IDE). DrJava was developed by Professor Corky Cartwright at Rice University. DrJava is installed in the ACCEL lab and on most on computers in CIT labs.

If you have problems, and if you have a laptop, the best thing to do is to bring it in to someone to look at.

Table of contents

 

You need a Java virtual machine

You will need the Java software development kit (JDK) from the Sun website. If you have a Macintosh with Mac OS X, you almost certainly have the JDK installed already, so you don't have to download it. If you are using a PC running a version of Windows, chances are that you don't have the JDK yet, and you can download it here.

Several download options will be offered. Choose the JDK 6 Update 7. This give you the Java Runtime Environment (JRE) AND the Java Development Kit (JDK). Read the installation instructions.

The Java Runtime Environment allows you to run Java programs, for example, Java programs that are contained in "jar files".

The Java Development Kit allows you to "compile" Java programs —i.e. to translate them into a "machine language" so they can be run by the Java Runtime Environment.

Downloading DrJava

The easiest thing for you to do is to download this version of DrJava: drjava-stable-20090821-r5004.jar. This version supports Java 5, and Java 6, and we advise using it. Or use the newer Beta version: drjava-beta-20100711-r5314.jar

Alternatively, download the latest version of DrJava from this web page (by clicking the link). Choose a version of DrJava to download. The page will show you several versions of DrJava. Use the Current Stable Release (runs with JDK1.5.0, see above). On a Windows PC, click either on the jar file or on Stable Windows App. You'll be sent to select a location (mirror) from which to download DrJava. You may choose any of the mirrors.

Warning: you may get a dialog saying something about a "JAR archive security check". If you do, just right-click on the DrJava download link and select "Save Link As" (or the equivalent in your browser).

A common DrJava problem: finding tools.jar

If the system tells you that it cannot find a file called tools.jar, you need to select the correct location of that file. On a PC, it is in some place like

C:\Program Files\Java\jdk1.5.0_04\lib\tools.jar

You can also use a desktop tool to search for this file on your computer.

If you didn't set the correct path for the file tools.jar at installation time, set it after installation by going through DrJava's Preferences option. To do so, follow these menu items: Edit / Preferences / Resource Locations / Tools.jar Location. Then type or browse to the correct location.

Running DrJava

There are several ways to run DrJava:

  • From the command line, you can type:   java -jar drjava-stable-20090821-r5004.jar
  • On many platforms, you can simply double-click the jar file to start DrJava.
  • On OS X or Windows, download the appropriate application. You can then run DrJava as a normal application.

If you are on a WIndows System, double-clicking the jar file may not do the right thing. The problem may be that some other application has "stolen" the right to be executed when the jar file is doubleclicked. If you are experiencing this problem, visit the following site and see whether downloading and ioinstalling JarFix will solve the problem:

http://www.softpedia.com/get/Others/Miscellaneous/Jarfix.shtml

Documentation --how to use DrJava

The demos given in class and in the demo sessions should help, if you take notes.

Second, information on using DrJava is in Appendix I of the course text and in Chapter 19 Chapter 19 of the accompanying CD ProgramLive. Watch the ProgramLive lectures! They are short and informative.

Third, here is documention on using DrJava on the web.

Wrong-version error.

Do you get a message that looks like this?

Error: cannot access javax.swing.JFrame
bad class file: C:\Program Files\Java\jre1.5.0\lib\rt.jar(javax/swing/JFrame.class)
class file has wrong version 49.0, should be 48.0
Please remove or make sure it appears in the correct subdirectory of the classpath.

It may mean that your computer has two different systems on it and is an inconsistent state. If your computer has jre5.0, then it cannot use SDK 4.7. Uninstall SDK4.7 and download JDK 5.0 and use its tools.jar.

Can't use a JUnit tester.

One student reported not being able to create and use a JUnit tester; he got the error message: package junit.framework does not exist. To correct this, he did the following.

1. Downloaded file junit-4.1.jar (you can do it by clicking the link).

2. Copied it into C:\Program Files\Java\jdk1.5.0_10\lib. (If you are using a different jdk, then store it in the appropriate place.)

3. Opened DrJava, and hit Edit > Preferences > Resource Locations. In the popup window, in the field Extra Classpath, hit Add then clicked on the junit-4.1.jar file in the lib folder. Then hit Apply > OK.

There may be slight differences depending on your operating system, but this is the general idea.