Eclipse-Java Development User Guide

download Eclipse-Java Development User Guide

of 84

Transcript of Eclipse-Java Development User Guide

  • 8/3/2019 Eclipse-Java Development User Guide

    1/84

    Java development user guideContents1. Java development overview

    2. Getting Started2.1. Basic tutorial2.1.1. Preparing Eclipse2.1.2. Creating your first Java project2.1.3. Browsing Java elements using the package explorer2.1.4. Editing Java elements2.1.4.1. Opening a Java editor2.1.4.2. Using quick views2.1.4.3. Adding new methods2.1.4.4. Using content assist2.1.4.5. Identifying problems in your code

    2.1.4.6. Using code templates2.1.4.7. Organizing import statements2.1.4.8. Using the local history2.1.4.9. Extracting a new method2.1.5. Creating a Java class2.1.6. Renaming Java elements2.1.7. Moving and copying Java elements2.1.8.Navigate to a Java element's declaration2.1.9. Viewing the type Hierarchy2.1.10. Searching the workbench2.1.11. Running your programs2.1.12. Debugging your programs

    2.1.13. Evaluating expressions2.1.14. Evaluating snippets2.1.15. Using the Java browsing perspective2.1.16. Writing and running JUnit tests2.2. Project configuration tutorial2.2.1. Detecting existing layout2.2.2. Organizing sources2.2.3. Sibling products in a common source tree2.2.4. Overlapping products in a common source tree2.2.5. Product with nested tests2.2.6. Products sharing a common source framework

    2.2.7. Product nesting resources in output directory2.2.8. Project using a source framework with restricted access2.3. Eclipse and J2SE 5.03. Concepts3.1. Java Projects3.2. Java Builder3.2.1. Build Classpath3.2.1.1. Inclusion and Exclusion Patterns3.2.1.2. Access Rules

  • 8/3/2019 Eclipse-Java Development User Guide

    2/84

    3.2.1.3. Classpath Variables3.3. Java Perspectives3.4. Java Views3.4.1. Filtering in Java Views3.4.2. Sorting in Java Views3.4.3. Java Element Decorations3.4.4. Presentation Options for Java Views3.5. Java Editor3.6. Quick Fix and Assist3.7. Templates3.8. Java Search3.9. Refactoring Support3.10. Debugger3.11. Scrapbook3.12. Local Debugging3.13. Remote Debugging3.14. Breakpoints

    3.15. String Externalization4. Tasks4.1. Customizing the Debugger and Console4.1.1. Changing the active perspective when launching4.1.2. Changing the appearance of the console view4.2. Creating JAR Files4.2.1. Creating a new JAR file4.2.2. Setting advanced options4.2.3. Defining the JAR file's manifest4.2.4. Regenerating a JAR File4.3. Using the Local History4.3.1. Comparing a Java element with a local history edition4.3.2. Replacing a Java element with a local history edition4.3.3. Restoring a deleted workbench element4.4. Externalizing Strings4.4.1. Finding strings to externalize4.4.2. Finding unused and incorrectly used keys in property files4.5.Navigating the Workbench4.5.1. Opening an editor for a selected element4.5.2. Showing an element in the Package Explorer view4.5.3. Opening a type in the Package Explorer view4.5.4. Opening an editor on a type4.5.5. Opening a package

    4.6. Working with JREs4.6.1. Assigning the default JRE for the workbench4.6.2. Adding a new JRE definition4.6.3. Choosing a JRE for launching a project4.6.4. Deleting a JRE definition4.7. Running and Debugging4.7.1. Breakpoints4.7.1.1. Adding Line Breakpoints

  • 8/3/2019 Eclipse-Java Development User Guide

    3/84

    4.7.1.2. Removing Line Breakpoints4.7.1.3. Enabling and Disabling Breakpoints4.7.1.4. Setting Method Breakpoints4.7.1.5. Applying Hit Counts4.7.1.6. Managing Conditional Breakpoints4.7.1.7. Catching Java Exceptions4.7.1.8. Creating Exception Breakpoint Filters4.7.2. Local Debugging4.7.2.1. Preparing to Debug4.7.2.2. Launching a Java program in Debug Mode4.7.2.3. Suspending Threads4.7.2.4. Resuming Threads4.7.2.5. Stepping through the execution of a program4.7.2.6. Inspecting Values4.7.2.7. Evaluating expressions4.7.3. Remote Debugging4.7.3.1. Using the remote Java application launch configuration

    4.7.3.2. Disconnecting from a VM4.7.4. Creating a Java application launch configuration4.7.5. Launching a Java program4.7.6. Launching a Java applet4.7.7. Setting execution arguments4.7.8. Relaunching a program4.7.9. Inspecting memory in the Memory view4.7.9.1. Adding a variable, expression, or register to the Memory view4.7.9.2. Adding multiple memory renderings and removing renderings4.7.9.3. Working with memory monitors4.7.9.4. Changing the contents of a memory location4.7.9.5. Memory view preferences4.7.9.6. Working with multiple Memory views4.7.9.7. Removing memory monitors from the Memory view4.8. Using the Scrapbook4.8.1. Creating a Java Scrapbook Page4.8.2. Inspecting the result of evaluating an expression4.8.3. Displaying the result of evaluating an expression4.8.4. Running an expression4.8.5. Using code assist4.8.6. Scrapbook error reporting4.8.6.1. Viewing compilation errors4.8.6.2. Viewing runtime exceptions

    4.9. Using the Formatter Application4.9.1. Running the formatter application4.9.2. Generating a config file for the formatter application5. Reference5.1. Breakpoints5.1.1. Condition Option5.1.2. Enabled Option5.1.3. Exception Breakpoint Caught Option

  • 8/3/2019 Eclipse-Java Development User Guide

    4/84

    5.1.4. Exception Breakpoint Suspend on Subclass Option5.1.5. Exception Breakpoint Uncaught Option5.1.6. Hit Count Option5.1.7. Method Breakpoint Entry Option5.1.8. Method Breakpoint Exit Option5.1.9. Suspend Policy Option5.1.10. Watchpoint Modification Option5.1.11. Watchpoint Access Option5.2. Menus and Actions5.2.1. File Menu Actions5.2.2. Edit Menu Actions5.2.3. Source Menu Actions5.2.4. Refactor Menu Actions5.2.5.Navigate Menu Actions5.2.6. Search Menu Actions5.2.7. Project Menu Actions5.2.8. Run Menu Actions

    5.2.9. Java Toolbar Actions5.2.10. Run and Debug Toolbar Actions5.2.11. Java Editor Actions5.3. Preferences5.3.1. Java5.3.1.1. Appearance5.3.1.1.1. Member Sort Order5.3.1.1.2. Type Filters5.3.1.2. Build Path5.3.1.2.1. Classpath Variables5.3.1.2.2. User Libraries5.3.1.3. Code Style5.3.1.3.1. Clean Up5.3.1.3.2. Code Templates5.3.1.3.3. Formatter5.3.1.3.4. Organize Imports5.3.1.4. Compiler5.3.1.4.1. Building5.3.1.4.2. Errors/Warnings5.3.1.4.3. Javadoc5.3.1.4.4. Task Tags5.3.1.5. Debug5.3.1.5.1. Detail Formatters

    5.3.1.5.2. Heap Walking5.3.1.5.3. Logical Structures5.3.1.5.4. Primitive Display Options5.3.1.5.5. Step Filtering5.3.1.6. Editor5.3.1.6.1. Content Assist5.3.1.6.1.1. Advanced5.3.1.6.1.2. Favorites

  • 8/3/2019 Eclipse-Java Development User Guide

    5/84

    5.3.1.6.2. Folding5.3.1.6.3. Hovers5.3.1.6.4. Mark Occurrences5.3.1.6.5. Save Actions5.3.1.6.6. Syntax Coloring5.3.1.6.7. Templates5.3.1.6.8. Typing5.3.1.7. Installed JREs5.3.1.7.1. Execution Environments5.3.1.8. JUnit5.3.1.9. Properties Files Editor5.3.2. Run/Debug5.3.2.1. Console5.3.2.2. Launching5.3.2.2.1. Default Launchers5.3.2.2.2. Launch Configurations5.3.2.3. Perspectives

    5.3.2.4. String Substitution5.3.2.5. View Management5.4. Property Pages5.4.1. Javadoc Location5.4.2. Java Build Path5.4.3. Java Compiler5.4.4. Java Task Tags5.4.5. Source Attachment5.4.6. Run / Debug5.5. Refactoring5.5.1. Refactor Actions5.5.2. Refactor Wizard5.5.3. Extract Method Errors5.6. Search5.6.1. Java Search Tab5.6.2. Java Search Actions5.7. Toolbar5.7.1. Java Toolbar Actions5.7.2. Java Editor Toolbar Actions5.7.3. Run and Debug Toolbar Actions5.8. Views5.8.1. Breakpoints View5.8.1.1. Access

    5.8.1.2. Add Java Exception Breakpoint5.8.1.3. Breakpoint Properties5.8.1.4. Caught5.8.1.5. Collapse All5.8.1.6. Copy5.8.1.7. Disable5.8.1.8. Enable5.8.1.9. Entry

  • 8/3/2019 Eclipse-Java Development User Guide

    6/84

    5.8.1.10. Exit5.8.1.11. Expand All5.8.1.12. Export Breakpoints5.8.1.13. Go to File for Breakpoint5.8.1.14. Group By5.8.1.15. Hit Count5.8.1.16. Import Breakpoints5.8.1.17. Link with Debug View5.8.1.18. Modification5.8.1.19. Paste5.8.1.20. Remove Selected Breakpoints5.8.1.21. Remove All Breakpoints5.8.1.22. Select All5.8.1.23. Select Default Working Set5.8.1.24. Show Qualified Names5.8.1.25. Show Supported Breakpoints5.8.1.26. Skip All Breakpoints

    5.8.1.27. Suspend Policy5.8.1.28. Working Sets...5.8.1.29. Uncaught5.8.2. Console View5.8.2.1. CVS Console5.8.2.1.1. Copy5.8.2.1.2. Cut5.8.2.1.3. Find/Replace5.8.2.1.4. Open Link5.8.2.1.5. Paste5.8.2.1.6. Select All5.8.2.2. Process Console5.8.2.2.1. Copy5.8.2.2.2. Cut5.8.2.2.3. Console Preferences5.8.2.2.4. Find/Replace5.8.2.2.5. Paste5.8.2.2.6. Remove All Terminated Launches5.8.2.2.7. Remove Launch5.8.2.2.8. Select All5.8.2.2.9. Show Console When Standard Out Changes5.8.2.2.10. Show Console When Standard Error Changes5.8.2.2.11. Terminate

    5.8.2.3. Stacktrace Console5.8.2.3.1. Autoformat Console5.8.2.3.2. Copy5.8.2.3.3. Cut5.8.2.3.4. Find/Replace5.8.2.3.5. Format5.8.2.3.6. Open Link5.8.2.3.7. Paste

  • 8/3/2019 Eclipse-Java Development User Guide

    7/84

    5.8.2.3.8. Select All5.8.2.4. Clear the Console5.8.2.5. Display Selected Console5.8.2.6. Open Console5.8.2.7. Pin the Console5.8.2.8. Scroll Lock5.8.3. Debug View5.8.3.1. Execution Control Commands5.8.3.1.1. Resume5.8.3.1.2. Step Into5.8.3.1.3. Step Over5.8.3.1.4. Step Return5.8.3.1.5. Suspend5.8.3.1.6. Terminate5.8.3.1.7. Terminate/Disconnect All5.8.3.1.8. Terminate and Relaunch5.8.3.1.9. Terminate and Remove

    5.8.3.2. Copy Stack5.8.3.3. Disconnect5.8.3.4. Drop to Frame5.8.3.5. Edit Launch Configuration5.8.3.6. Edit Source Lookup5.8.3.7. Edit Step Filters5.8.3.8. Filter Package5.8.3.9. Filter Type5.8.3.10. Find...5.8.3.11. Lookup Source5.8.3.12. Open Declared Type5.8.3.13. Open Declared Type Hierarchy5.8.3.14. Properties5.8.3.15. Relaunch5.8.3.16. Remove All Terminated5.8.3.17. Show Monitors5.8.3.18. Show Qualified Names5.8.3.19. Show System Threads5.8.3.20. Show Thread Groups5.8.3.21. Use Step Filters5.8.4. Display View5.8.4.1. Clear5.8.4.2. Content Assist

    5.8.4.3. Copy Selected Statements5.8.4.4. Cut Selected Statements5.8.4.5. Display5.8.4.6. Execute Selected Statement5.8.4.7. Find/Replace5.8.4.8. Inspect5.8.4.9. Paste5.8.4.10. Select All

  • 8/3/2019 Eclipse-Java Development User Guide

    8/84

    5.8.5. Expressions View5.8.5.1. Detail Pane5.8.5.1.1. Assign Value5.8.5.1.2. Content Assist5.8.5.1.3. Cut5.8.5.1.4. Copy5.8.5.1.5. Display5.8.5.1.6. Execute5.8.5.1.7. Find/Replace5.8.5.1.8. Force Return5.8.5.1.9. Inspect5.8.5.1.10. Max Length5.8.5.1.11. Paste5.8.5.1.12. Select All5.8.5.1.13. Wrap Text5.8.5.2. View Display Commands5.8.5.2.1. Show Contants

    5.8.5.2.2. Show Logical5.8.5.2.3. Show Null5.8.5.2.4. Show Qualified5.8.5.2.5. Show References5.8.5.2.6. Show Static5.8.5.2.7. Show Type Names5.8.5.3. View Layout Commands5.8.5.3.1. Show Columns5.8.5.3.2. Select Columns5.8.5.3.3. Horizontal View Orientation5.8.5.3.4. Vertical View Orientation5.8.5.3.5. View Only5.8.5.4. Add Watch Expression5.8.5.5. All Instances5.8.5.6. All References5.8.5.7. Change Variable Value5.8.5.8. Collapse All5.8.5.9. Copy Expressions5.8.5.10. Convert to Watch Expression5.8.5.11. Disable Selected Watch Expression5.8.5.12. Edit Watch Expression5.8.5.13. Enable Selected Watch Expression5.8.5.14. Find...

    5.8.5.15. Inspect Variable5.8.5.16. Java Preferences5.8.5.17. Reevaluate Watch Expression5.8.5.18. Remove Selected Expressions5.8.5.19. Remove All Expressions5.8.5.20. Select All5.8.5.21. Toggle Watchpoint5.8.6. Package Explorer view

  • 8/3/2019 Eclipse-Java Development User Guide

    9/84

    5.8.6.1. Java Element Filters dialog5.8.7. Variables View5.8.7.1. Detail Pane5.8.7.1.1. Assign Value5.8.7.1.2. Content Assist5.8.7.1.3. Cut5.8.7.1.4. Copy5.8.7.1.5. Display5.8.7.1.6. Execute5.8.7.1.7. Find/Replace5.8.7.1.8. Force Return5.8.7.1.9. Inspect5.8.7.1.10. Max Length5.8.7.1.11. Paste5.8.7.1.12. Select All5.8.7.1.13. Wrap Text5.8.7.2. View Display Commands

    5.8.7.2.1. Show Contants5.8.7.2.2. Show Logical5.8.7.2.3. Show Null5.8.7.2.4. Show Qualified5.8.7.2.5. Show References5.8.7.2.6. Show Static5.8.7.2.7. Show Type Names5.8.7.3. View Layout Commands5.8.7.3.1. Show Columns5.8.7.3.2. Select Columns5.8.7.3.3. Horizontal View Orientation5.8.7.3.4. Vertical View Orientation5.8.7.3.5. View Only5.8.7.4. All Instances5.8.7.5. All References5.8.7.6. Change Variable Value5.8.7.7. Collapse All5.8.7.8. Copy Variables5.8.7.9. Create Watch Expression5.8.7.10. Find...5.8.7.11. Inspect Variable5.8.7.12. Java Preferences5.8.7.13. Select All

    5.8.7.14. Toggle Watchpoint5.8.8. Java Outline View5.8.9. Java Scrapbook Page5.8.10. Type Hierarchy View5.8.11. Call Hierarchy View5.9. Java Editor5.9.1. Java Content Assist5.9.2. Java Formatter

  • 8/3/2019 Eclipse-Java Development User Guide

    10/84

    5.9.3. Quick fix5.9.4. Quick assist5.10. Wizards and Dialogs5.10.1. Create New Elements5.10.1.1.New Java Project Wizard5.10.1.1.1. Java Build Path Page5.10.1.1.2. Attaching Source to JAR Files and Variables5.10.1.2.New Java Package Wizard5.10.1.3.New Java Class Wizard5.10.1.4.New Java Enum Wizard5.10.1.5.New Java Interface Wizard5.10.1.6.New Java Annotation Wizard5.10.1.7.New Source Folder Wizard5.10.1.8.New Java Scrapbook Page Wizard5.10.2. Export Breakpoints5.10.3. Export Launch Configurations5.10.4. Externalize Strings wizard

    5.10.5. Import Breakpoints5.10.6. Import Launch Configurations5.10.7. JAR File Exporter5.10.8. Javadoc Generation5.10.9. Java Element Filters5.10.10. Open Type Dialog5.10.11. Create Getter and Setter5.10.12. Generate toString ( )5.10.12.1. Format Templates5.10.12.2. Code Styles5.10.12.3. Content Listing5.10.13. Override Methods5.11. Frequently-Asked Questions: JDT5.12. Glossary5.13. Icons5.14. Available Quick Assists5.15. Available Quick Fixes5.16. List of JDT Key Bindings6. Tips and tricks7. What's new8. Legal

    1. Java development overviewThe JDT project provides the tool plug-ins that implement a Java IDE supporting thedevelopment of any Java application, including Eclipse plug-ins. It adds a Java project natureand Java perspective to the Eclipse Workbench as well as a number of views, editors, wizards,builders, and code merging and refactoring tools. The JDT project allows Eclipse to be adevelopment environment for itself.

    Try the Basic tutorialto get a first impression. Discover more in theTips and Tricks section andlearn about the latest features in What's new in 3.4

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-BasicTutorial.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-BasicTutorial.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tips/jdt_tips.htmlhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tips/jdt_tips.htmlhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/whatsNew/jdt_whatsnew.htmlhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-BasicTutorial.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tips/jdt_tips.htmlhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/whatsNew/jdt_whatsnew.html
  • 8/3/2019 Eclipse-Java Development User Guide

    11/84

    2.1. Basic tutorialThis tutorial provides a step by step walk-through of the Java development tools.

    Next Section:Preparing the workbench

    2.1.1. Preparing EclipseIn this section, you will verify that Eclipse is properly set up for Java development.

    The following is assumed:

    You are starting with a new Eclipse installation with default settings.

    You are familiar with the basic Eclipse workbench mechanisms, such as views andperspectives.

    If you're not familiar with the basic workbench mechanisms, please see the Getting Startedchapter of the Workbench User Guide.

    Verifying JRE installation and classpath variables1. If you still see the Eclipse Welcome page, click the arrow icon to begin using Eclipse.

    2. Select the menu item Window > Preferences... to open the workbench preferences.

    3. Select the Java > Installed JREs preference page to display the installed JavaRuntime Environments. Confirm that a JRE has been detected. By default, the JRE usedto run the workbench will be used to build and run Java programs. It should appear with acheckmark in the list of installed JREs. We recommend that you use a Java SDK insteadof a JRE. An SDK is designed for development and contains the source code for the Javalibrary, easing debugging. Additional SDKs can be added by searching the hard drive for

    installed SDKs. To do so, simply click the Search... button and specify a root folder forthe search.If you work with code that does not yet use generics (as we do in this tutorial), werecommend that you install a Java SDK 1.4 as well, but leave the most recent versionchecked as default.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-2.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-2.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/PLUGINS_ROOT/org.eclipse.platform.doc.user/gettingStarted/qs-01.htmhttp://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workbench)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.debug.ui.preferences.VMPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.debug.ui.preferences.VMPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workbench)%22)http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-2.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/PLUGINS_ROOT/org.eclipse.platform.doc.user/gettingStarted/qs-01.htmhttp://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workbench)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.debug.ui.preferences.VMPreferencePage)%22)
  • 8/3/2019 Eclipse-Java Development User Guide

    12/84

    4. Select the General > Workspace preference page. Confirm that the Buildautomatically option is checked.

    5. Select the Java > Build Path preference page. Confirm that Source and outputfolder is set to Folders.

    6. Select the Java > Editorpreference page. Confirm that option Report problems asyou type is checked.

    7. Select the Java > Compiler preference page. Confirm that option Compilercompliance level matches your default JRE version (usually 1.6).

    http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workspace)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.BuildPathPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaEditorPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaEditorPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CompliancePreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CompliancePreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaEditorPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.BuildPathPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workspace)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workspace)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.BuildPathPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaEditorPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CompliancePreferencePage)%22)
  • 8/3/2019 Eclipse-Java Development User Guide

    13/84

    8. Click on OKto save the preferences.

    Next Section:Creating your first Java project

    Java projectsClasspath variablesBuild classpath

    Working with JREs

    Installed JREs PreferencesJava Editor Preferences

    2.1.2. Creating your first Java projectIn this section, you will create a new Java project. You will be using JUnit as your exampleproject. JUnit is an open source unit testing framework for Java.

    Getting the Sample Code (JUnit)First you need to download the JUnit source code.

    1. Clickhere to download the JUnit source code.

    2. Save the archive (do not extract) to a directory from now on referenced as .

    Creating the project1. Inside Eclipse select the menu item File > New > Project.... to open the New Project

    wizard

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-3.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-3.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-project.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-classpath-variables.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-build-classpath.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/tasks-JREs.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/debug/ref-installed_jres.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/http:/www.eclipse.org/jdt/ui/smoke-test/junit3.8.1src.ziphttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-3.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-project.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-classpath-variables.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-build-classpath.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/tasks-JREs.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/debug/ref-installed_jres.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/http:/www.eclipse.org/jdt/ui/smoke-test/junit3.8.1src.zip
  • 8/3/2019 Eclipse-Java Development User Guide

    14/84

    2. Select Java Project then clickNext to start the New Java Projectwizard:

    On this page,

    type "JUnit" in the Project name field, and

    select "J2SE-1.4" in the Use an execution environment JRE field.

    Then clickFinish.

    http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.newWizard(newWizardId=org.eclipse.jdt.ui.wizards.JavaProjectWizard)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.newWizard(newWizardId=org.eclipse.jdt.ui.wizards.JavaProjectWizard)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.newWizard(newWizardId=org.eclipse.jdt.ui.wizards.JavaProjectWizard)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.newWizard(newWizardId=org.eclipse.jdt.ui.wizards.JavaProjectWizard)%22)
  • 8/3/2019 Eclipse-Java Development User Guide

    15/84

    3. In the Package Explorer, expand theJUnitproject and select the source foldersrc.

    4. Select the menu item File > Import....

    5. Expand General, select Archive file, and clickNext.

    6. Click the Browse button next to the Archive file field and browse to select

    /junit381src.jarNote: This step assumes that you followed steps 1 and 2 in the Getting the Sample Codesection above.

    7. In the Import wizard, expand the root node, press Deselect All and select only thejunitnode. You can expand and select elements within thejunitdirectory on the left pane toview the individual resources that you are importing on the right pane. Note: Do notdeselect any of the resources in the junit directory at this time. You will need all of theseresources in the tutorial.

  • 8/3/2019 Eclipse-Java Development User Guide

    16/84

    8. Make sure that the JUnit project's source folder appears in the destination Into folderfield. Then clickFinish. In the import progress indicator, notice that the importedresources are compiled as they are imported into the workbench. This is because theBuild automatically option is checked on the Workbench preferences page.

    9. In the Package Explorer view, expand the JUnit project and the src folder to view the

    JUnit packages.

    Next Section:Browsing Java elements using the package explorer

    Java projectsJava views

    New Java Project WizardPackage Explorer View

    2.1.3. Browsing Java elements using thepackage explorerIn this section, you will browse Java elements within the JUnit project.

    1.

    In the Package Explorer view, make sure the JUnit project and the source folder areexpanded so you can see the packages.

    2. Expand the package junit.framework to see the Java files contained in the package.

    3. Expand the Java file TestCase.java. Note that the Package Explorer shows Java-specific sub-elements of the source code file. The public type and its members (fieldsand methods) appear in the tree.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-4.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-4.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-project.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-java-project.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-view-package-explorer.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-4.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-project.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-java-project.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-view-package-explorer.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    17/84

    Next Section:Opening a Java editor

    Java views

    Package Explorer View

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-OpenJavaEditor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-OpenJavaEditor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-view-package-explorer.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-OpenJavaEditor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-view-package-explorer.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    18/84

    2.1.4.1. Opening a Java editorIn this section, you will learn how to open an editor for Java files. You will also learn aboutsome of the basic Java editor features.

    1. Expand the packagejunit.samples and select the file VectorTest.java. You can open

    VectorTest.java in the Java editor by double clicking on it. In general you can open a Javaeditor for Java files, types, methods and fields by simply double clicking on them. Forexample, to open the editor directly on the method testClone defined in VectorTest.java,expand the file in the Package Explorer and double click on the method.

    2. Notice the syntax highlighting. Different kinds of elements in the Java source arerendered in unique colors. Examples of Java source elements that are rendereddifferently are:

    Regular comments

    Javadoc comments

    Keywords

    Strings

  • 8/3/2019 Eclipse-Java Development User Guide

    19/84

    3. Look at the Outline view. It displays an outline of the Java file including the packagedeclaration, import declarations, fields, types and methods. The Outline view uses icons

    to annotate Java elements. For example, icons indicate whether a Java element is static (

    ), abstract ( ), or final ( ). Different icons show you whether a method overrides a

    method from a base class ( ) or when it implements a method from an interface ( ).

    4. Toggle the Hide Fields, Hide Static Members, and Hide Non-Public Members buttonsin the Outline view toolbar to filter the view's display. Before going to the next step makesure that the Hide Non-Public Members and Hide Static Fields and Methods buttonsare not pressed.

    5. In the Outline view, select different elements and note that they are again displayed in awhole file view in the editor. The Outline view selection now contains a range indicator

  • 8/3/2019 Eclipse-Java Development User Guide

    20/84

    on the vertical ruler on the left border of the Java editor that indicates the range of theselected element.

    Next Section:Using quick views

    Java viewsJava editorSorting elements in Java views

    Java Outline ViewJava Editor Preferences

    2.1.4.2. Using quick viewsIn this section, you will be introduced to the quick outline view. Quick views are in-place viewswhich are shown on top of the editor area and can easily be controlled using the keyboard. Asecond quick view will be introduced in theType Hierarchy section.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-Quickviews.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-Quickviews.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views-sorting.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-view-outline.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-Quickviews.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views-sorting.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-view-outline.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    21/84

    Quick OutlineTo use the quick outline view in the Java editor:

    1. Openjunit.samples.VectorTest.java file in the Java editor if you do not already have itopen.

    2. Press Ctrl+O or select Navigate > Quick Outline and you will see an in-place outline ofthe current source file.

    3. Press Ctrl+O a second time and all inherited fields, types and methods are shown as well.Inherited members are shown in grey.

    4. Start typing while the quick outline view is shown to filter the list of displayed elements.Further, use the arrow keys to navigate in the outline view and press Enter to reveal the

  • 8/3/2019 Eclipse-Java Development User Guide

    22/84

    selected element in the Java editor.

    5. Click the triangle in the upper right corner to see the quick view menu:

    The menu items can be divided into 3 categories: Position - Allows you to resize and move the quick view and to remember these

    settings

    Filter- Define filters so that not all members are shown in the quick outline.

    Sort- Sort the members by their defining type or alphabetically.

    Note:Ctrl+O always opens the outline for the current Java editor. Press Ctrl+F3 to open thequick outline for the currently selected type.

  • 8/3/2019 Eclipse-Java Development User Guide

    23/84

    Next Section:Adding new methods

    2.1.4.3. Adding new methods1. Start adding a method by typing the following at the end of the VectorTest.java file (but

    before the closing brace of the type) in the Java editor:public void testSizeIsThree()

    As soon as you type the method name in the editor area, the new method appears at thebottom of the Outline view.

    In addition,

    error annotations (red boxes) appear in the overview ruler positioned on the right

    hand side of the editor,

    error icons appear in the vertical ruler positioned on the left of the editor,

    an error indicator appears in the top right corner of the editor,

    errors are marked in the text.

    These error annotations indicate that the compilation unit is currently not correct. If youhover over the error in the text, a tool tip appears: Syntax error on token ")", { expectedafter this token. This is correct since the method doesn't have a body yet. Note that error

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-AddMethod.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-AddMethod.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-AddMethod.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    24/84

    annotations in the editor are updated as you type. This behavior can be controlled via the

    Report problems as you type option located on the Java > Editor preference page.

    2. Click the Save button. The compilation unit is compiled automatically and errors appearin the Package Explorer view, in the Problems view and on the vertical ruler (left handside of the editor). In the Package Explorer view, the errors are propagated up to theproject of the compilation unit containing the error.

    http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaEditorPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaEditorPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.JavaEditorPreferencePage)%22)
  • 8/3/2019 Eclipse-Java Development User Guide

    25/84

    3. Complete the new method by typing the following:

    {

    //TODO: Check size

    Note that the closing curly brace has been inserted automatically.

    4. Save the file. Notice that the error indicators disappear since the missing brace has beenadded.

    Next Section:Using content assist

    Java editor

    Java Editor Preferences

    2.1.4.4. Using content assistIn this section you will use content assistto finish writing a new method. Open the filejunit.samples/VectorTest.java in the Java editor if you do not already have it open and select the

    testSizeIsThree() method in the Outline view. If the file doesn't contain such a method seeAdding new methods for instructions on how to add this method.

    1. Replace the TODO comment with the following lines.

    assertTrue(fFull.size() == 3);

    Vector v = new Vector();

    for (int i=0; i

  • 8/3/2019 Eclipse-Java Development User Guide

    26/84

    2. With your cursor at the end of the word assert, press Ctrl+Space to activate contentassist. The content assist window with a list of proposals will appear. Scroll the list to seethe available choices.

    3. With the content assist window still active, type the letter 't' in the source code afterassert (with no space in between). The list is narrowed and only shows entries startingwith 'assert'. Single-click various items in the list to view any available Javadoc help foreach item.

    4. Select assertTrue(boolean) from the list and press Enter. The code for theassertTrue(boolean) method is inserted.

    5. Complete the line so that it reads as follows:

    assertTrue(v.size() == fFull.size());

    6. Save the file.

    Next Section:Identifying problems in your code

    Java editor

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-7.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-7.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-7.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    27/84

    Java Content AssistJava Editor Preferences

    2.1.4.5. Identifying problems in your codeIn this section, you will review the different indicators for identifying problems in your code.

    Build problems are displayed in the Problems view and annotated in the vertical ruler of yoursource code.

    1. Openjunit.framework/TestCase.java in the editor from the Package Explorer view.

    2. Add a syntax error by deleting the semicolon at the end of the package declaration in thesource code.

    3. Click the Save button. The project is rebuilt and the problem is indicated in several ways:

    In the Problems view, the problems are listed,

    In the Package Explorer view, the Type Hierarchy or the Outline view, problem

    ticks appear on the affected Java elements and their parent elements,

    In the editor's vertical ruler, a problem marker is displayed near the affected line,

    Squiggly lines appear under the word which might have caused the error, and

    The editor tab is annotated with a problem marker.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-java-editor-code-assist.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-java-editor-code-assist.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    28/84

    4. You can hover over the marked word in the editor to view a description of the problem.You can also hover over the problem markers in the vertical or overview rulers.

    5. Click the Close ("X") button on the editor's tab to close the editor.

    6. In the Problems view, select a problem in the list. Open its context menu and select GoTo. The file is opened in the editor at the location of the problem.

  • 8/3/2019 Eclipse-Java Development User Guide

    29/84

    7. Correct the problem in the editor by adding the semicolon. Click the Save button. The

    project is rebuilt and the problem indicators disappear.8. In the Outline view, select the methodgetName(). The editor will scroll to this method.

    9. On the first line of the method change the returned variable fName to fTestName. Whileyou type, a problem highlight underline appears on fTestName, to indicate a problem.Hovering over the highlighted problem will display a description of the problem andapplicable quick fixes.

    10. On the marker bar a light bulb marker appears. The light bulb signals that correctionproposals are available for this problem.

    11.Click to place the cursor onto the highlighted error, and choose Quick Fix from the Editmenu bar. You can also press Ctrl+1 or left click the light bulb. A selection dialogappears with possible corrections.

  • 8/3/2019 Eclipse-Java Development User Guide

    30/84

    12.Select 'Change to fName' to fix the problem. The problem highlight line will disappear asthe correction is applied.

    13. Close the file without saving.

    14.You can configure how problems are indicated on the General > Editors > TextEditors > Annotations preference page.

    Next Section:Using code templates

    Java editorJava viewsJava builder

    Editor preference pageQuick fix

    2.1.4.6. Using code templatesIn this section you will use content assist to fill in a template for a common loop structure. Openjunit.samples/VectorTest.java file in the Java editor if you do not already have it open.

    1. Start adding a new method by typing the following:

    public void testValues() {Integer[] expected= new Integer[3];

    for

    2. With the cursor at the end offor, press Ctrl+Space to enable content assist. You willsee a list of common templates for "for" loops. When you single-click a template, orselect it with the Up orDown arrow keys, you'll see the code for the template in its helpmessage. Note that the local array name is guessed automatically.

    http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.editors.preferencePages.Annotations)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.editors.preferencePages.Annotations)%22)http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-EditorTemplates.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-EditorTemplates.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-builder.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-builder.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-java-editor-quickfix.htmhttp://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.editors.preferencePages.Annotations)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.editors.preferencePages.Annotations)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.editors.preferencePages.Annotations)%22)http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-EditorTemplates.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-builder.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-java-editor-quickfix.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    31/84

    3. Choose the for - iterate over array entry and press Enter to confirm the template.The template will be inserted in your source code.

    4. Next we change the name of the index variable from i to e. To do so simply press e, asthe index variable is automatically selected. Observe that the name of the index variablechanges at all places. When inserting a template all references to the same variable areconnected to each other. So changing one changes all the other values as well.

    5. Pressing the tab key moves the cursor to the next variable of the code template. This isthe array expected.

    Since we don't want to change the name (it was guessed right by the template) we presstab again, which leaves the template since there aren't any variables left to edit.

    6. Complete the for loop as follows:

    for (int e= 0; e < expected.length; e++) {

    expected[e]= new Integer(e + 1);

  • 8/3/2019 Eclipse-Java Development User Guide

    32/84

    }

    Integer[] actual= to

    7. With the cursor at the end ofto, press Ctrl+Space to enable content assist. Picktoarray - convert collection to array and press Enter to confirm the selection(or double-click the selection).

    The template is inserted in the editor and type is highlighted and selected.

    8.Overwrite the selection by typing Integer. The type of array constructor changes whenyou change the selection.

    9. Press Tab to move the selection to collection and overwrite it by typing fFull.

    10. Add a semicolon and the following lines of code to complete the method:assertEquals(expected.length, actual.length);

    for (int i= 0; i < actual.length; i++)

    assertEquals(expected[i], actual[i]);

    11. Save the file.

    Next Section:Organizing import statements

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-OrganizeImports.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-OrganizeImports.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-OrganizeImports.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    33/84

    Java editorTemplates

    Templates PreferencesJava Editor Preferences

    2.1.4.7. Organizing import statementsIn this section you will organize the import declarations in your source code. Openjunit.samples/VectorTest.java file in the Java editor if you do not already have it open.

    1. Delete the import declarations by selecting them in the Outline view and selecting Deletefrom the context menu. Confirm the resulting dialog with Yes. You will see numerous

    compiler warnings in the vertical ruler since the types used in the method are no longerimported.

    2. From the context menu in the editor, select Source > Organize Imports. The requiredimport statements are added to the beginning of your code below the package declaration.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-editor-templates.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/editor/ref-preferences-templates.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-editor-templates.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/editor/ref-preferences-templates.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-editor.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    34/84

    You can also choose Organize Imports from the context menu of the importdeclarations in the Outline view.

    Note: You can specify the order of the import declarations using the Java > CodeStyle > Organize Imports preference page.

    3. Save the file.

    Next Section:Using the local history

    Java editor

    Organize Imports Preferences

    2.1.4.8. Using the local historyIn this section, you will use the local history feature to switch to a previously saved version of anindividual Java element.

    1. Openjunit.samples/VectorTest.java file in the Java editor and select the methodtestCapacity() in the Outline view.

    2. Change the content of the method so that the 'for' statements reads as:

    for (int i= 0; i < 99; i++)

    Save the file by pressing Ctrl+S.

    3. In the Outline view, select the method testCapacity(), and from its context menu,select Replace With > Element from Local History.

    4. In the Replace Java Element from Local History dialog, the Local History list showsthe various saved states of the method. The Java Source Compare pane shows details ofthe differences between the selected history resource and the existing workbenchresource.

    http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.ImportOrganizePreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.ImportOrganizePreferencePage)%22)http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-LocalHistory.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-LocalHistory.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/codestyle/ref-preferences-organize-imports.htmhttp://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.ImportOrganizePreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.ImportOrganizePreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.ImportOrganizePreferencePage)%22)http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-LocalHistory.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/codestyle/ref-preferences-organize-imports.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    35/84

    5. In the top pane, select the previous version, and click the Replace button. In the Javaeditor, the method is replaced with the selected history version.

    6. Save the file.

    7. Beside replacing a method's version with a previous one you can also restore Java

    elements that were deleted. Again, select the method testCapacity() in the Outline view,and from its context menu, select Delete. Confirm the resulting dialog with Yes and savethe file.

    8. Now select the type VectorTestin the Outline view, and from its context menu, selectRestore from Local History.... Select and check the method testCapacity() in theAvailable Java Elements pane. As before, the Local History pane shows the versionssaved in the local history.

  • 8/3/2019 Eclipse-Java Development User Guide

    36/84

    9. In the Local History pane, select the earlier working version and then clickRestore.

    Next Section:Extracting a new method

    Java editor

    Using the local history

    2.1.4.9. Extracting a new methodIn this section, you will improve the code of the constructor ofjunit.framework.TestSuite. Tomake the intent of the code clearer, you will extract the code that collects test cases from baseclasses into a new method called collectTestMethods.

    1. In thejunit.framework/TestSuite.java file, select the following range of code inside theTestSuite(Class) constructor:

    Class superClass= theClass;Vector names= new Vector();

    while(Test.class.isAssignableFrom(superClass)) {

    Method[] methods= superClass.getDeclaredMethods();

    for (int i= 0; i < methods.length; i++) {

    addTestMethod(methods[i],names, constructor);

    }

    superClass= superClass.getSuperclass();

    }

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-ExtractMethod.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-ExtractMethod.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/tasks-62.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-ExtractMethod.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/tasks-62.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    37/84

    2. From the selection's context menu in the editor, select Refactor > Extract Method....

    3. In the Method Name field, type collectInheritedTests.

  • 8/3/2019 Eclipse-Java Development User Guide

    38/84

    4. To preview the changes, press Preview>.The preview page displays the changes that will

    be made. Press OKto extract the method.

  • 8/3/2019 Eclipse-Java Development User Guide

    39/84

    5. Go to the extracted method by selecting it in the Outline view.

  • 8/3/2019 Eclipse-Java Development User Guide

    40/84

    Next Section:Creating a Java class

    Java editorRefactoring support

    Java Preferences

    2.1.5. Creating a Java classIn this section, you will create a new Java class and add methods using code generation actions.

    1. In the Package Explorer view, select the JUnit project. Click the New Java Packagebutton in the toolbar, or select New > Package from the project's context menu .

    2. In the Name field, type testas the name for the new package. Then clickFinish.

    3. In the Package Explorer view, select the new testpackage and click the New Java Classbutton in the toolbar.

    4. Make sure thatJUnitappears in the Source Folder field and that testappears inthe Package field. In the Name field, type MyTestCase.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-9.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-9.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-refactoring.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-9.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-refactoring.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    41/84

    5. Click the Browse button next to the Superclass field.

    6. In the Choose a type field in the Superclass Selection dialog, type Testto narrow the listof available superclasses.

  • 8/3/2019 Eclipse-Java Development User Guide

    42/84

    7. Select the TestCase class and clickOK.

    8. Select the checkbox forConstructors from superclass.

    9. ClickFinish to create the new class.

  • 8/3/2019 Eclipse-Java Development User Guide

    43/84

    10.The new file is opened in the editor. It contains the new class, the constructor andcomments. You can select options for the creation and configuration of generated

    comments in the Java > Code Style > Code Templates preference page.

    11.In the Outline view select the new class MyTestCase. Open the context menu and

    select Source > Override/Implement Methods....

    http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeTemplatePreferencePage)%22)
  • 8/3/2019 Eclipse-Java Development User Guide

    44/84

    12.In the Override Methods dialog, checksetUp() and tearDown() and clickOK. Twomethods are added to the class.

  • 8/3/2019 Eclipse-Java Development User Guide

    45/84

    13.Change the body ofsetUp() to container= new Vector();

    14.containerand Vectorare underlined with a problem highlight line as they cannot beresolved. A light bulb appears on the marker bar. Move the mouse over the underlinedword Vector. A hover appears that shows the error message and contains quick fixes.Move the mouse into the hover and clickImport 'Vector' (java.util). This adds themissing import declaration.

    The blinking cursor should still be on the line that contains the error (if not, set it to theend of the line). Press Ctrl+1. This lets the cursor jump to the nearest error location andopens the quick fix proposals. Choose Create field 'container'to add the new field.

  • 8/3/2019 Eclipse-Java Development User Guide

    46/84

    15.In the Outline view, select the class MyTestCase. Open the context menu and selectSource > Generate Getters and Setters....

    16.The Generate Getter and Setter dialog suggests that you create the methods getContainerand setContainer. Select both and clickOK. A getter and setter method for the fieldcontainer are added.

  • 8/3/2019 Eclipse-Java Development User Guide

    47/84

    17. Save the file.

    18.The formatting of generated code can be configured in the Java > Code Style >Formatterpreference page. If you use a prefix or suffix for field names (e.g. fContainer),

    you can specify this in the Java > Code Style preference page so that generated gettersand setters will suggest method names without the prefix or suffix.

    Next Section:Renaming Java elements

    Java viewsJava editor

    New Java Class wizardSource actionsQuick fix

    http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeStylePreferencePage)%22)http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-8.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-8.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-class.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-menu-source.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-java-editor-quickfix.htmhttp://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeStylePreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeFormatterPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.ui.preferences.CodeStylePreferencePage)%22)http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-8.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-class.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-menu-source.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-java-editor-quickfix.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    48/84

    Override methods dialogGenerate Getter and Setter dialogCode formatter preference pageCode style preference pageCode templates preference page

    2.1.6. Renaming Java elementsIn this section, you will rename a Java element using refactoring. Refactoring actions change thestructure of your code without changing its semantics (behavior).

    1. In the Package Explorer view, selectjunit.framework/TestCase.java.

    2. From its context menu, select Refactor > Rename.

    3. In the New Name field on the Rename Compilation Unit page, type "TestCase2".

    4. To preview the changes that will be made as a result of renaming the class, press Next.

    5. The workbench analyzes the proposed change and presents you with a preview of thechanges that would take place if you rename this resource.

    Since renaming a compilation unit will affect the import statements in other compilationunits, there are other compilation units affected by the change. These are shown in a listof changes in the preview pane.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-dialog-override-method.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-dialog-gettersetter.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/codestyle/ref-preferences-formatter.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-code-style.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/codestyle/ref-preferences-code-templates.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-dialog-override-method.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-dialog-gettersetter.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/codestyle/ref-preferences-formatter.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/ref-preferences-code-style.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/java/codestyle/ref-preferences-code-templates.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    49/84

    6. On the Refactoring preview page, you can scroll through the proposed changes and selector deselect changes, if necessary. You will typically accept all of the proposed changes.

    7. ClickFinish to accept all proposed changes.

    You have seen that a refactoring action can cause many changes in different compilation units.These changes can be undone as a group.

    1. In the menu bar, select Edit > Undo Rename Compilation Unit.

  • 8/3/2019 Eclipse-Java Development User Guide

    50/84

    2. The refactoring changes are undone, and the workbench returns to its previous state. Youcan undo refactoring actions right up until you change and save a compilation unit, atwhich time the refactoring undo buffer is cleared.

    Next Section:Moving and copying Java elements

    Refactoring support

    Refactoring actionsRefactoring wizardJava preferences

    2.1.7. Moving and copying Java elementsIn this section, you will use refactoring to move a resource between Java packages. Refactoringactions change the structure of your code without changing its semantic behavior.

    1. In the Package Explorer view, select the MyTestCase.java file from the testpackage anddrag it into thejunit.samples package. Dragging and dropping the file is similar toselecting the file and choosing Refactor > Move from the context menu.

    2. You will be prompted to select whether or not to update references to the file you aremoving. Typically, you will want to do this to avoid compile errors. You can press thePreviewbutton to see the list of changes that will be made as a result of the move.

    3. Press OK. The file is moved, and its package declaration changes to reflect the newlocation.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-10.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-10.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-refactoring.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-menu-refactor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-refactorings.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-10.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-refactoring.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-menu-refactor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-refactorings.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    51/84

    4. Use Edit > Undo Move to undo the move.

    The context menu is an alternative to using drag and drop. When using the menu, you mustspecify a target package in the Move dialog, in addition to selecting the update referencesoptions you've already seen.

    1. Select the MyTestCase.java file and from its context menu, select Refactor > Move.

    2. In the Move dialog, expand the hierarchy to browse the possible new locations for theresource. Select thejunit.samples package, then clickOK. The class is moved, and itspackage declaration is updated to the new location.

  • 8/3/2019 Eclipse-Java Development User Guide

    52/84

    Next Section:Navigate to a Java element's declaration

    Java viewsRefactoring support

    Refactoring actionsRefactoring wizardJava preferences

    2.1.8. Navigate to a Java element'sdeclarationIn this section, you will learn how to open a type in the Java Editor and how to navigate torelated types and members.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-Navigate.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-Navigate.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-refactoring.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-menu-refactor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-refactorings.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-Navigate.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-views.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-refactoring.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-menu-refactor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-refactorings.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    53/84

    1. Open the Open Type dialog by pressing Ctrl+Shift+T, choosing Navigate > Open

    Type..., or clicking the toolbar icon ( ). Type Money, press the Arrow Down key a fewtimes to select MoneyTest, and then press Enter to open the type in the Java editor.

    2. On the first line of the MoneyTestclass declaration, select the superclass TestCase andeither

    from the menu bar select Navigate > Open Declaration or

    press F3.

  • 8/3/2019 Eclipse-Java Development User Guide

    54/84

    The TestCase class opens in the editor area and is also represented in the Outline view.

    Note: This command also works on methods and fields.

    3. With the TestCase.java editor open and the class declaration selected:

    from the menu bar select Navigate > Open Type Hierarchy or

  • 8/3/2019 Eclipse-Java Development User Guide

    55/84

    press F4.

    4. The Type Hierarchy view opens with the TestCase class displayed.

    Note: You can also open editors on types and methods in the Type Hierarchy view.

    Next Section:Viewing the type hierarchy

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-6.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-6.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-6.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    56/84

    Opening an editor for a selected element

    Type Hierarchy View

    2.1.9. Viewing the type hierarchyIn this section, you will learn about using the Type Hierarchy view by viewing classes andmembers in a variety of different ways.

    1. In the Package Explorer view, findjunit.framework/TestCase.java. From its context

    menu, select Open Type Hierarchy. You can also open type hierarchy view:

    from the menu bar by selecting Navigate > Open Type Hierarchy.

    from the keyboard by pressing F4 after selecting TestCase.java.

    2. The buttons in the view tool bar control which part of the hierarchy is shown. Click

    the Show the Type Hierarchybutton to see the class hierarchy, including the baseclasses and subclasses. The small arrow on the left side of the type icon of TestCaseindicates that the hierarchy was opened on this type.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/tasks-73.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-type-hierarchy.htmhttp://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.jdt.ui.commands.showElementInTypeHierarchyView(elementRef=JUnit/junit.framework.TestCase)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.jdt.ui.commands.showElementInTypeHierarchyView(elementRef=JUnit/junit.framework.TestCase)%22)http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/tasks-73.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-type-hierarchy.htmhttp://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.jdt.ui.commands.showElementInTypeHierarchyView(elementRef=JUnit/junit.framework.TestCase)%22)
  • 8/3/2019 Eclipse-Java Development User Guide

    57/84

    3. Click the Show the Supertype Hierarchy button to see a hierarchy showing the type'sparent elements including implemented interfaces. This view shows the results of goingup the type hierarchy.

    In this "reversed hierarchy" view, you can see that TestCase implements the Testinterface.

    4. Click the Show the Subtype Hierarchy button in the view toolbar.

  • 8/3/2019 Eclipse-Java Development User Guide

    58/84

    5. Click the Lock View and Show Members in Hierarchy button in the toolbar of themember pane, then select the runTest() method in the member pane. The view will now

    show all the types implementing runTest().

  • 8/3/2019 Eclipse-Java Development User Guide

    59/84

    6. In the Type Hierarchy view, click the Show the Supertype Hierarchy button. Then onthe member pane, select countTestCases() to display the places where this method isdeclared.

  • 8/3/2019 Eclipse-Java Development User Guide

    60/84

    7. In the Type Hierarchy view select the Testelement and select Focus On 'Test' from itscontext menu. Testis presented in the Type Hierarchy view.

    8. Activate the Package Explorer view and select the package junit.framework. Use OpenType Hierarchy from its context menu. A hierarchy is opened containing all classes ofthe package. For completion of the tree, the hierarchy also shows some classes from otherpackages. These types are shown by a type icon with a white fill.

  • 8/3/2019 Eclipse-Java Development User Guide

    61/84

    9. Use Previous Type Hierarchies to go back to a previously opened element. Click on thearrow next to the button to see a list of elements or click on the button to edit the historylist.

    If you are working in the editor and only want to do a quick lookup for a hierarchy you can usethe Quick Type Hierarchy:

    1. Openjunit.framework.TestCase.java file in the Java editor if you do not already have itopen.

    2. Select the type name in the Java editor

  • 8/3/2019 Eclipse-Java Development User Guide

    62/84

    3. Press Ctrl+T or invoke Navigate > Quick Type Hierarchy and the in-place typehierarchy view is shown.

    4. Pressing Ctrl+T while the type hierarchy view is shown will toggle between supertypehierarchy and subtype hierarchy.

    To see where a virtual method call can resolve to:

    1. In the body ofrunBare() select the invocation ofsetUp()

    2. Press Ctrl+T or invoke Navigate > Quick Type Hierarchy and the in-place typehierarchy view is shown.

    3. You can see thatsetUp() is implemented in 3 more classes. ObjectandAssertare onlyshown with a white filled images as are only required to complete the hierarchy but donot implementsetUp()

    4. Select a type to navigate to its implementation ofsetUp()

  • 8/3/2019 Eclipse-Java Development User Guide

    63/84

    Next Section:Searching the workbench

    Java views

    Type Hierarchy viewJava Base preference page

    2.1.10. Searching the workbenchIn this section, you will search the workbench for Java elements.

    In the Search dialog, you can perform file, text or Java searches. Java searches operate on thestructure of the code. File searches operate on the files by name and/or text content. Javasearches are faster, since there is an underlying indexing structure for the code structure. Textsearches allow you to find matches inside comments and strings.

    Performing a Java search from the workbench

    1. In the Java perspective, click the Search ( ) button in the workbench toolbar or use

    Search > Java... from the menu bar.2. If it is not already selected, select the Java Search tab.

    3. In the Search string field, type runTest. In the Search Forarea, select Method, and intheLimit To area, select References.Verify that the Scope is set to Workspace.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-11.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-11.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-type-hierarchy.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-11.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-editor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/ref-type-hierarchy.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    64/84

    Then clickSearch. While searching you may clickCancel at any time to stop the search.Partial results will be shown.

    4. In the Java perspective, the Search view shows the search results.

    Use the Show Next Match ( ) and Show Previous Match ( ) buttons to navigate toeach match. If the file in which the match was found is not currently open, it is opened inan editor.

    5. When you navigate to a search match using the Search view buttons, the file opens in theeditor at the position of the match. Search matches are tagged with a search marker in therulers.

  • 8/3/2019 Eclipse-Java Development User Guide

    65/84

    Searching from a Java viewJava searches can also be performed from specific views, including the Outline, Type Hierarchyview and the Package Explorer view.

    1. In the Package Explorer view, double-clickjunit.framework.Assert.java to open it in aneditor.

    2. In the Outline view, select the fail(String) method, and from its context menu,select References > Workspace.

  • 8/3/2019 Eclipse-Java Development User Guide

    66/84

    Searching from an editorFrom the Package Explorer view, openjunit.framework.TestCase.java. In the editor, select theclass name TestCase and from the context menu, select References > Workspace.

  • 8/3/2019 Eclipse-Java Development User Guide

    67/84

    Continuing a search from the search viewThe Search Results view shows the results for the TestCase search. Select a search result andopen the context menu. You can continue searching the selected element's references anddeclarations.

  • 8/3/2019 Eclipse-Java Development User Guide

    68/84

    If you want to follow multiple levels of method calls, you can also use Navigate > Open CallHierarchy.

    Performing a file search1. In the Java perspective, click the Search button in the workbench toolbar or select

    Search > File from the menu bar.

    2. If it is not already selected, select the File Search tab.

    3. In the Containing text field, type TestCase. Make sure that the File name patterns field

    is set to *.java. The Scope should be set to Workspace. Then clickSearch.

  • 8/3/2019 Eclipse-Java Development User Guide

    69/84

    4. To find all files of a given file name pattern, leave the Containing Text field empty.

    Viewing previous search resultsIn the Search Results view, click the arrow next to the Previous Search Results toolbar button

    to see a menu containing the list of the most recent searches. You can choose items from thismenu to view previous searches. The list can be cleared by choosing Clear History.

    The Previous Search Results button will display a dialog with the list of all previous searchesfrom the current session.

  • 8/3/2019 Eclipse-Java Development User Guide

    70/84

    Selecting a previous search from this dialog will let you view that search.

    Next Section:Running your programs

    Java search

    Refactoring actionsRefactoring wizardJava preferences

    2.1.11. Running your programsIn this section, you will learn more about running Java programs in the workbench.

    1. In the Package Explorer view, findjunit.textui/TestRunner.java and double-click it toopen it in an editor.

    2. In the Outline view, notice that the TestRunner class has an icon which indicates that theclass defines a main method.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-12.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-12.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-search.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-menu-refactor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-refactorings.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-12.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/concepts/concept-java-search.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-menu-refactor.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-wizard-refactorings.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/preferences/ref-preferences-java.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    71/84

    3. Right click on TestRunner.java in the Package Explorer and select Run As > JavaApplication. This will launch the selected class as a local Java application. The Run Ascontext menu item is also available in other places, such as the Outline view.

    4. Notice that the program has finished running and the following message appears in theConsole view telling you that the program needs an execution argument. Running class

  • 8/3/2019 Eclipse-Java Development User Guide

    72/84

    from the Package Explorer as a Java Application uses the default settings for launchingthe selected class and does not allow you to specify any arguments.

    5. To specify arguments, use the drop-down Run menu in the toolbar and select RunConfigurations....

    You can also Ctrl+Click a configuration in the drop-down menu to start editing thatconfiguration.

    6. This time, the Launch Configurations dialog opens with the TestRunner launch

    configuration selected. A launch configuration allows you to configure how a program islaunched, including its arguments, classpath, and other options. (A default launchconfiguration was created for you when you chose Run > Java Application).

  • 8/3/2019 Eclipse-Java Development User Guide

    73/84

    7. Select the Arguments tab and typejunit.samples.VectorTestin the Program argumentsarea.

    8. ClickRun. This time the program runs correctly, indicating the number of tests that wererun.

  • 8/3/2019 Eclipse-Java Development User Guide

    74/84

    9. Switch to the Debug perspective. In the Debug view, notice that a process for the lastprogram launch was registered when the program was run.

    By default, the Debug view automatically removes any terminated launches when a new

    launch is created. This preference can be configured on the Run/Debug > Launchingpreference page

    Note: You can relaunch a terminated process by selectingRelaunch from its contextmenu.

    10.Select the drop-down menu from the Run button in the workbench toolbar. This listcontains the previously launched programs. These programs can be relaunched byselecting them in the history list.

    11.By default the currently selected resource or active editor is launched when the run buttonis hit. If none of these is launchable the current project will be launched. You can

    configure this behavior under Run/Debug > Launching.

    12.From the context menu in the Debug view (or the equivalent toolbar button), selectRemove All Terminated to clear the view of terminated launch processes.

    http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.debug.ui.LaunchingPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.debug.ui.LaunchingPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.debug.ui.LaunchingPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.debug.ui.LaunchingPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.debug.ui.LaunchingPreferencePage)%22)http://tmp/svp63.tmp/javascript:executeCommand(%22org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.debug.ui.LaunchingPreferencePage)%22)
  • 8/3/2019 Eclipse-Java Development User Guide

    75/84

    Next Section:Debugging your programs

    Changing debugger launch optionsConnecting to a remote VM with the Remote Java application launch configurationDisconnecting from a VMLaunching a Java programRunning and debugging

    Debug viewRun menu actionsRun and debug toolbar actions

    2.1.12. Debugging your programsIn this section, you will debug a Java program.

    1. In the Package Explorer view in the Java perspective, double-clickjunit.samples/VectorTest.java to open it in an editor.

    2. Place your cursor on the vertical ruler along the left edge of the editor area on thefollowing line in the setUp() method:

    fFull.addElement (new Integer(1));

    and double-click on the ruler to set a breakpoint.

    The breakpoint icon indicates the status of the breakpoint. The plain blue breakpoint iconindicates that the breakpoint has been set, but not yet installed.

    Note: Once the class is loaded by the Java VM, the breakpoint will be installed and acheckmark overlay will be displayed on the breakpoint icon.

    http://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-13.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-13.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/tasks-9.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/task-remotejava_launch_config.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/task-disconnect_remote_debug.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/task-launching_java_program.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/task-running_and_debugging.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/debug/ref-debug_view.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/menus/run/ref-menu-run.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-toolbar-run.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/gettingStarted/qs-13.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/tasks-9.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/task-remotejava_launch_config.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/task-disconnect_remote_debug.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/task-launching_java_program.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/tasks/task-running_and_debugging.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/views/debug/ref-debug_view.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/menus/run/ref-menu-run.htmhttp://127.0.0.1:1043/help/topic/org.eclipse.jdt.doc.user/reference/ref-toolbar-run.htm
  • 8/3/2019 Eclipse-Java Development User Guide

    76/84

    3. In the Package Explorer view, select thejunit.samples package and select Debug As, andthen Java Application. When you run a program from a package, you will be promptedto choose a type from all classes in the package that define a main method.

    4. Select the VectorTestitem in the dialog, then clickOK.

    Note: You can also simply hit the debug button which will launch thecurrently selected resource or active editor. SelectJava Application when you areprompted to select a way to debug VectorTest.

    5. The program will run until the breakpoint is reached. When the breakpoint is hit,execution is suspended, and you are asked whether to open the Debug perspective. ClickYes. Notice that the process is still active (not terminated) in the Debug view. Otherthreads might still be running.

  • 8/3/2019 Eclipse-Java Development User Guide

    77/84

    Note: The breakpoint now has a checkmark overlay since the class VectorTest wasloaded in the Java VM.

  • 8/3/2019 Eclipse-Java Development User Guide

    78/84

    6. In the editor in the Debug perspective, select new Vector() from the line above wherethe breakpoint is set, and from its context menu, select Inspect.

    7. The expression is evaluated in the context of the current stack frame, and a pop-upappears which displays the results. You can send a result to the Expressions view bypressing the key binding displayed in the pop-up.

    8. Expressions that you evaluate while debugging a program will be listed in this view. Todelete an expression after working with it, select the expression and choose Remove fromits