handout #2

CSE142—Computer Programming I

Installing Java

For this course we will be using a combination of two software products: the Java tools from Sun Microsystems and a simple editor called TextPad.  The Java tools are known as the JDK (Java Development Kit), which is distributed freely by Sun Microsystems.  It includes a Java compiler and a Java runtime system.  TextPad is a shareware text editor.  The Computer Science and Engineering Department has purchased a site license for the use of TextPad to support CS instruction.  Both of these have already been installed on the machines in the Introductory Programming Lab on the third floor of Mary Gates Hall.

Getting the JDK and TextPad on a Windows Machine

We are using the latest version of the Java compiler known as version 1.5 or “Java 5.0”.  You can obtain a copy at this url:

http://java.sun.com/j2se/1.5.0/download.jsp

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

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

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 be automatically opened by 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 this filter.  Then click on “Move up” until it is at the top of the list.

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.

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 (be sure to download the “stable” version):

http://drjava.org/

To be able to use the latest Java (Java 5.0), you have to have the Tiger operating system (OS X 10.4 or higher).  If you have an older operating system like Panther, you might want to consider buying the upgrade ($69 at the university bookstore, which is a discounted price).  Even with Tiger, you won’t get the new version of Java automatically.  You have to go to this web page to download it:

http://www.apple.com/support/downloads/java2se50release1.html

This still isn’t enough because you have to run a program to update the default version of Java.  The utility can be found in the folder /Applications/Utilities/Java/J2SE 5.0/.  Make sure that you list Java 5 at the top of the list for which Java to use.