ICS 22 / CSE 22 Fall 2012
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. Despite the fact that this will allow you to do your work at home (or anywhere, using a laptop), be aware that 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 a computer running Windows or Mac OS X into a Java development environment, including Eclipse, at no cost.

What's in this document?

Installing on Windows or Mac OS X 10.7 (Lion)

Before you get started, be aware that this document only describes how to set up Java 7 and Eclipse on a computer running Windows or Mac OS X 10.7 (Lion). To install Java 7 and Eclipse on either of these operating systems, see the applicable section below.

Installing on Linux or Solaris

If you use Linux or Solaris, JDK 7 Update 7 (7u7) can be downloaded from Oracle's Java SE Downloads page, the same way it can for Windows, and can also be downloaded using built-in "package managers." Installation procedures vary from one distribution of Linux to another, but ample documentation is available online.

Installing on Mac OS X versions older than 10.7 (Lion)

If you want to run Java 7 under a version of Mac OS X prior to 10.7 (Lion), there is a version from the OpenJDK group available at code.google.com. The version you want is at this link in particular:

It is a bit tricky to install properly; read the directions of the site carefully.

Setting up Java 7 on Windows

Removing Eclipse and previous versions of Java

First, it's best if you delete Eclipse and uninstall all earlier versions of Java you have installed on your machine. (Use the "Add/Remove Programs" utility in the Windows Control Panel to uninstall Java; delete the "eclipse" folder to delete Eclipse.) Leaving old versions causes setup of Java 7 to be more complicated and problematic, and an old version of Eclipse will not recognize the new version of Java without some rather messy settings changes, whereas installing Eclipse after installing the new Java will cause Eclipse to find and use Java 7.

Getting started

What you'll need to get started is a Java compiler and Java virtual machine, both of which must support Java 7. A great option is to download the Java SE Development Kit (JDK) 7 Update 7 (7u7) from Oracle's Java SE Downloads page. The download is free. It's best to download the JDK and not the JRE — the difference is that the JDK includes a Java compiler (javac) and a variety of other tools for building and packaging-up Java programs, while the JRE (the Java Runtime Environment) includes only the necessary tools to allow you to run Java programs.

Installation: the easy part

The JDK includes an installation program, which places all of the files into the appropriate places and sets up some 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.7.0_07

I suggest changing it to the following folder instead:


(And, of course, you can feel free to install to a drive other than C:, if you have more than one.)

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:


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:


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 4.2. Start by downloading this; be sure that you get the Windows version and not a version intended for a different operating system. Also, be aware that there are a number of different Eclipse distributions that are somewhat different, but you'll be best off with Eclipse Classic 4.2.

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, which you'll find linked from the first project; 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

What you'll need to get started is the latest production (non-beta) Mac version of the Java SE 7 SDK (JDK 7) from Java SE Downloads. Just click on the JDK Download button in the Java SE 7 Update 7 section of the page, accept the license agreement, choose the Mac OS X 64-bit download, and save it.

Be sure you download the JDK and not the JRE! The JDK includes a Java compiler (java), 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.)


The JDK includes an installation program, which places all of the files into the appropriate places and sets up some desktop shortcuts for you. The Mac download is a disk image (.dmg) file. Double-click on it; after a short delay, a (pseudo) disk drive with the same name will appear on the screen; double-click the drive to view its files (if the files are not already shown on the screen). Click on the .pkg (package) file present; to install Java, follow the instructions on the installation screens (it's typically best to just accept the default settings).

When installation completes, you'll be taken to a web page to register your installation; registration is optional.

Checking if you have the latest version installed and selected as default

The Mac will not necessary use the new Java if a previous version was installed. To see what version of Java is being used, open a new Terminal window (by double-clicking on the Terminal application, which is usually found in the Utilities folder inside the Applications folder), then type the following command:

    java -version

If you have the latest version of Java installed, you should see a few lines of text, with the first being:

    java version "1.7.0_07"

If you see that the version number starts with "1.7.0," you're in business! Your machine is ready to go.

If you see a version number that starts with something other than "1.7" (like "1.6" 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 7 (64 bit) is in the list; if so, drag it to the top of the list, making sure that it is the first item. Close the dialog box.

If Java SE 7 (64 bit) is not in the list at all, you'll need to download and install the latest version of Java for OS (as discussed above), then make it the default version (if it is not already) as discussed in this section.

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.

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 two separate downloads of Eclipse Classic 4.2 for Mac OS X, Mac OS X 32 Bit and Mac OS X 64 Bit. All modern Macs are 64-bit machines; you only need the 32-bit version of Eclipse if your machine is on the order of ten or more years old. If you are unsure which version to use, download the 64-bit version and try it.

Installing Eclipse on Mac OS X

To install Eclipse Classic 4.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.