an introduction to eclipse: quick guide · automatic code generation • eclipse can automatically...

18
An Introduction to Eclipse: Quick Guide Part 1: Getting Started with Eclipse Part 2: Working with Eclipse Useful Online Guides 1 1

Upload: others

Post on 19-Apr-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

An Introduction to Eclipse:Quick Guide

• Part 1: Getting Started with Eclipse

• Part 2: Working with Eclipse

• Useful Online Guides

1

1

Part 1: Getting Started with Eclipse

• Installation & Running

• The User Interface

• Creating a Project

• Creating a Class

• Running a Project

• Navigating Projects

2

2

Installation and Running

• Check java is present and up-to-date: “java -version”

• Download from http://www.java.com/en/download/manual.jsp

• Eclipse Enterprise Edition: http://www.eclipse.org/downloads/

• Unzip and install (win: http://www.7-zip.org/ if needed)

• Run:

• windows: eclipse.exe

• linux / os x: eclipse application

• in the lab: “Root > opt > eclipse-3.7 > eclipse”

3

3

The User Interface

Projects & Classes

Methods & Attributes

Output

Editor

Current Perspective

4

4

Creating a New Project

[right-click]

1 2

3

4

5

5

Creating a Class

[right-click]

can auto-generate main method stub

right-click on the location / package where you want to place this class

1 2

6

6

Running a ProjectIn Eclipse: From command line:

Navigate to ProjectName/bin folder to execute

If your project is packaged then from bin use “java packageName/className” to execute

7

7

Navigating Projects

Selecting an item in one view brings it into focus in the other views

8

8

Part 2: Working with Eclipse

• Creating Packages

• Automatic Code Generation

• Importing System Classes into Projects

• Importing System and User Libraries

• Debugging

• Refactoring

• Creating jars

• Other Useful Features

9

9

Creating Packages1

2

By convention these are named in ‘myPackage’ style, just like classes

If you move classes between packages Eclipse will automatically fix references in other classes, and add import statements where needed

10

10

Automatic Code Generation

• Eclipse can automatically generate constructors and some frequently used methods

• With a class open in the Editor view, use the Source menu item as apt

• Hover on a problem notification to see the Quick Fix options:

• select one, then [control+enter] to invoke

• it can fix import declarations and most simple (non runtime) coding errors

11

11

Importing System ClassesProblem: Types ArrayList and Color are not recognised

Solution: Automatically import the classes

12

12

Importing Libraries

For other libraries we select “Add External Jars” then navigate as apt

This adds a JRE System Library1

2

3

13

13

Debugging

• Red warnings are items that might cause the program to fail to run

• depends if the code is reachable

• Yellow warnings are advisory:

• attributes, methods and imports that are never used

• non-generic Collection types in use:

• such as ArrayList versus ArrayList<Integer>

• Hover on the warning for info, use Quick-Fix where apt

• Runtime errors can be traced from Console to the guilty line of code in Editor:

• click on the error to see the line in focus

• Visit http://www.ibm.com/developerworks/library/os-ecbug/ for a guide to the more advanced inbuilt debugging features

14

14

Refactoring

• Eclipse can rename methods and attributes across the whole scope of a project

• [double-click] on a method or attribute name > Refactor > Rename

• Optionally, old methods can be retained and deprecated:

15

15

Creating Jars

• JAR which includes source code (say for sharing work)

• [right-click] on project

• Export > Java > JAR File > Next

• select ‘Export java source files and resources’

• Name the JAR

• Runnable JAR (source code omitted, but includes externally referenced libraries)

• [right-click] on project

• Export > Java > Runnable JAR File > Next

• Select Launch Configuration: ‘Extract External Files’

• Name the JAR

About Launch Configuration:

Extract: external JARs will be extracted and the class files put/mixed together with your class files

Package: external JARs will remain as JARs in the root of your archive

16

16

Other Useful Features

• To highlight the scope of { } parentheses, [double-click] just after the opening parenthesis

• Add // TODO comments to your code to manage work-in-progress

• View the TODO list using the Task view, NOT the Task List view

• Click on an item to bring it to focus in other views

• File Handling: the default working directory for files is the top level directory for the project, NOT the (src) directory containing the source code

17

17

Useful Online Guides

• Lars Vogel’s Eclipse IDE Tutorial

• http://www.vogella.de/articles/Eclipse/article.html

• David Scuse’s guide to Eclipse 3.1

• http://www.cs.umanitoba.ca/~eclipse/Eclipse3-1.pdf

• Debugging with the Eclipse Platform

• http://www.ibm.com/developerworks/library/os-ecbug/

• Eclipse Current Release User Guide

• http://help.eclipse.org/indigo/index.jsp

• Book/eBook: Eclipse IDE Pocket Guide by Ed Burnette (O’Reilly Publishing)

(which also form the reference materials for this guide)

18

18