30
SOME TIPS FOR USING ECLIPSE Creating and running a Java program

Some Tips for Using Eclipse

  • Upload
    palila

  • View
    28

  • Download
    1

Embed Size (px)

DESCRIPTION

Creating and running a Java program. Some Tips for Using Eclipse. Create a New Java Project. Create new Java Project. File/New/Java Project. Create New Project – Give it a name. Name the project. Add a class to the project. Right-click on src . Select New/Class. New project is open. - PowerPoint PPT Presentation

Citation preview

Page 1: Some Tips for Using Eclipse

SOME TIPS FOR USING ECLIPSECreating and running a Java program

Page 2: Some Tips for Using Eclipse

Eclipse Eclipse is an Interactive Development

Environment (IDE) for Java programmers It provides

A project manager to manage all Java projects throughout the semester

An code editor that helps write correct Java instructions (no need for NotePad++)

An execution environment in which one can compile, test, and run Java programs without leaving Eclipse (no more Command Line use)

Page 3: Some Tips for Using Eclipse

Eclipse Workspace An Eclipse Workspace is simply a folder where

all Java projects for the semester will be stored You must remember where it is once you select it It must be a place where you have write access

permissions It must be a place that you can access when you

need it Example: thumb drive, Z:\ drive, portable hard drive, or

cloud storage such as DropBox, OneDrive, Box, etc. Make sure there is enough space in the Workspace to

hold all projects for the semester

Page 4: Some Tips for Using Eclipse

Eclipse

Be sure Java is

selectedJava editor –

type code here

Error messages and running program

output display here

Java projects in your

workspace

Page 5: Some Tips for Using Eclipse

Create a New Java Project

Create new Java Project

File/New/Java Project

Page 6: Some Tips for Using Eclipse

Create New Project – Give it a name

Name the project

Page 7: Some Tips for Using Eclipse

New Project in the Package Explorer After creating a new project as on the previous

slide, it will appear in the Package Explorer column on the left in Eclipse

Project name

Subfolder for .java files

Java library – contains Java API classes such as

String, Scanner, etc.

Page 8: Some Tips for Using Eclipse

Add a class to the project

Right-click on src. Select New/Class

New project is open

Page 9: Some Tips for Using Eclipse

Adding a new Driver Class

Give the class a name

If this is the driver class, add a main method

Make sure this is checked

Click Finish

Assign a package name

Page 10: Some Tips for Using Eclipse

Generated code

Fill in class purpose

Fill in method description

Fill in body of main method

Page 11: Some Tips for Using Eclipse

Add Another Non-Driver class Use same technique without a main method

Class name

hw1

Page 12: Some Tips for Using Eclipse

Add desired attributes

Page 13: Some Tips for Using Eclipse

Generate Default Constructor

Select me

Deselect All to Generate Default

Constructor

Select both

Page 14: Some Tips for Using Eclipse

Default Constructor

Fill in the Description

Fill in the body of the default constructor

Page 15: Some Tips for Using Eclipse

Generate Parameterized Constructor Follow the same process but do NOT deselect

the attributes (fields) All of the following code is generated

Page 16: Some Tips for Using Eclipse

Resulting code so far . . .

Fill in purpose

Fill in parameter details

Page 17: Some Tips for Using Eclipse

Generate Getters and Setters

Select me

Choose those you want

Remember it is not always desirable to have getters and

setters – depends on what needs to remain

private

Page 18: Some Tips for Using Eclipse

Added Getters/Setters

Depending on which are selected in the previous

dialog, a series of getters and setters like this is

generated

Page 19: Some Tips for Using Eclipse

Other code generators Comment out (or uncomment) the

selected lines of code

Add a block of comments to a method you have

written

Generate a toString method for your class

Generate hashCode ( ) and equals ( ) methods

Page 20: Some Tips for Using Eclipse

Renaming an attribute or method Use Refactor / Rename to change the name of

a method or attribute of a class, a local variable, parameter, or even the name of a class.

This changes the name everywhere it appears in the code.

Page 21: Some Tips for Using Eclipse

If you refer to a class that is not in your own project or in any imported class, Eclipse puts a red squiggly line underneath the reference

Which import do I need?

Page 22: Some Tips for Using Eclipse

Let Eclipse help you select the right import Hover the mouse cursor over the underlined

word and a tool-tip will appear; choose what you want from the tool-tip and Eclipse does rest

Click this choice

Page 23: Some Tips for Using Eclipse

Alternatively, do this Press ctrl-shift-O (letter O, not zero) and Eclipse

will fill in the correct import for you or it will list possible imports and let you choose one

Page 24: Some Tips for Using Eclipse

Running a program

To run a program

Right-click on (or in) the driver (code)

Page 25: Some Tips for Using Eclipse

Another way to run the program …Click me

Page 26: Some Tips for Using Eclipse

… from your workspace

Submitting a project

Page 27: Some Tips for Using Eclipse

Project Folder Contents in Workspace

Contains .java files for your

project

Contains the compiled .class files

Page 28: Some Tips for Using Eclipse

The bin folder

This folder contains the compiled .class files. Do NOT submit them.

Page 29: Some Tips for Using Eclipse

The src Folder

.java files for the project

Zip ONLY these files, naming the zipped folder appropriately. DO NOT zip the containing folder

(src or DemoProject1)

If you are using a non-Windows machine such as a Mac or a Linux machine, it is your responsibility to be sure your system does NOT add extraneous folders and other items

to your zipped folder.

Page 30: Some Tips for Using Eclipse

Zipping the files

Use Send To Compressed Folder

or …

… some other archiving tool such as 7-zip

Select the files to be zipped and right-click