Informatics 102 Spring 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?
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 7 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.
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 7. A great option is to download the Java SE 7u3 JDK 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_03
I suggest changing it to the following folder instead:
C:\jdk1.7.0_03
(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:
;C:\jdk1.7.0_03\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.7.0_03\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.7.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, 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
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 officially-released version of Java through the regular Software Updates feature of Mac OS X.
Mac OS X 10.7 ("Lion") does not come with Java installed; you can install it by folloiwng the instructions on the Java for OS X Lion page.
A word about Java 7 (or the lack thereof)
For a variety of reasons, Java releases for Mac OS X tend to lag behind those on other platforms. Sadly, Java 7 has not yet been officially released for Mac OS X at this time. There is a "developer preview" version that is available, but it can be tricky to install (and even trickier to use with Eclipse), so my advice is to install the officially-released Java 6 instead. Almost nothing we do in lecture, and nothing you will need to do for your projects, will require Java 7.
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_22" Java(TM) SE Runtime Environment, Standard Edition (build 1.6.0_22-b04-307-9M3263) Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03-307, mixed mode)
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 and install the latest version of Java for your Mac OS X version, then make it the default version (if it is not already) as discussed above.
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.7.2 for Mac OS X. All modern Macs are 64-bit machines, so unless your machine is on the order of ten or more years old, the right download for you is Mac OS X (Cocoa 64). If you are unsure which version to use, download that; if it fails to work, then delete it and try downloading the 32-bit version, Mac OS X (Cocoa 32), instead. It is very unlikely that Mac OS X (Carbon) will be the right choice for you.
Installing Eclipse on Mac OS X
To install the 64-bit Cocoa version of Eclipse Classic 3.7.1:
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.