|
written by Martin Stepp (Lectura email ID: stepp),
UA CS grad student and former section leader
written for use with Windows operating systems, Java SDK v1.3.1 and TextPad v4.5, or newer
The University of Arizona
Computer Science 127a, 127b, 227, and 335
Here is a step-by-step guide for setting up your home computer to do your homework for
C SC 127a, 127b, 227 and 335, and any other class that uses Java and TextPad for its homework
assignments. Please remember that some classes do not officially endorse working at home, so
if you do the assignment at home instead of in the lab, you may still have to go to the lab
in order to turn your program in. Also, generally you are responsible for making sure your program
works on the school's provided environment; it is recommended that you test all programs in the
lab before turning them in.
Please note: If your course textbook comes with a CD with software on it,
these directions do not apply to the versions of JDK and TextPad that come on that CD!
Please also note: JDK and TextPad are constantly being updated. If the
screenshots shown say j2sdk1_3_0-win.exe but you find that the actual file
you download is named j2sdk1_3_1-win.exe or something, that probably just
means a newer version of the program is out. I'll trust that you are intelligent enough to
make the mental adjustment to what you see in my screenshots.
(1) Download and Install Java 2 Software Development Kit (also called "Java 2 SDK" or just "JDK")
The Java 2 Software Development Kit is the compiler you'll need to use to turn your Java
programs into computer code and to make them run. You will need to download it from Sun's
Java web site, and then install it onto your computer.
Once you're at Sun's Java site (there's a link to it below), in the Download J2SE TM v 1.3.1_04 section, under Windows (all languages), click the DOWNLOAD link in the SDK column. It is important that you do not accidentally click the link in the JRE column, because the JRE is a different program that does not include the Java compiler you need.
Next, accept Sun's license agreement, then choose a download site. It's fine to choose the first one from the list.
This may take several hours if you're using a 56K modem, or it may finish really
quickly if you're on something faster like a dorm connection. Either way, when it's done,
it should make a file called something like j2sdk-1_3_1_04-windows-i586.exe on your hard
drive.
|
Once the j2sdk1_3_0-win.exe file is done downloading, run it
to install the program. Go to the folder where you saved it and double-click the file to
run it, like in the picture on the left. It's very important that
you RUN the file; JDK won't actually be installed on your system until you run the j2sdk-1_3_1_04-windows-i586.exe
file (pictured here with a different name because the picture is out of date).During the installation, you can just hit OK or Next
at all the screens; you don't need to reconfigure anything. The default options are fine. |
Got all that? Please do it for yourself now; go to Sun's Java site by clicking the link
below. If you have trouble, you may also want to visit Sun's Java Installation Help page,
which can help you make sure you have JDK installed properly.
Java 2 SDK Download Page
Java 2 SDK Installation
Instructions Page
(2) Modify your path (OPTIONAL)
You may now modify your system's path so that it knows how to find your Java
Development Kit. This step is optional, and may be skipped if you do not plan to
run java commands from a DOS Prompt or command line. If this is the case and you wish
to skip, jump down to Step 3 below.
The way to set the path is different depending on whether you have
Windows 95/98/ME or if you have Windows NT/2000/XP. Follow the appropriate
directions for your operating system.
Windows 95/98/ME:
Edit your C:\autoexec.bat file by clicking
Start -> Run...
and then typing in
notepad C:\autoexec.bat
in the box that pops up.
 
(You may not have an autoexec.bat file yet, in which case Notepad will ask
if you want to create this file. Choose yes.)
Once you're in Notepad editing autoexec.bat, please add these two lines to
the bottom of it. You may want to copy-and-paste them to make sure you type them exactly
right.
NOTE: Because JDK's version keeps changing, the folder you installed JDK into might not
be named C:\jdk1.3 . If this is the case, substitute your JDK's folder in the place
of C:\jdk1.3 below.
SET PATH=%PATH%;C:\jdk1.3\bin
SET CLASSPATH=.

If your autoexec.bat already has stuff in it, don't remove the old stuff;
put these new lines at the bottom. Save the file, exit, and restart the computer. Then
come back to this page and proceed to Step 3.
Windows NT/2000/XP and higher:
Right-click My Computer and choose Properties. This will open the system
properties box. There are many tabs to click on. Find the section about
Environment Variables. Set the variable PATH to include the bin subfolder
of your JDK directory.
That is, if for example your JDK was installed into the folder
C:\jdk1.3, then you would append a semicolon and C:\jdk1.3\bin
to your PATH. (Substitute your JDK folder's name if it is different.) Also add
an environment variable CLASSPATH whose value is set to a period, like shown in the
text above.
(3) Download and Install TextPad
This part is pretty easy. Click the link below to go to TextPad's download site. I
recommend that you choose to download the English edition by HTTP. When you're through,
press your browser's Back button to come back here. It'll look like this:

TextPad Download Page
Download and run the file to install TextPad to your computer. You don't need to
change any of the default options. Just click Next or OK
until it's done.
Please note: It is important that you install JDK before you start
installing TextPad! If you don't do it in that order, then TextPad won't detect that you
have JDK, and it won't add its Tools like Compile Java, Run Java Application, et cetera.
(4) Test Everything to Make Sure We Did It All Right
Let's see if we can compile a sample program to make sure we did everything right.
Download the following small program to your hard disk and open it up with TextPad.
You can do this by right-clicking it and choosing "Save Link As..." (Netscape)
or "Save Target As..." (Internet Explorer), and saving it to your hard disk with
the filename "Test.java" . For best results, put quotes
around the file name so that it will not add extra characters. Web browsers have
been known to rename files with incorrect names, like Test.java.txt. Remember that the file MUST be named Test.java, with only the T
capitalized (Java is case-sensitive), for this to work.
 Test.java
Be careful; it's easy to save the file and think you named it Test.java correctly, but
mistakenly give it the wrong filename, such as Test.java.txt . This is because
Windows sometimes doesn't obey when you tell it what filename you wanted to save. Here's
an explanation about Windows and file names:
In Microsoft Windows, when you create a new file and then save it for the first
time, Windows may add the .txt extension to the filename. Therefore, a file you name
Test.java is saved as Test.java.txt. It's important to note that you cannot see the .txt
extension unless you turn on the viewing of file extensions (in Windows 98, click Start
-> Settings -> Folder Options... -> View , then uncheck "Hide
file extensions for known file types"). To prevent the .txt extension, enclose the
filename in quotation marks, such as "Test.java", when typing it into the Save
As dialog box. Or, if you've already named the file incorrectly and want to rename
it, open the file in TextPad and click File -> Rename... to change its name.
Once you've downloaded the file, open it using TextPad and click Tools ->
Compile Java.
If you don't have a Tools -> Compile Java command, look below for help.

If it worked, you'll just see a delay for a few seconds and then it'll return to the
screen you were at before. It won't display any kind of messages on the screen. Once it's
done, click Tools -> Run Java Application.
If you followed all this mess of directions correctly, you should see something like this:

If you got through all that, CONGRATULATIONS! If not, please read the problem Q/A
section below. If none of those problems matches yours, or if you still can't find a
solution, please send mail to your section leader, head TA, and/or instructor. I personally
will be unable to help you with Java / TextPad issues, because I am no longer affiliated
with the University of Arizona.
If you're going to email the TAs or teacher, please include a clear, detailed description of exactly
what the problem is. If possible, please tell me what operating system you use and
what versions of JDK and TextPad you tried to install. It would also help if you
pasted into your email a copy of the contents of your C:\autoexec.bat file so they can check
that. Thanks!
PROBLEMS YOU MIGHT HAVE
· When I try to compile, I get a "Cannot find C:\WINDOWS\SYSTEM32\javac.exe" error
This is usually caused if you accidentally downloaded the Sun JRE instead of the Java 2 SDK. You may
have clicked the wrong link when you went to Sun's download page. Try repeating the steps 1-3
by re-downloading (making sure it is the SDK and not the JRE), re-installing TextPad, and attempting
to compile it again.
. My code won't compile, and I get a message like this:
C:\My Documents\cs127a_prog1\Greetings.java:7: cannot resolve symbol
symbol : class TextReader
This problem means that either you didn't download TextReader.java (which some courses use in
their programs) onto your computer, or that the Java compiler can't find it. If you did
download it, chances are that you put it in the wrong folder. The TextReader.java file
(just like any supporting Java class file you'll use) must be placed into the same folder as your
program. So if your program is in the C:\My Documents\cs127a_prog1 folder, your
TextReader.java should go there as well. If you're positive that the files ARE in the same folder,
but it still doesn't work, there might be some problem with your CLASSPATH as described previously.
· The Test.java program compiles fine, but when I try to run
it, I get a "NoClassDefFound: Test" error
This problem can be caused if you didn't properly set up your path as outlined above; you
may not have properly modified your autoexec.bat file. If you skipped Step 2, this is a sign
that you may need to go back and do it after all. Please re-read and double-check
Step 2 to make sure you did it right. Remember that you have to restart for it to take
effect. If you have your path or classpath set improperly in autoexec.bat, it can
confuse JDK so that it can't find your program; that's what causes a NoClassDefFound
error. Also, if you run Windows 2000 and accidentally followed the Windows 95/98
directions, the setup may not work. The autoexec.bat file isn't used in Windows
2000, so it won't fix things for you to modify autoexec.bat in Win2000. You have to
set the PATH environment variable instead, as described in Step 2 above.
· I get output that looks something like this:
javac: invalid argument:
C:\WINDOWS\Desktop\Test.jav
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-O Optimize; may hinder debugging or enlarge class file
...
Tool completed with exit code 2
This message appears when the Java program compiler doesn't like your program that
you're trying to compile, because it has an invalid file name. Your file is probably
not named Test.java ; it is probably named Test.java.txt or Test.jav or something like
that. In TextPad, while editing your program, click File -> Rename... and
double-check the file's name. If it's not Test.java , change it and try again.
· I don't see the JDK Tools in my TextPad
If you installed TextPad and you don't see the JDK Tools, such as Compile Java, Run Java
Application, et cetera, then you probably did one of the following things:
- Forgot to install JDK, or
- Installed TextPad before you installed JDK, or
- Tried to use the old versions of TextPad and JDK on your textbook's CD, which don't work
with these directions
Remember, just because you've downloaded the j2sdk1_3_0-win.exe
file, doesn't mean that JDK is installed on your computer. You have to run the file
as well, as outlined in Step 1 above.
If you are sure that you did install JDK, then you may have installed it after installing
TextPad by mistake. You must have JDK already installed BEFORE you begin to install
TextPad. If not, then TextPad doesn't detect JDK's presence, so it doesn't add its JDK
Tools.
If this is the case, you can just manually add the JDK Tools yourself. In TextPad,
click
Configure -> Preferences -> Tools -> Add -> JDK Commands
This should add them for you. If you click as far as the Add button and don't see the
option for JDK Commands, then your JDK installation is messed up and you should try it
again.
· My program prints out really tiny!
If your programs print out in a pint-sized font, in TextPad, click Configure, Preferences...,
then double-click Document Classes, then Java, and lastly click Font.
Click the circular button labeled Printer to specify that you want to change the
font used for printing out. Now in the list of fonts, choose a font other than the one
it's currently set to. (Just changing the font size won't fix the problem; you
actually have to choose a different font.) Click OK to save your changes.
(This semester, electronic turn-in will be used, so you may not have to print things out
much anyhow.)
· I'm working from the school's lab, and I've lost the JDK
Commands in TextPad
Contact lab staff by sending email to lab@cs.arizona.edu
and telling them about the problem. They will help fix it for you. (Please only contact
lab staff about school lab related issues, not issues if you're working from home.)
Last modified on Wednesday, August 28, 2002
back to Martin's CS site

|