Pages

Sunday, August 17, 2014

Java environment

Setting up your Java development                               environment

  • In this section you will get instruction for downloading and installing JDK and using eclipse IDE
  • The JDK include a set of command line tools for compiling and running your code.
  • 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.You need an installed JDK in order to use Eclipse for Java development.

Install JDK 6


Follow these steps to download and install JDK 6:
  1. 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).
  2. Click the Download button.
  3. Select the operating system platform you need.
  4. 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.
  5. Save the file to your hard drive when prompted.
  6. 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.

Install Eclipse

To download and install Eclipse, follow these steps:
  1. Browse to Eclipse Galileo Sr2 Packages.
  2. Click on Eclipse IDE for Java Developers.
  3. Under Download Links on the right-hand side, select your platform.
  4. Select the mirror you want to download from, then save the file to your hard drive.
  5. 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).

Set up Eclipse

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:
  1. Launch Eclipse by double-clicking on eclipse.exe (or the equivalent executable for your platform).
  2. 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.
  3. Dismiss the Welcome to Eclipse screen.
  4. Click Window > Preferences > Java > Installed JREs. Figure 1 shows the setup screen for the JRE:
    Figure 1. Configuring the JDK used by Eclipse
    Correct JDK 6 JRE setup in Eclipse.
  5. 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.
  6. Specify the JDK's home directory (such as C:\home\jdk1.6.0_20 on Windows), then click Finish.
  7. 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.

The Eclipse development environment

The Eclipse development environment has four main components:
  • Workspace
  • Projects
  • Perspectives
  • Views
The primary unit of organization in Eclipse is the workspace. A workspace contains all of your projects. A perspective is a way of looking at each project (hence the name), and within a perspective are one or more views.

The Java perspective

Figure 2 shows the Java perspective, which is the default perspective for Eclipse. You should see this perspective when you start up Eclipse.
Figure 2. Eclipse Java perspective
The Eclipse IDE startup screen shows a default Java perspective.
The Java perspective contains the tools you need to begin writing Java applications. Each tab shown in Figure 2 is a view for the Java perspective. Package Explorer and Outline are two particularly useful views.
The Eclipse environment is highly configurable. Each view is dockable, so you can move it around in the Java perspective and place it where you want it. For now, though, stick with the default perspective and view setup.

Create a project

Follow these steps to create a new Java project:
  1. Click on File > New > Java Project ... and you will see a dialog box open like the one shown in Figure 3:
    Figure 3. New Java Project wizard
    New Project wizard dialog box.
  2. Enter Intro as the project name and click Finish.
  3. If you want to modify the default project settings, click Next. (This is recommended only if you have experience with the Eclipse IDE.)
  4. Click Finish to accept the project setup and create the project.

No comments:

Post a Comment