Intro to Eclipse Rick Mercer - PowerPoint PPT Presentation

1 / 37
About This Presentation
Title:

Intro to Eclipse Rick Mercer

Description:

Tools are added as plug-ins, many are free. Tomcat, XML Editor, Java, C#, C , UML ... Other Cool Things. Occasionally you need the debugger. To use the ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 38
Provided by: rickmercer
Category:
Tags: eclipse | intro | mercer | rick

less

Transcript and Presenter's Notes

Title: Intro to Eclipse Rick Mercer


1
Intro to EclipseRick Mercer
2
Outline
3
Eclipse
  • Eclipse is a universal tool platform
  • An open extensible IDE for anything and nothing
    in particular
  • Small runtime kernel
  • Tools are added as plug-ins, many are free
  • Tomcat, XML Editor, Java, C, C, UML
  • J2EE development? GUI builder? UML modeling?
  • Have to pay
  • Has a workspace for managing resources
  • Workspace is organized into projects

4
Eclipse
  • Open source project--can get it for free
  • Version 1.0 Nov 01
  • Version 2.1 March 03
  • Version 3.0 July 2004
  • Has its own compiler (but still need a JRE)
  • IBM had 40 million invested before making it
    open source as Eclipse.org
  • IBM, Rational, Borland, TogetherSoft, Fujitsu,
    Oracle, Sybase, Red Hat, Webgain, HP
  • Board determines the goals and objectives

5
Three Projects at Eclipse.org
  • The Eclipse Platform (Eclipse)
  • workbench into which tools can be plugged
  • Subprojects Compare, Help, Search
  • Java Development Kit (JDT)
  • Led by Eric Gamma
  • Subprojects Debug support for Java, UI
  • Plug-in Development Environment (PDE)

6
Open Source
  • Eclipse is distributed under the Common Public
    License (CPL)
  • It joins the likes of Linux, Apache and Mozilla

7
JDT
  • The Eclipse platform provides a way to integrate
    new tools
  • Plug-in metaphor add new tools easily
  • To be useful, Eclipse needs plug-ins
  • When you download it, you will get the Java
    Development Toolkit (JDT)
  • Run and debug Java Applets, Applications and
    JUnit Tests

8
Perspectives
  • Eclipse has many perspectives
  • Each has several windows in a certain layout
  • Different things happen on right clicks with
    different perspectives
  • You will see, use, and switch between
  • Java Perspective
  • Debug Perspective

9
Getting Eclipse on Your Machine
  • If necessary, install recent version of Java
    (1.4.2)
  • You only need the Java Runtime Environment (JRE)
  • Get Eclipse release 3.0 (July-04)
  • Unzip to a folder in Windows, use C\Program
    Files
  • Does not infect registry or environment variables
  • Create shortcut an put it on your desktop.
  • Start Eclipse and enter a folder where you would
    like to store your projects (can change this
    later)
  • Eclipse creates a folder named workspace under it
  • Each new workspace folder looks like

10
Click here to write code
11
  • This is the resource perspective with these views
  • Navigator
  • Outline
  • Tasks
  • Resources

12
And then do these steps
  • File gt New gt Project gt Java Project
  • Enter Hello as the project name
  • File gt New gt Class
  • Enter First as the class name
  • Click the box to get the main method stub
  • Add System.out.println("Hello World")
  • Run gt Run as gt Java Application
  • Click on the Console tab
  • Then Eclipse will look like the following

13
(No Transcript)
14
Projects and Folders
  • Projects are mapped to a folder under the
    workspace folder
  • And packages are in subfolders under the project
    folder
  • You will use a self-contained, high-level,
    platform-neutral hierarchy

15
Perspectives, Views, Editors
  • View A single pane in a perspective
  • Perspective A collection of views
  • Many plugins have their own perspectives
  • Editors Different type for different files
  • Could have a text editor or the Java editor
    (color syntax highlighting, auto-formatting, code
    completion), or PowerPoint,

16
Why Eclipse?
  • Integrated testing framework
  • Optional Code completion
  • Suggestions to fix errors (shows at error)
  • Built in Java help
  • Ability to add plug-ins
  • Refactorings change signature, rename, extract
    method
  • Code templates
  • sop System.out.println("_")
  • for for (int index 0 index lt n index)
  • Faster compilation
  • Nice debugger

17
Debugging
  • First need to set at least one breakpoint
  • Use Debug as rather than Run as
  • Use Step Filtering with Shift F5
  • Later you will add filters to avoid stepping into
    Java classes
  • Saves lots of time, no need to debug java

18
Preferences
  • Many things can be changed
  • Fonts, code formatting, tabs at top or bottom of
    views, code generated for new files
  • Can set debugging preferences and the above by
    importing a preference file
  • Will specify coding style, comments, spacing,
    indentation,
  • A team can use the same preference file to
    enforce coding style

19
Testing Framework
  • JUnit is a testing framework that is integrated
    into Eclipse
  • Use this to test one method at a time
  • Tests will always be available to detect when
    something breaks
  • Used by professional developers to design and
    implement good code
  • Has become a programming methodology called test
    driven development (TDD)

20
Test Driven Development
  • The steps
  • Write a test that specifies a tiny bit of
    functionality
  • Ensure the test fails (functionality not built
    yet!)
  • Write only the code necessary to make the test
    pass
  • Refactor the code, ensuring that it has the
    simplest design possible for the functionality
    built to date
  • Important to use a testing framework like NUnit
  • Improve internal structure of code without
    making externally visible changes to the
    functionality

21
JUnit Preview
  • JUnit http//www.junit.org/ is an open source
    testing framework to support TDD
  • You write a separate unit test as a class
  • In the same language as the production code
  • Useful methods in class Assert include
  • assertEqual, assertTrue, assertFalse,
    assertNotNull, assertNull

22
Demo TDD with Java in Eclipse
  • Develop a class that models an account at a bank
    that will be used in our Bank case study

23
Write a test first that will not compile
Demo TDD with Java in Eclipse
  • using NUnit.Framework
  • public class BankAccountTest extends junit.frame
    ???
  • public void testGetters()
  • BankAccount b1
  • b1 new BankAccount("Kim", 100.00)
  • // Expected, Actual
  • Assert.AreEqual("Kim", b1.ID)
  • // Expected, Actual
  • Assert.AreEqual(100.00, b1.Balance)

24
Make test code compileLet test fail
  • public class BankAccount
  • public BankAccount(string ID,
  • double initBalance)
  • public string ID
  • get return ""
  • public double Balance
  • get return 0.0
  • // end class BankAccount

25
Make Tests Pass
  • public class BankAccount
  • private string id
  • private double balance
  • public BankAccount(string ID, double
    initBalance)
  • id ID
  • balance initBalance
  • public string ID
  • get return id
  • public double Balance
  • get return balance

26
Begin demo with a passing Properties test method
  • Reinforces that objects have their own state (set
    of values) and they can remember their values

Now allow withdrawals next slide
27
Withdraw
  • Add behavior to allow withdrawals when the
    balance is large enough
  • Don't allow withdrawals if the amount requested
    exceeds the account balance
  • Continue with the following test list
  • Withdraw when there is enough money
  • Withdraw the whole balance
  • Withdraw when there is not enough money
  • Switch to VS.NET

28
Why a Testing Framework?
  • There is power in the green bar
  • Students verify their code works without
  • Intro students can use testing frameworks

29
Why use TDD in CS1?
  • Helps distinguish objects and classes
  • Provides a process
  • students develop one method at a time
  • Better than one class at a time
  • Hypothesize and verify
  • Set up an experiment, written as a test
  • Verify it works (or that it doesn't)
  • Makes for better projects and test questions
  • Allow loans to max of 2,000 in increments of 100

30
Benefits of TDD
  • Benefits
  • Fewer defects
  • Less debugging
  • More confidence
  • Better design
  • Catches errors immediately

31
  • Is testing important?

32
Structured Labs
  • A set of structured labs designed for CS1 in C
    will be available from the course web site
  • http//www.cs.arizona.edu/classes/cs186/sum
    mer04/
  • Plan to add to
  • http//www.msdnaa.net/curriculum/repository.asp
    x
  • Reinforce concepts with hands on activities, in a
    closed lab setting or as homework
  • Rick Mercer mercer_at_cs.arizona.edu

33
  • using NUnit.Framework
  • TestFixture
  • public class BankAccountTest
  • Test
  • public void Properties()
  • BankAccount b1
  • b1 new BankAccount("Kim", 100.00)
  • Assert.AreEqual("Kim", b1.ID)
  • Assert.AreEqual(100.00, b1.Balance)
  • Test
  • public void WithdrawWithEnoughMoney()
  • BankAccount b1
  • b1 new BankAccount("Kim", 100.00)

BankAccountTest.cs
34
  • public class BankAccount
  • private string id
  • private double balance
  • public BankAccount(string ID, double
    initBalance)
  • id ID
  • balance initBalance
  • public string ID
  • get return id
  • public double Balance
  • get return balance

BankAccount.cs
35
Other Cool Things
  • Can ensure a method is throwing an exception
  • This test will succeed
  • Test
  • ExpectedException(typeof(InvalidOperationExceptio
    n))
  • public void Pop()
  • Stack s new Stack()
  • s.Pop()
  • If s.Pop() is removed, the test would fail

36
Other Cool Things
  • Occasionally you need the debugger
  • To use the Debugger with NUnit
  • Set a breakpoint on the failed assertion
  • Proceed as before (run with NUnit)
  • Execution stops at the breakpoint
  • Step through the source code, watch variables

37
Summary
  • Eclipse is a workbench to which tools such as JDT
    can be added
  • Has perspectives, views, and editors
  • Editor in use depends on the resource
  • Has preferences that can be changed
  • Lots of help for software developers
  • Complex Takes a while to get used to it
  • But the tools are helpful, you'll save time and
    wrote better code
Write a Comment
User Comments (0)
About PowerShow.com