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 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
You can use either Java 5 or the latest 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.” 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”):
You can get Eclipse from:
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”):
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.”
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”.
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.