12
Spring 2016/2017 Computer Science Department TA Rena Alzaid How to use the Eclipse IDE for Java Application Development Pre-work: 1. Download and install Java JDK. Make sure to choose the appropriate link for your computer. (http://www.oracle.com/technetwork/java/javase/downloads/jdk8- downloads-2133151.html) 2. Download Eclipse Neon.2 (4.6.2) Development Environment. Make sure to choose the appropriate eclipse program link for your computer system. (https://eclipse.org/downloads/eclipse-packages/). 3. Run the eclipseinstaller by running the .exe file you downloaded in step 2. Choose Eclipse IDE for Java Developers then choose the installation folder you would like the program to be stored in and click INSTALL. Continue the installation process. The program will be installed on your system. 4. Create a folder on your desktop named MyWorkSpace. This folder will store all of your Java projects. 1. The first time you start Eclipse, it will ask you to specify a default workspace. This is where files are created for you. You need to remember this so that you can find your files to submit. Choose the MyWorkSpace folder you created in step 4 of the pre- work as your default workspace by clicking on Browse and selecting the folder MyWorkSpace from your desktop. Click Browse to choose the location of your default folder. Click to use the same folder each time eclipse is started

How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

Spring 2016/2017 Computer Science Department TA Rena Alzaid

How to use the Eclipse IDE for Java Application Development

Pre-work:

1. Download and install Java JDK. Make sure to choose the appropriate link for

your computer. (http://www.oracle.com/technetwork/java/javase/downloads/jdk8-

downloads-2133151.html)

2. Download Eclipse Neon.2 (4.6.2) Development Environment. Make sure to

choose the appropriate eclipse program link for your computer system.

(https://eclipse.org/downloads/eclipse-packages/).

3. Run the eclipseinstaller by running the .exe file you downloaded in step 2.

Choose Eclipse IDE for Java Developers then choose the installation folder you

would like the program to be stored in and click INSTALL. Continue the

installation process. The program will be installed on your system.

4. Create a folder on your desktop named MyWorkSpace. This folder will store all

of your Java projects.

1. The first time you start Eclipse, it will ask you to specify a default workspace. This is

where files are created for you. You need to remember this so that you can find your

files to submit. Choose the MyWorkSpace folder you created in step 4 of the pre-

work as your default workspace by clicking on Browse and selecting the folder

MyWorkSpace from your desktop.

Click Browse to

choose the location

of your default

folder.

Click to use the same

folder each time

eclipse is started

Page 2: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

2 | P a g e

2. Eclipse then comes up with a Welcome screen. This screen provides information for

new users, examples and tutorials. Click on the “Workbench” arrow icon, which will

start the workbench portion of eclipse. After that you will see the Eclipse main

window, also called the workbench.

This is the startup screen with no projects or files active.

Workbench

Go to the workbench

This will be the editor window

Drop down menus for various functions. You

can also use the icons once a project is created

Icons can be

used in place

of menu items

Page 3: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

3 | P a g e

Either the menu items listed across the top of the screen or the icons can be used to:

Create projects Create classes Execute them.

Since no projects currently exist, most of the icons on the toolbar are greyed out.

3. Eclipse is a project oriented integrated development environment (IDE). In other

words, you must create a project in order to run your files. Each Java program we

will write will be stored in its own project. From the Eclipse menu bar at the top of

the screen, choose

File > New > Java Project…

or

This opens the New Java Project dialog box. In this box, you should enter a unique

project name (i.e. you cannot have two projects with the same name).

You can also choose

Java Project

from the small arrow at this icon.

Page 4: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

4 | P a g e

4. To add files already stored, go to step # 8, otherwise continue reading:

After creating the project, you will see the screen below. More of the icons are

now available. You now need to Create a class. The class will contain your

application. There is more than one way to do this. First make sure the name of

the project folder is highlighted in the Package Explorer tab (located on the left

hand side of the screen) then do one of the following to create the class:

a) File > New > Class

b) Right click the project folder from under the Package Explorer tab located on

the left hand side of the screen, choose New > Class

c) Use the New Class icon.

You should type a unique name

here for the project you are

creating

Use default JRE

should be chosen here to make

sure it uses the JRE you recently

installed

Make sure to check this box so

your files will be stored in a

separate folder located in your

default folder. The project

folder will have the same

project name you chose.

This should be chosen to store all

the files for the project in one

folder. This is better to use when

trying to find your files quickly for

submission since they will all be

stored in one location.

Click Finish to continue with

the next step

This should be chosen to store the

program files for the project in

separate folders. This is better to

use if you prefer to organize your

files. Your source files will be

located in the folder src.

Page 5: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

5 | P a g e

5. Now a New Java Class dialog box will appear. You will need to provide the

following:

Choose File > New > Class

From the menu

Or choose the New Class icon

Or right click the project folder and choose

New > Class

The file name. The name should

be the same name as the class.

Leave empty

Should be public

Check this box if

your class

requires a main

method

Click Finish to create the new

class

Page 6: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

6 | P a g e

6. Having created the Java class, the window will change to the above. The edit pane

will have a predefined class and main entry point.

Within the Eclipse edit pane, please replace the following Java source code line

// TODO Auto-generated method stub

with

System.out.println("Hello World!");

If you make any syntax errors, you will see a red X appear to the left of the line with

the error. Hover over the X with the mouse to get more information about the error if

you need help. For example, if you leave the semicolon ( ; ) out from the code above,

you will see something like this:

Edit pane The file containing the class you created. The file name is the

same name as the class and has the “.java” extension

Problems pane. The compiler will list syntax errors here. You can click on the error message

and the edit window will move the cursor to that point.

Error

location

Error position

Page 7: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

7 | P a g e

Note: All errors must be fixed before you can run the class. The error indication will

disappear once the error is fixed

7. Periodically save your work using File > Save from the menu or by clicking on the

floppy disk icon.

Eclipse will automatically compile the source code when you save the file and any

syntax errors will be noted in the Problems pane.

Note: If your Java program requires more than one class, you can add additional classes

to your project by repeating the instructions starting from step 5. Make sure only one of

the classes contains a main method if your project contains more than one class! When

you are ready to run your program, continue with the step 10.

Hover over the X to get

more information about

the error

Error in the program. Click on the error to go to the

line containing the error. Fix all the errors to be able

to run the program

Page 8: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

8 | P a g e

8. If you are creating a project using Java files that are already stored in a folder for

you, right click the project name and choose import.

Click import to add

files already stored.

Choose File System from the

General folder in the import

dialog box

Click Next

Page 9: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

9 | P a g e

Another, easier way to do this is to drag and drop the file into the (default package)

of the project you wish to add the file to.

Click Browse to choose the folder

location containing your files

After selecting your

folder, click OK.

Place checks on the files you

wish to add to your project

Click Finish once you are

done

Page 10: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

10 | P a g e

9. If your program has no syntax errors, you can run your program as follows:

Highlight the Java file that has the main

method in it.

Choose

Run > Run As > Java Application

Page 11: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

11 | P a g e

Or you can right click the file, then

choose

Run As > Java Application

Or you can click the Run icon

Page 12: How to use the Eclipse IDE for Java Application Developmentportal.cs.ku.edu.kw/~rena/141/eclipse/How to use... · 3. Eclipse is a project oriented integrated development environment

12 | P a g e

10. You can remove files from a project by right clicking on the file and choosing

Delete. The same can be done to remove projects from the workspace.

Written by TA Rena Alzaid

The output of your program will be displayed in the

Console pane.

Output