introduction to eclipse csc 216 lecture 3 ed gehringer using (with permission) slides developed...

39
Introduction to Introduction to Eclipse Eclipse CSC 216 CSC 216 Lecture 3 Lecture 3 Ed Gehringer Ed Gehringer Using (with permission) slides developed Using (with permission) slides developed by— by— Dwight Deugo ([email protected]) Dwight Deugo ([email protected]) Nesa Matic ( Nesa Matic ([email protected] ) ) Sreekanth Konireddygari (IBM Corp.) Sreekanth Konireddygari (IBM Corp.)

Upload: wilfrid-oliver

Post on 31-Dec-2015

222 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

Introduction to EclipseIntroduction to EclipseCSC 216CSC 216

Lecture 3Lecture 3

Ed GehringerEd GehringerUsing (with permission) slides developed by—Using (with permission) slides developed by—

Dwight Deugo ([email protected])Dwight Deugo ([email protected])Nesa Matic (Nesa Matic ([email protected]))Sreekanth Konireddygari (IBM Corp.)Sreekanth Konireddygari (IBM Corp.)

Page 2: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

2v1.6 08/02/2006

Overview of Eclipse Lectures

1. Overview2. Installing and Running3. Building and Running Java

Classes

1. Overview2. Installing and Running3. Building and Running Java

Classes

Page 3: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

3v1.6 08/02/2006

Module Road Map

1. Overview Architecture Components Usage scenarios

2. Installing and Running3. Building and Running Java Classes

Page 4: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

4v1.6 08/02/2006

Overview » Plug-in Architecture

Eclipse Platform

Platform Runtime

Tool(plug-in)

Tool(plug-in)

Tool(plug-in)

Workbench

Workspace

Help

Team

Page 5: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

5v1.6 08/02/2006

Overview » Workbench Represents the

desktop development environment It contains set of tools

for resource management

It provides common way of navigating through the resources

Multiple workbenches can be opened at the same time

Page 6: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

6v1.6 08/02/2006

Overview » Workspace

Represents users data It is a set of user-defined resources

Files Contain arbitrary number of bytes

Folders Contain other folders or files

Projects Collections of files and folders

Page 7: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

7v1.6 08/02/2006

Module Road Map

1. Overview2. Installing and Running Eclipse

Where to get Eclipse? What is the support for Eclipse? Installing Eclipse Running Eclipse

3. Building and Running Java Classes4. Refactoring5. Debugging6. Testing with JUnit7. Version Control with CVS

Page 8: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

8v1.6 08/02/2006

Installing and Running Eclipse » Getting Eclipse

Page 9: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

9v1.6 08/02/2006

Installing and Running Eclipse » http://www.eclipse.org

Main point for finding Eclipse resources Downloads Articles Discussion groups Bugs

Contains various resources for using Eclipse Contains references to other Eclipse related

sites

Page 10: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

10v1.6 08/02/2006

Installing and Running Eclipse » Downloading Eclipse’s Install Zip File

Click on the Download from the main page on http://www.eclipse.org Choose the closest site from which to download

(ibiblio in our case) Choose the build for download (usually the latest

build) Choose the platform for download and type of

download (http or ftp) Specify where to save the download locally

Page 11: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

11v1.6 08/02/2006

Installing and Running Eclipse » Installing Eclipse

Unzip the downloaded file to the directory of your choice

Page 12: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

12v1.6 08/02/2006

Installing and Running Eclipse » eclipse.exe

Eclipse is run by double-clicking on the eclipse.exe file The file is located in the Eclipse installation

directory If there is no path set for javaw.exe program,

the following dialog will come up

Page 13: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

13v1.6 08/02/2006

Installing and Running Eclipse » Missing a Java VM?

Download the latest Java Runtime Environment (JRE), e.g., v1.4.1_02 from http://java.sun.com/j2se/

Click on the downloaded EXE file to install When given the option by the installer,

identify a directory of your choice for the install files

Update the PATH environment variable to include the JRE’s bin directory

Page 14: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

14v1.6 08/02/2006

Installing and Running Eclipse » Specifying JVM

There are two ways of specifying JVM for Eclipse: By installing JVM under the \jre\ directory off the

eclipse install directory By specifying existing JVM in the PATH

environment variableStart » Control Panel » System » Advanced » Environment

Variables

Page 15: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

15v1.6 08/02/2006

Installing and Running Eclipse » Running Eclipse

When Eclipse is run, a Workbench opens

Page 16: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

16v1.6 08/02/2006

Installing and Running Eclipse » Default Workspace

The default workspace is created when Eclipse runs for the first time The workspace is located under \workspace\

directory of Eclipse installation directory For example c:\eclipse\workspace

The workspace contains user defined data – projects and resources such as folders and files

Page 17: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

17v1.6 08/02/2006

Installing and Running Eclipse » Module Summary

In this module you have learned: What Eclipse is, its background and components How Eclipse is used How to download, install and run Eclipse

Page 18: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

18v1.6 08/02/2006

Module Road Map1. Overview2. Installing and Running3. Building and Running Java Classes

Developing Java applications Projects, packages, classes Browsing Java code Searching Java code Organizing Java code Using Code Assist Running Java applications Scrapbook

Page 19: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

19v1.6 08/02/2006

Building and Running Java Classes » Java Development Tooling - JDT

Eclipse’s Java Development Environment is often referred to as JDT – Java Development Tooling Using the JDT you can do following with the

Java programs: Write Compile Test Debug

Page 20: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

20v1.6 08/02/2006

Building and Running Java Classes » Perspectives

When developing Java code commonly used perspectives are: Java Perspective

Designed for working with Java projects Java Browsing Perspective

Designed for browsing structure of Java projects Java Type Hierarchy Perspective

Designed for exploring type hierarchy Debug Perspective

Designed for debugging Java programs

Page 21: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

21v1.6 08/02/2006

Building and Running Java Classes » Java Perspective

Contains: Editor area Package

Explorer View Hierarchy View Outline View Problems View

Page 22: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

22v1.6 08/02/2006

Building and Running Java Classes » Java Browsing Perspective

Contains: Editor area Projects View Packages View Types View Members View

Page 23: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

23v1.6 08/02/2006

Building and Running Java Classes » Java Type Hierarchy Perspective

Contains editor area and Hierarchy View

Page 24: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

24v1.6 08/02/2006

Building and Running Java Classes » Creating Java Project

Project used to organize resources (source, class, icons) for a project

To create Java project: Select File » New

Project… from the menu

The New Project wizard comes up

Select Java Project Click Next

Page 25: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

25v1.6 08/02/2006

Building and Running Java Classes » New Project Wizard

Specify Project Name Click Next

Page 26: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

26v1.6 08/02/2006

Building and Running Java Classes » Creating Packages

Package contains Java class files

To create a package for a project: Select the project in the

Package Explorer Choose New » Package

from the context menu New Java Package

window appears Specify package name Click Finish

Page 27: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

27v1.6 08/02/2006

Building and Running Java Classes » Creating Classes

To create a class in a package: Select the package

in the Package Explorer

Choose New » Class from the context menu

The Class wizard comes up

Specify class details (Name, Modifiers & Superclass)

Click Finish

Page 28: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

28v1.6 08/02/2006

Exercise 1

Create a new Java application Project titled EgApp.

Create a new Package csc517 in the Project EgApp.

Create a new class titled MainClass with the main() method in the Package csc517.

Page 29: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

29v1.6 08/02/2006

Building and Running Java Classes » Using Code Assist When activated, code assist opens a list of

available code completions Code Assist activates by Crtl+Space

Activates automatically when a message needs to be sent to an object (after the dot is typed)

Page 30: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

30v1.6 08/02/2006

Building and Running Java Classes » Using Quick Fix

Useful if Java compiler shows errors Gives options for fixing the errors Activated through Edit » Quick Fix menu option

Error indication

Page 31: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

31v1.6 08/02/2006

Building and Running Java Classes » Searching for Java Classes

When developing Java application a good search mechanism is very important You often search for class, method declarations, and

references It is important to be able to find things quickly

Eclipse Java Search mechanism is very extensive It allows you to search for:

Types, methods, constructors, packages, and fields Declarations, Implementers, References In the scope of Workspace, Working Set, or Selected

Resources

Page 32: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

32v1.6 08/02/2006

Building and Running Java Classes » Running Java Classes

To Run Java application Choose Run »

Run… from the menu

Standard Java output is displayed in the console window

Page 33: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

33v1.6 08/02/2006

Building and Running Java Classes » Console View Represents standard Java console Opens by default when standard Java output

is used Can also be open from Window » Show View

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

Page 34: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

34v1.6 08/02/2006

Building and Running Java Classes » Scrapbook…

Allows for writing and executing of Java code Very useful for quick test of Java code that you

write The Java code in the Scrapbook can be:

Displayed as a string when evaluated Inspected when evaluated

Opens an Inspector view where you can see returning object from evaluation and all containing fields

Executed

Page 35: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

35v1.6 08/02/2006

Building and Running Java Classes » Scrapbook… It is created by selecting a

project and choosing New » Other…from the Package Explorer’s context menu

This opens up the New dialog box

Expand Java Expand Java Run/Debug

under Java Select Scrapbook page

and click Next. This will open New

Scrapbook page Enter the name of the page Your scrapbook page will

become a resource in your project

Page 36: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

36v1.6 08/02/2006

Building and Running Java Classes » Scrapbook

To open the scrapbook page just click on the resource

It opens up like a Java source file editor

Type Java code and select the context menu to Display or Inspect

Page 37: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

37v1.6 08/02/2006

Building and Running Java Classes » Scrapbook

Class names must be fully qualified in what you type

Set imports to make life easier

Think of your scrapbook as a page that Eclipse will take the source you type, wrap it in a class with your source in the main menu, then compile and execute

Page 38: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

38v1.6 08/02/2006

Building and Running Java Classes » Summary

You have learned: How to create projects, packages and classes How to browse Java code and search for Java

code How to use coding assistance How to run Java code How to use the Scrapbook

Page 39: Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo (dwight@espirity.com) Nesa Matic (nesa@espirity.com)

39v1.6 08/02/2006

Exercise 2 Create a new class titled NewClass and add it to the package csc517 in the project

EgApp you have created in Exercise 1.

Add a private integer field (member variable) mVar to the class NewClass.

Add a constructor method to accept an integer to initialize the private integer field mVar.

Add a public method printField that takes no parameters and returns void.

Add code to the printField method to print the value of the private variable mVar to the standard output.

Instantiate an object of type NewClass in the main() routine of the MainClass.

Call the printField routine of the NewClass object.

Run the project EgApp.

What do you see in the Console window?