CPS313 Handout
18 August 2006
PATH
environment variable
(the name of this variable can be Path
on your computer).
If you would like to see the value of your current PATH
environment variable
type the command path
in the command prompt. This command
shows what your current PATH
is. Alternatively, you can type
echo %PATH%
to see what the PATH
variable is or type set
to see all environment variables. There are cases when you would like
to make permanent additions to the PATH
.
For example, after installing Java, you should add the directory
for the Java commands to the PATH
.
In Windows XP, open the Control Panel
.
Make sure it is in classic mode
.
Click the System
icon, then on the Advanced
tab,
then on the Environment Variables
button (see the figure below).
Edit the
PATH
variable in the System Variables
section
(you might need to edit PATH
both in System Variables
, and in User
Variables
).
The same method works for Windows NT and Windows 2000.
Of course, you can do this only on your home computer (only the system administrators
can edit the system PATH
variable on the computers in the labs).
If you installed the recent release of Java 1.5.0, you will probably add
C:\Program Files\Java\jdk1.5.0_08(or something similar) to your PATH variable. Be very careful with the spacing when you edit the PATH variable. There must be no spaces around the symbols
=
;
%
.jar
).
If the Java compiler will not know where to find them, then you will be able to run
only programs of very limited functionality. But we would like to study Java
using the robot libraries provided with the textbook. For this reason,
we have to make sure that these libraries are accessible to the Java compiler.
To find the current CLASSPATH
environment variable, open
Command Prompt
and type echo %CLASSPATH%
or symply type set
to see all environment variables.
If your machine is running Windows XP, then you
can set globally the CLASSPATH
variable (in the control panel)
following the same sequence of steps as described above for PATH
.
If CLASSPATH
is not listed in the User Variables
section,
then you need to create a new entry by
clicking "New" and then filling in the two entries in the pop-up,
fairly obviously the Variable Name
is
CLASSPATH
and the Variable value
is similar to
C:\Program Files\Java\jdk1.5.0_08\lib\tools.jar;C:\UserName\cps313\Robots\becker.jar;.(Of course,
UserName
should be your name, the path to the Robots
can be different on your machine depending on where your installed libraries
from the CD provided with the textbook). The trailing "dot"
is important: it tells to Java compiler
to use classes (if there are any) from the current
directory. If the CLASSPATH
is already listed,
then you can append the path by clicking on "Edit" and simply tacking the new setting
on the end of whatever is already there (remember to add a semicolon first).
After making your changes, click on the OK button on both the Environment Variables
dialog and the System
dialog.
You will not need to restart your computer, but you will need to restart any applications
which may have read the CLASSPATH
settings before your changes
(including any Command Prompt
windows).
If your machine is running Linux you can test whether your CLASSPATH is already correct with the following command:
echo $CLASSPATHThe output should be similar to one of these
/home/yourUserName/313/Robots:/sw1/jdk1.5.0_06/lib/:.
/home/yourUserName/313/Robots:.
export CLASSPATH=/home/yourUserName/313/Robots:.
bluej
at the command prompt.
hw1, hw2, ...,
for your homework assignments. You probably want to place all those homework directories into another directory such as
/home/yourname/homework/or
c:\homework\You need to create that directory outside BlueJ, with a file manager or the mkdir command in a command shell window. Once you did, do the following steps.
homework
).
In the name field, enter the name of your new project
(for example, hw1
).
public static void main(String[] args) { System.out.println("Hello World!"); }in the class, and save the file (Class Save).
BlueJ will now display your output ("Hello World!") in a terminal window. To close terminal window, click Options --> Close. Once you learnt how to write new Java programs, you can explore how to run example programs from the textbook.
Before you start, customize BlueJ settings. Click Tools-->Preferences-->Libraries. Add path to each library that BlueJ will need to use, e.g.:
C:\UserName\cps313\Robots\becker.jar
In the sequel, it is assumed that you have updated
the CLASSPATH
environment variable as specified above.
If you are not sure about CLASSPATH
, talk to a TA.
For simplicity, in this handout I will discuss only the very first program
from the textbook: DeliverParcel.java
but you can run all other programs following similar instructions.
bluej
program.
Click on "Open in BlueJ" button near the bottom-right corner. A new Project window will open.
jedit
It is free, it is written in java, and it works on all major platforms. You can download a personal copy from http://www.jedit.org/