Informatics 45 Spring 2010
Setting Up Java and Eclipse 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 on your own machines. What follows is enough information to turn your Windows-based or Macintosh computer into a Java development environment, including Eclipse, 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 and Eclipse on a computer running Windows or Mac OS X.

If you use Linux or Solaris, JDK 6 Update 18 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 and Eclipse 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. 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 Update 18. 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_18

I suggest changing it to the following folder instead:

C:\jdk1.6.0_18

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.

How you get to these environment variables is slightly different on different versions of Windows.

On Windows 7 and Vista, click the start orb in the lower-left corner of the screen, move your mouse over Computer, right-click, and select Properties from the pop-up menu. Click the Advanced System Settings link, then click the Environment Variables... button.

On Windows XP and 2000, right-click the My Computer icon on your desktop and select Properties. Select the Advanced tab. Click the Environment Variables... button.

Once you've brought up the environment variables, find the PATH variable listed under "System variables" and add this to the end of it:

;C:\jdk1.6.0_18\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:\jdk1.6.0_18\lib

If you're using javac and java from the command line, 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, your Java installation is ready to go; you're now ready to proceed to installing Eclipse.


Setting up Eclipse on Windows

Downloading Eclipse

There are several different distirbutions of Eclipse available for download at eclipse.org, each geared toward users with different kinds of needs: Java programming, web development, and so on. So the first thing to know is which distribution to download. For our work in this course, I'm expecting you to use Eclipse Classic 3.5.2. Start by downloading this; be sure that you get the Windows version and not a version intended for a different operating system.

Installing Eclipse

Eclipse is distributed as files in a Zip archive and, unlike most software you install on Windows, has no installation program. Instead, you'll need to do a few things on your own in order to get it installed.

From here, your next step depends on which version of Windows you're running.

On Windows 2000, XP, and Vista. Right-click on the eclipse.exe file you found, select Create Shortcut to create a shortcut to allow you to run Eclipse. Drag this shortcut to your desktop or Quick Launch bar. You can then use this shortcut to open Eclipse any time you'd like.

On Windows 7. Double-click on eclipse.exe to start Eclipse. When asked for a workspace, use the default for now. Once the program starts, you'll see the Eclipse icon show up on your taskbar. Right-click that icon and select Pin this program to taskbar, so that you'll be able to run Eclipse any time you'd like.

That's it! Eclipse is installed and ready to go. Before you get started, note that I've provided an Eclipse workspace for your use in this course; please use that instead of the default, as it's been configured appropriately for the work you'll be doing here.


Setting up Java on Mac OS X

Getting started

First, I'll assume that you're running at least version 10.5 of Mac OS X on a 64-bit Mac. (On Mac OS X, you can find your version number by selecting About This Mac under the apple menu.)

If you're running an earlier version of Mac OS X or are running 10.5 on a 32-bit Mac, there may still be hope available at this link, though you'll need to be comfortable with the Terminal application and getting around your Mac. Note that, if you go this route, you won't need to set up Java FX or NetBeans.

If you're running MacOS 9, it's time to upgrade — probably to a new machine.

Mac OS X 10.5 and 10.6 can be updated to the most recent version of Java, equivalent to JDK 6 Update 17, using one of the following links:

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.


Setting up Eclipse on Mac OS X

Determining which version of Eclipse is right for you

There are three separate downloads of Eclipse Classic 3.5.1 for Mac OS X. The first thing you need to decide is which one of them is right for your machine, which requires you to distinguish between "Cocoa" and "Carbon".

So, assuming that you have a relatively modern Mac, you'll want the 64-bit Cocoa installation of Eclipse Classic 3.5.2

Installing Eclipse on Mac OS X

To install the 64-bit Cocoa version of Eclipse Classic 3.5.2:

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.