Skip to content
cdm2012 edited this page Nov 28, 2012 · 25 revisions

This tutorial describes how to create your first Java application using the Eclipse IDE.

In this tutorial, you will be covering the following topics:

  • Download, Extract and Open Eclipse
  • Open a project by copying and pasting source code
  • Open a new project and designate a name for it
  • Refactoring a project name to a desired name
  • Deleting a project from the package explorer
  • Open an existing project from your directory list
  • Edit Source Code, then run new implementation

If you have eclipse already you can skip to section 2, where there is a supplementary video that shows how to use eclipse in action. The tutorial concludes with editing the Java source code from section 2 and running with the new implementation.

1 Download, Extract and Open an Eclipse Version

1.1 Choose your version of Eclipse

There is a student version of eclipse that can be downloaded here. There are other of versions available from the Eclipse organization listed below (CTRL + Click to open all downloads in a new window or tab).

Download Eclipse

The Eclipse Foundation also has a downloads page that covers all the version of eclipse for full scale development, click the image above for details.

1.2 Extract the zip file

After downloading the zip file, extract it with your archive opener (e.g., 7Zip, WinRar, etc.).

Extract Zip containing Eclipse

1.3 Execute the Eclipse Application

Once you can execute the eclipse file, it will prompt you to to select a workspace.

Execute Eclipse

Opening Eclipse you will notice it does not need to install.

1.4 Create an Eclipse workspace

When selecting a workspace, keep in mind that it will hold all of your Java projects.

Create Workspace

2 Paste Java project

2.1 How to paste and generate a Project

The image below is a video that provides an example of how to generate a Java project. (CTRL + Click to open video in a new window or tab).

Lawn Mower Video

The source code from the video can be copied from section 2.2

2.2 Copy source code

Highlight the source code below and copy it (CTRL + C or Right Click)

   public class LawnMower {

       /**
        * The main method is the entry point to Java programs.
        * @param args The arguments sent in from the command line
        */
       public static void main(String[] args) {
           System.out.println("This program creates a yard to a specific size...");

           // create (length, width & area) variables for the yard and house 
           double yardLength = 0.0, yardWidth = 0.0, yardArea = 0.0;
    
           // yardArea and houseArea calculations will be made here
           yardArea = (yardWidth * yardLength);
    
           // formatting for theses values will be output here
           System.out.println("\nThe area of the yard is " + yardArea);
       }
   }

See more on the main method at Oracle's Getting Started Guide.

2.3 Paste the source code

Paste the source code by right clicking in the Package Explorer and pasting the copied content.

Paste Source

2.4 First project created

Your project is now generated for you in the package explorer, with the following project structure.

First Project

2.5 Run the project

Now that you have a project, you can now run your application. To start the Java Application, select your project by right click on it, Then select Run-As-> Java Application . You should get the following result:

   This program creates a yard to a specific size...
   The area of the yard is 0.0

3 Create Java project

3.1 Select Java Project

Select File → New → Java Project and create the Java project "LawnCare". The follow the example below.

Create Project

3.2 Completed Project

After clicking "Finish", you will have the following project structure.

Completed Project

4 Rename (Refactor) Project

4.1 Find the project that is to be renamed

Right Click on the project's name. Then select Refactor → Rename

Refactor Project

4.2 Rename the Project

Enter the new name that you want your project to have.

Rename Project

5 Deleting a project

5.1 Select project to be deleted

Right Click on the project's name, then select Delete.

Select Project

5.2 Delete the project

There will be a prompt for deleting the project where you can delete it from the computer completely.

Delete Project

6 Import an existing project

6.1 Choose import option

Right Click in the Package Explorer, then select Import.

Select Package Explorer

6.2 Select import type

Choose the option to import an Existing Project into Workspace.

Import Option

6.3 Choose the folder

Select the Browse button, then select the project folder that you want to import (e.g., LawnCare).

Choose Folder

6.4 Complete import with correct file path

You will then have the directory selected where your project is, now click Finish to bring in your project under its previous project settings.

Complete Import

7 Running the Application (As a Java Programmer)

7.1 Edit the Source Code

Adding the following changes to the existing source code and you will get an output showing a Yard Area.

   double yardLength = 10.0, yardWidth = 10.0, yardArea = 0.0;

7.2 Run the Project

To start the Java Application, select your project by right click on it, Then select Run-As-> Java Application . You should get the following result:

   This program creates a yard to a specific size...
   The area of the yard is 100.0