Setting up your Java development environment
In this section, you'll get instructions for downloading and installing JDK 6 and the current release of the Eclipse IDE, and for setting up your Eclipse development environment.
The JDK includes a set of command-line tools for compiling and running your Java code, including a complete copy of the JRE. Although you certainly can use these tools to develop your applications, most developers appreciate the additional functionality, task management, and visual interface of an IDE.
Eclipse is a popular open source IDE for Java development. It handles basic tasks, such as code compilation and setting up a debugging environment, so that you can focus on writing and testing code. In addition, you can use Eclipse to organize source code files into projects, compile and test those projects, and store project files in any number of source repositories. You need an installed JDK in order to use Eclipse for Java development.
Follow these steps to download and install JDK 6:
- Browse to Java SE Downloads and click the Java Platform (JDK) box to display the download page for the latest version of the JDK (JDK 6, update 21 at the time of this writing).
- Click the Download button.
- Select the operating system platform you need.
- You will be asked for your account username and password. Enter them if you have an account, sign up if you don't, or you can click Continue to skip this step and proceed to the download.
- Save the file to your hard drive when prompted.
- When the download is complete, run the install program. (The file you've just downloaded is a self-extracting ZIP file that is also the install program.) Install the JDK to your hard drive in an easy-to-remember location (such as C:\home\jdk1.6.0_20 on Windows or ~/jdk1.6.0_20 on Linux). It's a good idea to encode the update number in the name of the install directory you choose.
You now have a Java environment on your machine. Next, you will install the Eclipse IDE.
To download and install Eclipse, follow these steps:
- Browse to Eclipse Galileo Sr2 Packages.
- Click on Eclipse IDE for Java Developers.
- Under Download Links on the right-hand side, select your platform.
- Select the mirror you want to download from, then save the file to your hard drive.
- Extract the contents of the .zip file to a location on your hard drive that you'll be able to remember easily (such as C:\home\eclipse on Windows or ~/eclipse on Linux).
The Eclipse IDE sits atop the JDK as a useful abstraction, but it still needs to access the JDK and its various tools. Before you can use Eclipse to write Java code, you have to tell it where the JDK is located.
To set up your Eclipse development environment:
- Launch Eclipse by double-clicking on eclipse.exe (or the equivalent executable for your platform).
- The Workspace Launcher will appear, allowing you to select a root folder for your Eclipse projects. Choose a folder you will easily remember, such as C:\home\workspace on Windows or ~/workspace on Linux.
- Dismiss the Welcome to Eclipse screen.
- Click Window > Preferences > Java > Installed JREs. Figure 1
shows the setup screen for the JRE:
Figure 1. Configuring the JDK used by Eclipse
- Eclipse will point to an installed JRE. You need to make sure you use the one you downloaded with JDK 6. If Eclipse does not automatically detect the JDK you installed, click Add... and in the next dialog Standard VM, then click Next.
- Specify the JDK's home directory (such as C:\home\jdk1.6.0_20 on Windows), then click Finish.
- Confirm that the JDK you want to use is selected and click OK.
Eclipse is now set up and ready for you to create projects and compile and run Java code. The next section will familiarize you with Eclipse.