handout #2

CSE143—Computer Programming II

Installing Java

For this course you will need to have a Java compiler and a development environment.  You can use whatever environment you want.  Common choices are DrJava, TextPad, jGRASP and Eclipse.  All of these are installed on the machines in the Introductory Programming Lab on the third floor of Mary Gates Hall and on the computers on the second floor of Odegaard.

Getting the JDK and an IDE on a Windows Machine

Please use Java 6.  You can get Java 6 at this url:

http://java.sun.com/javase/downloads/index.jsp

There are several versions available on this page.  Be sure to follow the link that is labeled “JDK 6 Update 5.”  Install the JDK before you install your IDE.  You can get TextPad from:

http://www.textpad.com/download/index.html

You can get DrJava from (download the “current stable release”):

http://drjava.org/

You can get jGRASP from:

http://jgrasp.org/

You can get Eclipse from:

http://www.eclipse.org/

For Macintosh Users

Any OS X operating system will have Java available automatically.  Unfortunately, TextPad does not run on the Macintosh.  There are several other programming environments that you can choose from.  Most beginners prefer DrJava, which can be downloaded at the following site (download the “stable release”):

http://drjava.org/

TextPad has commands to compile and run a program.  The equivalents in DrJava are the “Compile All” tab and under the Tools menu, “Run Document’s main method.”

Configuring TextPad

TextPad should automatically configure itself for use with the JDK, but there are a few settings you might want to choose.  Go to the “Configure” menu and select “Preferences.”

1.      If you want to see line numbers in the editor (because the Java compiler gives line numbers when it reports errors), select “View” and “Line numbers.”

2.      If you want Java files to automatically open in TextPad, select “Associated Files.”  Under “New extension” select “.java”.  Then click on “Add”.

3.      If you want TextPad to use Java files by default when bringing up a file dialog, select “File Name Filters.”  You will see a list of filters including “.java”.  Select it.  Then click on “Move up” until it is at the top of the list.

4.      You can avoid problems with any classpath setting by setting your own.  Select “Tools” and “Compile Java” and change this setting:

Parameters:

$File

By adding a classpath of “dot” (the dot is required):

Parameters:

-classpath . $File

And under “Tools” and “Run Java Application”, change this setting:

Parameters:

$BaseName

By adding a classpath of “dot” (again, the dot is required):

Parameters:

-classpath . $BaseName

For any of these options to take effect, you will have to select “apply”.

Troubleshooting TextPad and JDK

  1. If you are having trouble installing, you can uninstall either or both programs and start fresh.
  2. Be sure to install Java before TextPad.
  3. If you go into TextPad and find that the Java tools are not on the Tools menu, you should first make sure that Java has actually been installed on the machine.  If it has, then you should be able to go to the Configure menu, select Preferences, select Tools and under the Add menu you should find the option “JDK Tools.”
  4. If you get this error message:

Exception in thread "main" java.lang.NoClassDefFoundError

Make sure that you have successfully compiled the program inside of TextPad (it should beep when you give the command “Compile Java”).  If the program compiles properly and you still get this error, then you probably have a setting for an environment variable called “classpath”.  You can verify this by going to Programs/Accessories/Command Prompt and giving the command “set c”.  This will show you all of your variables that begin with the letter “c”.  If you see a setting for classpath, then that’s your problem.  To fix it go to the "my computer" icon, right click and select properties, select the "advanced" tab, click on the "environment variables" button and find and delete the setting for classpath.

  1. If all else fails, you might need to clean up your registry.  Uninstall both programs.  Then run a program to clean up your registry.  For example, you might go to download.com and download a program like RegistryMechanic.  After you’ve run this program, restart your computer and run the installers again.