Download PPT - NCSU COE People

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Introduction to Eclipse
CSC 216
Lecture 3
Ed Gehringer
Using (with permission) slides developed by—
Dwight Deugo ([email protected])
Nesa Matic ([email protected])
Sreekanth Konireddygari (IBM Corp.)
Overview of Eclipse Lectures
1. Overview
2. Installing and Running
3. Building and Running Java Classes
v1.6
08/02/2006
2
Module Road Map
1. Overview



2.
3.
Architecture
Components
Usage scenarios
Installing and Running
Building and Running Java Classes
v1.6
08/02/2006
3
Overview »
Plug-in Architecture
Eclipse Platform
Workbench
Tool
(plug-in)
Help
Tool
(plug-in)
Workspace
Team
…
Tool
(plug-in)
Platform Runtime
v1.6
08/02/2006
4
Overview »

Represents the
desktop development
environment



Workbench
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
v1.6
08/02/2006
5
Overview »


Workspace
Represents users data
It is a set of user-defined resources

Files


Folders


Contain arbitrary number of bytes
Contain other folders or files
Projects

v1.6
Collections of files and folders
08/02/2006
6
Module Road Map
1.
Overview
2. Installing and Running Eclipse
 Where to get Eclipse?
 What is the support for Eclipse?
 Installing Eclipse
 Running Eclipse
3.
4.
5.
6.
7.
Building and Running Java Classes
Refactoring
Debugging
Testing with JUnit
Version Control with CVS
v1.6
08/02/2006
7
Installing and Running Eclipse »
v1.6
08/02/2006
8
Getting Eclipse
Installing and Running Eclipse »

Main point for finding Eclipse resources






http://www.eclipse.org
Downloads
Articles
Discussion groups
Bugs
Contains various resources for using Eclipse
Contains references to other Eclipse related
sites
v1.6
08/02/2006
9
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
v1.6
08/02/2006
10
Installing and Running Eclipse »

Installing Eclipse
Unzip the downloaded file to the directory of
your choice
v1.6
08/02/2006
11
Installing and Running Eclipse »

Eclipse is run by double-clicking on the
eclipse.exe file


eclipse.exe
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
v1.6
08/02/2006
12
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
v1.6
08/02/2006
13
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 variable
Start » Control Panel » System » Advanced » Environment Variables
v1.6
08/02/2006
14
Installing and Running Eclipse »

Running Eclipse
When Eclipse is run, a Workbench opens
v1.6
08/02/2006
15
Installing and Running Eclipse »

The default workspace is created when
Eclipse runs for the first time



Default Workspace
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
v1.6
08/02/2006
16
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
v1.6
08/02/2006
17
Module Road Map
1.
2.
3.
Overview
Installing and Running
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
v1.6
08/02/2006
18
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:




v1.6
Write
Compile
Test
Debug
08/02/2006
19
Building and Running Java Classes »

Perspectives
When developing Java code commonly used
perspectives are:

Java Perspective


Java Browsing Perspective


Designed for browsing structure of Java projects
Java Type Hierarchy Perspective


Designed for working with Java projects
Designed for exploring type hierarchy
Debug Perspective

v1.6
Designed for debugging Java programs
08/02/2006
20
Building and Running Java Classes »

Contains:





Editor area
Package
Explorer View
Hierarchy
View
Outline View
Problems View
v1.6
08/02/2006
21
Java Perspective
Building and Running Java Classes »
Java Browsing Perspective

Contains:





Editor area
Projects View
Packages View
Types View
Members View
v1.6
08/02/2006
22
Building and Running Java Classes »
Java Type Hierarchy Perspective

Contains editor area and Hierarchy View
v1.6
08/02/2006
23
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
v1.6
08/02/2006
24
Building and Running Java Classes »


Specify Project Name
Click Next
v1.6
08/02/2006
25
New Project Wizard
Building and Running Java Classes »


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
v1.6
08/02/2006
26
Creating Packages
Building and Running Java 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
v1.6
08/02/2006
27
Creating Classes
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.
v1.6
08/02/2006
28
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)
v1.6
08/02/2006
29
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
v1.6
08/02/2006
30
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
v1.6
08/02/2006
31
Building and Running Java Classes »

To Run Java
application


Choose Run »
Run… from the
menu
Standard Java
output is
displayed in the
console window
v1.6
08/02/2006
32
Running Java Classes
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");
v1.6
08/02/2006
33
Building and Running Java Classes »

Allows for writing and executing of Java code


Scrapbook…
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
v1.6
08/02/2006
34
Building and Running Java Classes »








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
v1.6
08/02/2006
35
Scrapbook…
Building and Running Java Classes »



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
v1.6
08/02/2006
36
Scrapbook
Building and Running Java Classes »



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
v1.6
08/02/2006
37
Scrapbook
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
v1.6
08/02/2006
38
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?
v1.6
08/02/2006
39