Getting, installing and testing the
Java Programming: Installing the 1
Make sure you have room! (150MB).
Download the appropriate file from java.sun.com:
– Get the JDK Standard Edition 1.4.1
» Java version one is Java 1 and Java 1.1
» Java version two is Java 1.2, Java 1.3 and Java 1.4 (Do not be confused by
Run the file (start the installation). Install somewhere easy to access, I
Download and install documentation
– Java 2 SDK Standard Edition documentation.
– HTML files.
Java Programming: Installing the 2
PATH Environment Variable
To run the tools (compiler, JVM, etc) from
the DOS command line you need to add the
location of the tools to your PATH.
Java Programming: Installing the 3
What is a DOS search path ?
The concept of a search path came from DOS, which inherited from UNIX, etc
The search path is a list of directories that DOS/Windows will search for
You can view the current search path by creating a DOS Prompt (Start |
Programs | MS-DOS Prompt). You will see a DOS prompt that looks
something like :
At this prompt, type the command „PATH‟, and you will see output similar to
– C:\WINDOWS> PATH
We need to place one of the directories that the JDK installation created on
the search path, specify the bin directory. We do this with the command:
– C:\WINDOWS> PATH
Java Programming: Installing the 4
The Java compiler and VM use the CLASSPATH environment variable to
decide where to look for class definitions (Java code).
Very similar to the PATH environment variable in DOS
It is set in a similar fashion.
The CLASSPATH is kept as a DOS environment variable, and can be viewed
with the „SET‟ command. The SET command will display a list of all the DOS
environment variables and their values. The one we‟re interested in is the
– C:\WINDOWS> SET
CLASSPATH=.;C:\j2sdk1.4.0;C:\j2sdk1.4.0\bin ("." is the current directory ).
This CLASSPATH setting has 3 directories: ‘.’ which represents the current
directory (whichever directory you‟re working in right now); C:\jdk1.2, and
Java Programming: Installing the 5
Batch files to source your
You can use your favorite editor to create a txt file in the
root directory called “SETUP4JAVA.bat”
Insert the following lines into this file:
Now, each time you start an MS-DOS Prompt, you only need to type
the single command:
– C:\WINDOWS> C:\SET4JAVA
There are several techniques for setting the search path and class path
permanently. However, these require several steps and can be very
confusing if you don‟t already know how to modify your environment,
so they are not included here. Books on Windows can help you in this
Java Programming: Installing the 6
Typically you need to reboot to have any
changes to the PATH take effect.
Open a MS-DOS prompt window
(command prompt for Win2K and up).
Type "java –version". If you get
"unknown command" or something like
that, your PATH is not right…
Java Programming: Installing the 7
Organizing your work
In general, you do the following:
– create a folder to hold the java code.
» Recommended is creating a directory such as
C:\JAVAPROGS, and then additional directories for each
homework assignment, e.g. C:\JAVAPROGS\HW1, so your
directory structure would look like:
Windows j2sdk1.4.0 JAVAPROGS
Java Programming: Installing the 8
General process in writing Java
– use an editor (notepad will work, but other editors will
work better – check out editplus at www.editplus.com)
to create a Java program. You may use commerial
packages like Visual Café, Jbuilder, and CodeWarrior
is a few to mention. But most of these add in
unnecessary complexity and may introduce a new
source of error which you will not be able to detect.
– compile the program (using javac)
– run the program (using java)
Java Programming: Installing the 9
Example directory Structure of a
The bin directory contains the
java complier and the java \
The includes directory has c j2sdk1.4.0
header file for native code
jre (java runtime) has Command bin include jre lib
executeable for the runtime
and also the Class libraries javac java appletviewer
Lib contains some of the
class libraries used by the run
Java Programming: Installing the 10
Sun "first cup of Java" tutorial
on the web at:
Goes through all the steps, explains how to
resolve common problems
Java Programming: Installing the 11