ICS 22 / CSE 22 Fall 2008
Setting Up Java On Your Computer
A word of warning
One of the advantages of programming in Java is that it's possible to set up your own computer as a Java development environment easily and cheaply. On the other hand, working in the lab has some genuine benefits, particularly for those of you who are fairly new to programming and/or fairly new to UCI. In the lab, you'll find that help is more readily available when you get stuck, that your machine setup will generally be stable and designed well for the task of working on your assignments, and that you're free from the distractions of your home.
Nevertheless, I'm aware that many of you, either out of want or need, will choose to do some percentage of your work at home. What follows is enough information to turn your Windows-based or Macintosh computer into a Java development environment at little or no cost.
What's in this document?
Before you get started, be aware that this document only describes how to set up Java on a computer running Windows or Mac OS X.
If you use Linux or Solaris, JDK 6.0 Update 7 can be downloaded from java.sun.com, the same way it can for Windows; sadly, you're on your own as far as installing it goes, though there is ample documentation available on the web.
The document is broken into separate sections detailing how to install Java on Windows and on Mac OS X; these sections follow.
Setting up Java on Windows
Getting started
What you'll need to get started is a Java compiler and Java virtual machine, both of which must support Java 6.0. A great option is to download the Java SE 6 JDK (JDK 6) from java.sun.com, the latest version of which is JDK 6.0 Update 7 (6u7). The download is free! Be sure you download the JDK and not the JRE! The JDK includes a Java compiler (javac), a Java virtual machine (java), and all of the standard Java library components — in other words, everything you need to write Java programs in a wide variety of problem domains, and more than enough firepower for the assignments we'll be giving you. (The JRE is the Java Runtime Environment, which includes the necessary code to allow you to run Java programs, but not to write and compile them!)
Installation: the easy part
The JDK includes an installation program, which places all of the files into the appropriate places and sets up some desktop shortcuts for you. However, after running the installation program, you still won't be able to execute javac or java, without making a couple of modifications "under the hood" of your system.
When asked what folder you should install the JDK into, the default will be:
C:\Program Files\Java\jdk1.6.0_07
I suggest changing it to the following folder instead:
C:\jdk6.0_07
The reason for this suggestion is that the next steps in the installation process will be simpler if the folder you choose has a shorter name that, importantly, has no spaces in it.
The (not all that) hard part: PATH and CLASSPATH
You can execute programs from a Command Prompt by simply typing their names, such as javac or java. But there's a catch: Windows has to know where it can find these programs. This is the job of the PATH environment variable. PATH is a list of folders, separated by semicolons, in which Windows will look for a program whenever you try to execute one.
Similarly, whenever the Java compiler or Java virtual machine need to be able to use a Java class (such as when you import a class from the Java library), the compiler or virtual machine needs to be able to know where to find it. This is the job of the CLASSPATH environment variable. CLASSPATH is a list of folders, separated by semicolons, in which the Java compiler or virtual machine will look for a Java class whenever it's trying to find one.
So, to make the JDK work, you have to modify the PATH and CLASSPATH environment variables on your system, so that Windows will be able to find javac and java, and so that javac and java will be able to find all of the necessary Java classes.
Right-click the My Computer icon on your desktop and select Properties. Select the Advanced tab. Click the Environment Variables... button. Under "System variables," find the PATH variable and add this to the end of it:
;C:\jdk6.0_07\bin
Then find the CLASSPATH variable. If it doesn't exist (and it probably won't, if you've never used your system to develop Java code), click the New... button, specifying CLASSPATH as its name, and the following value:
.;C:\jdk6.0_07\lib
You will need to bring up a new Command Prompt window, in order for these changes to take effect.
That's it!
At this point, you should be good to go. Enjoy!
Setting up Java on Mac OS X
Getting started
First, I'll assume that you're running the latest version of Mac OS X (10.5, as of this writing). If you're running an earlier version, it's time to upgrade; the current Java won't run on your machine. (On Mac OS X, you can find your version number by selecting About This Mac under the apple menu.) If you're running MacOS 9, it's really time to upgrade — probably to a new machine.
Currently-updated installations of Mac OS X (10.5) should include JDK 6.0 Update 5, which is the latest version available for Mac. If you find that your machine does not have Java installed, Java downloads for Mac OS X are available at this link.
Finding help if you get stuck during this process
Because I'm not a Mac user, I unfortunately won't be able to help if you get stuck while following this process. If you're having trouble, I'd encourage you to seek help from knowledgeable friends and/or other students.
Checking if you have the latest version installed and selected as default
The first thing you should do is to check if you have the latest version of Java installed. To do so, first open a new Terminal window (by command-N or choosing New Shell on the File menu); then type the following command:
java -version
If you have the latest version of Java installed, you should see something like the following:
java version "1.6.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0_05-09)
Java HotSpot(TM) Client VM (build 1.6.0_05-09, mixed mode, sharing)
If you see that the version number starts with "1.6," you're in business! Your machine is ready to go.
If you see a version number that starts with something other than "1.6" (like "1.5" or "1.4"), you'll need to continue following these instructions.
Checking what version of Java is the default on your machine
Mac OS X is perfectly happy to let different versions of Java coexist on your machine; installing a newer version of Java doesn't remove any earlier versions and doesn't even make the newer version the default Java on your machine. So, the next step is to see if the latest Java is installed but is not the default.
Launch Applications, then select Utilities, then Java, then Java Preferences. Click on the General tab, if it's not already selected. In the Java Application Runtime Settings box, see if Java SE 6 (64 bit) is in the list; if so, drag it to the top of the list, making sure that it is the first item. Click on the Save button in the lower right and quit.
If Java SE 6 (64 bit) is not in the list at all, you'll need to download the latest version of Java from this link and install it, then follow these instructions again to make it the default version.
After you've set Java SE 6 (64 bit) as your default version of Java, run the instructions in the section titled "Checking if you have the latest version installed and selected as default" to verify that the appropriate changes have been made and the latest version of Java is installed and selected as your default installation of Java.
What else you'll need to know
If you're used to the Mac environment and not used to Unix or other command-line processing systems, you'll want to learn at least a little Unix so you can find your way around. Those details are available elsewhere.