Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf ·...

15
Eclipse: Starting Start Eclipse as you would any other application On the lab machines: *** You may see the Eclipse welcome page: At the lower right, you can unclick the ”always show welcome ...” if you don’t want to see this every time you start Eclipse 1

Transcript of Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf ·...

Page 1: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Starting

• Start Eclipse as you would any other application

– On the lab machines: ***

• You may see the Eclipse welcome page:

– At the lower right, you can unclick the ”always show welcome ...” if you don’twant to see this every time you start Eclipse

1

Page 2: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Starting (2)

– Click on Workbench at the upper right to start Eclipse

∗ You will be presented with the Eclipse IDE launcher, which displays the defaultworkspace

∗ A workspace is a folder and files (hidden) for managing Java projects

∗ The default is either the last workspace you used, or a generic one created byEclipse (more on workspaces later)

∗ Select a workspace to continue

∗ (See General Notes later for more on work spaces)

2

Page 3: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Layout

• The initial Eclipse environment looks like this:

– The window contains the Eclipse work bench

– The work bench is divide into 5 main areas

∗ Areas display zero or more views

· The Package Explorer view on the left displays project info

· The center region is where the editor view is displayed

· Across the bottom view are several tabs, each of which represents a view

3

Page 4: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Projects

• Java programs are created as projects

– A project is a collection of files and folders

– To create a new project, either

1. Click the Create Java Project icon in the Package Explorer, or

2. Select File/New/Java Project from the tool bar:

4

Page 5: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Projects (2)

– In either case, you’ll be presented with the following:

∗ Provide a project name

∗ You can browse for a particular location (folder), or accept the default

∗ Accept the other defaults

∗ Click Finish

∗ Once you’ve created a project, you will see the Package Explorer updated withthe name of the project (MyFirstProject in the image)

5

Page 6: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Projects (3)

∗ The folders and files created for the project are viewable in the Explorer

6

Page 7: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Programs

• To create a Java program, either

1. Right click on the project name in Package Explorer and select New/Class, or

2. Select File/New/Class from the tool bar

– In either case, you will be presented with the following window:

– The source folder will default to the project you current have open

– You’ll need to provide a name for the class

∗ It should start with a capital letter (more on naming conventions later)

– Under modifiers, click public

– At the bottom are four check boxes, one of which is checked by default

∗ For now, assume you’ll want to check public static void man(String[] args)under Which method stubs would you like to create?

∗ This is required for runnable programs

∗ Checking this will automatically generate some code for you

7

Page 8: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Programs (2)

∗ Your completed window will look something like this:

∗ When completed, click Finish

8

Page 9: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Programs (3)

∗ Package Explorer will be updated and the initial code for your class will appearin an editor window:

· Note that in Package Explorer, src has been expanded to its fullest extent

· The src folder contains your source code (MyFirstProgram in this example),along with the methods it contains (main))

∗ Your are now ready to edit your program

9

Page 10: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Programs (4)

• Writing the program

– Up to this point, you haven’t written any code

– Note that under main is the comment TODO Auto-generated method stub

∗ This simply indicates that here is where you should add your code

∗ (In reality, you can add code anywhere you wish)

∗ After you finish your program, you might have something like this:

∗ Note how the Eclipse editor color-codes various parts of the program

∗ To save, use File/Save (or Save As)

10

Page 11: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Execution

• Running a program

– To execute a program, either

1. Right click on the project in Package Explorer, and select Run As/Java Ap-plication, or

2. Run/Run As/Java Application from the tool bar, or

3. Click the leftmost green circle with a white triangle in the toolbar at top

– When executing, and error messages, output, etc. will appear in a view underthe editor:

11

Page 12: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Execution (2)

– If there is a compiler error, it will be indicated by a red squiggle:

12

Page 13: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: Execution (2)

∗ Clicking on the small red x at the line number will list the nature of the errorand possible fixes:

13

Page 14: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: General Notes

• The Eclipse editor works just like most other editors: copy and paste, drag and drop,etc.

• You can delete a file from a project, but doing so will delete the file from disk if thefile is in the src folder

• You can add a file (created elsewhere) to a project simply by adding it to the srcfolder of the project

– You can also drag a file from any folder onto the project icon in the PackageExplorer to add it to a project

– If such a file is deleted from the project, it will not be deleted from disk

• You can switch workspaces at any time

– From the toolbar, choose File/Switch Workspace

∗ You’ll be presented with a drop down list of available work spaces

14

Page 15: Eclipse: Starting Start Eclipse as you would any other ...djmoon/cs1/cs1-notes/eclipse.pdf · Eclipse: Programs (3) Package Explorer will be updated and the initial code for your

Eclipse: General Notes (2)

– To create a new work space, choose Other

∗ Browse to the directory you want to create the work space in, then type in itsname

• If you lose a view, it can always be recovered using the Window option from the toolbar

• There are many, many options available in Eclipse

– The above overview is exactly that - a brief introduction to the basics

– New features will be introduced as needed

– Many features are for advanced programmers and are beyond the scope of thiscourse

15