The Eclipse IDE for Java development PDF

Title The Eclipse IDE for Java development
Author Kute Face
Course Programming 1
Institution University of the People
Pages 158
File Size 10.2 MB
File Type PDF
Total Downloads 42
Total Views 145

Summary

Bruno James...


Description

Got it! We use cookies to personalise ads and to analyse our traffic. We also share information about your use of our site with our advertising and analytics partners. By using this site you agree to our cookie use. See details

GET MORE...   

Read Premium Content ... Book Onsite or Virtual Training Consulting

TRAINING EVENTS 

Now offering virtual, onsite and online training

Using the Eclipse IDE for Java programming - Tutorial Lars Vogel, (c) 2007 - 2020 vogella GmbHVersion 5.3,27.08.2018 TABLE OF CONTENTS  1. The Eclipse IDE for Java development o 1.1. Download o

1.2. Installation procedure

o

1.3. Starting the Eclipse IDE

o

1.4. Appearance

 o

2. Important Eclipse terminology 2.1. Workspace

o

2.2. Views and editors

o

2.3. Eclipse projects

 o

3. The Eclipse user interface 3.1. Toolbar

o

3.2. Perspectives in Eclipse

o

3.3. Resetting and customizing a perspective

 o

4. The Eclipse Java perspective 4.1. Package Explorer view

o

4.2. Outline view

o

4.3. Problems view

o

4.4. Javadoc view

o

4.5. Java editor



5. Create your first Java program

o

5.1. Create project

o

5.2. Create package

o

5.3. Create Java class

o

5.4. Run your application code from the IDE

 o o  o o 

6. Run Java program outside Eclipse 6.1. Create JAR file 6.2. Run your program outside Eclipse 7. Exercise: Java project, packages and import statements 7.1. Create project 7.2. Create classes 8. Exporting and importing projects

o

8.1. Exporting projects

o

8.2. Importing projects

o

8.3. Exercise: Export and import projects



9. Source navigation in the Eclipse IDE

o

9.1. Package Explorer or Project Explorer

o

9.2. Link Package Explorer with editor

o

9.3. Opening a class

o

9.4. Open Resource dialog to open arbitrary files

o

9.5. Quick Outline

o

9.6. Open Type Hierarchy

o

9.7. Full text search

o

9.8. Java search and other specialized searches

o

9.9. Inline search in an editor

o

9.10. Annotation navigations

o

9.11. Mouse and keyboard navigation

o

9.12. Show in Breadcrumb

o

9.13. Shortcuts

o

9.14. Closing and opening projects

 o

10. Content Assist and Quick Fix 10.1. Content assist

o

10.2. Quick Fix

o

10.3. Exercise: Convert anonymous inner classes to lambda expressions and

 

vice versa 11. Generating code 12. Exercise: code generation and content assists

o

12.1. Introduction

o

12.2. Create project

o

12.3. Create class

o

12.4. Create instances

o

12.5. Write a test class

o

12.6. Example implementation of TodoProviderTest



13. Refactoring

o

13.1. Refactoring

o

13.2. Refactoring in Eclipse

 o

14. Exercise: Refactoring 14.1. Preparation

o

14.2. Extract method

o

14.3. Extract Constant

 

15. Eclipse Shortcuts 16. Using JARs (libraries) in Eclipse

o

16.1. Adding a Java library to the project classpath

o

16.2. Using project dependencies

o

16.3. Attach source code to a Java library

o

16.4. Add Javadoc to a Java library

 o

17. Updates and installation of plug-ins 17.1. Eclipse update manager

o

17.2. Performing an update

o

17.3. Install new functionality

o

17.4. See the installed components

o

17.5. Uninstalling components

o

17.6. Restarting Eclipse

 o o  o

18. Eclipse Marketplace 18.1. Using the Marketplace client 18.2. Maintaining your Favorites 19. Advanced Eclipse Update manager options 19.1. Manual installation of plug-ins (dropins folder)

o

19.2. Exporting and importing the installed components

o

19.3. Installing features via the command line

 o

20. Eclipse preference settings 20.1. What are preferences?

o

20.2. Opening the preference dialog

o

20.3. Configuring the preference values via the plugin_customization.ini file

o

20.4. Identifying preference setting values



21. Exercise: Optimizing the Eclipse IDE settings

o

21.1. Link Java editor with the Project Explorer or Package Explorer view

o

21.2. Automatic placement of semicolon

o

21.3. Auto-escape text pasted into Strings

o

21.4. Bracket highlighting

o

21.5. Always start previous launched application

o

21.6. Filtering out certain Java packages via Type filters

o

21.7. Format source code, organize imports and code cleanup on save

o

21.8. Completion overwrites and insert guessed method arguments

o

21.9. Auto activation key for code completion

 o

22. Eclipse code checks and cleanup 22.1. Java Development Toolkit code checks

o

22.2. Configuring the code settings

o

22.3. Annotation-based Null analysis

o

22.4. Running a code cleanup and removal of trailing whitespace

 o

23. More on preference settings 23.1. Configuring the editors for a file extension

o

23.2. Export and import preference settings

o

23.3. Preference settings per project

 o

24. Using templates and code formatters 24.1. Templates

o

24.2. Code Formatter

o

24.3. Code Templates

 o o  o o 

25. Exercise: Custom code template usage 25.1. Create template for try/catch/finally 25.2. Use template 26. Eclipse command line configuration 26.1. Eclipse memory and performance settings 26.2. Eclipse startup parameters 27. Local history for files

o

27.1. Local history

o

27.2. Compare files based on local history

o

27.3. Replace files based on local history

  o

28. Organizing your workspace with working sets 29. Tasks 29.1. Task management

o

29.2. Own tags

o

29.3. Mylyn

 o

30. Eclipse online resources 30.1. Online documentations

o

30.2. Web resources

  

31. Reporting Eclipse bugs and asking questions 32. Asking (and answering) questions 33. Eclipse bug reports and feature requests

o

33.1. Reporting bugs and feature requests

o

33.2. Using the Eclipse bugzilla system

o

33.3. Eclipse bug priorities

 o   o o

34. Using Eclipse Bugzilla 34.1. Run Bugzilla query 35. Next steps 36. Eclipse Resources 36.1. Eclipse 36.2. Eclipse Bug Tracker and Eclipse forum

Get the book!

1. The Eclipse IDE for Java development The Eclipse IDE (Eclipse) is an integrated development environment (IDE) with strong support for Java. In 2020 the Eclipse IDE is one of the leading IDEs with approximately one millions downloads per month. Eclipse can be extended with additional software components called plug-ins. Pre-packaged and tested Eclipse distributions are available for download to make it easier for users to get a consistent set of functionality. Unresolved directive in 001_article.adoc - include::014_ide.adoc[] == Install the Eclipse IDE

1.1. Download The Eclipse.org website provides pre-packaged Eclipse distributions to provide downloads for typical use cases. The Eclipse IDE for Java Developers distribution is designed to support standard Java development. It includes support for the Maven and Gradle build system and support for the Git version control system. Download the Eclipse IDE for Java Developers package from the following URL: https://eclipse.org/downloads/eclipse-packages/ The following screenshot shows the Eclipse download website for a Linux system. Press on the link beside the package description, for example Linux

64-Bit to start the download. The links which are displayed depend on your operating system.

The download is a zip file, which is a compressed archive of multiple files.

1.2. Installation procedure After you downloaded the file with the Eclipse distribution, unpack it to a local directory.

As a developer person you probably know how to extract a compressed file. Most operating systems can extract zip or tar.gz files in their file browser. For example, in Windows 7 with a right-click on the file and selecting Extract all…. But if in doubt, google for "How to extract a zip (or tar.gz on Linux) file on …". Replace "…" with your operating system. It is recommended to extract Eclipse into a directory with no spaces in its path. Do not use mapped network drives as access to them is slow. Also avoid to have path names longer than 255

characters, as earlier Windows version had problems with long path names.

1.3. Starting the Eclipse IDE After you extracted the compressed file, you can start Eclipse. No additional installation procedure is required, assuming that you have a Java runtime of at least version 11 installed on your machine. To start Eclipse, double-click the eclipse.exe (Microsoft Windows) or eclipse (Linux / Mac) file in the directory where you unpacked Eclipse. What to do if the Eclipse IDE does not start The Eclipse IDE requires at least Java 8 to run. If Eclipse does not start, check your Java version. The Eclipse system prompts you for a workspace. The workspace is the location in your file system where Eclipse stores its preferences and other resources. For example, your projects can be stored in the workspace. Select an empty directory and click the

OK

button.

Eclipse starts and shows the Welcome page. Close this page by clicking the x beside Welcome.

After closing the welcome screen, the application should look similar to the following screenshot.

1.4. Appearance Some user prefer a dark styled IDE. The appearance of Eclipse can be configured. By default, Eclipse ships with a few themes but Eclipse also provides a dark theme. To change the appearance, select from the menu Window Preferences General Appearance. The Theme selection allows you to switch to the Dark theme of Eclipse.

Restart your IDE afterwards to apply all colors to the new selection, some OS styling functionality requires a restart of the application.

2. Important Eclipse terminology 2.1. Workspace The workspace is the physical location (file path) for storing meta-data and (optional) your development artifacts. The meta-data stored for the workspace contains preferences settings, plug-in specific meta data, logs etc. You can choose the workspace during startup of Eclipse or via the File Switch Workspace Others menu entry.

Your projects, source files, images and other artifacts can be stored inside or outside your workspace. For example, if you use Git as version control system, you typically would store the Git repositories outside of the workspace.

2.2. Views and editors Eclipse provides views and editors to navigate and change content. View and editors can be grouped into perspectives. A view is typically used to work on a set of data. This data might be a hierarchical structure. If data is changed via the view, the underlying data is directly changed, without the need to save. For example, the Project Explorer view allows you to browse and modify files of Eclipse projects. Any change in the Project Explorer is directly applied to the files, e.g., if you rename a file, the file system is directly changed. Editors are typically used to modify a single data element, e.g., the content of a file or a data object. Change in an editor are only applied once the user saves. For example, the Java editor is used to modify Java source files. Changes to the source file are applied once the user selects the Save button. A editor with changed data (a dirty editor) is marked with an asterisk left to the name of the modified file.

2.3. Eclipse projects An Eclipse project contains source, configuration and binary files related to a certain task. It groups them into buildable and reusable units. An Eclipse project can have natures assigned to it which describe the purpose of this project. For example, the Java nature defines a project as Java project. Projects can have multiple natures combined to model different technical aspects. Natures for a project are defined via the .project file in the project directory.

3. The Eclipse user interface 3.1. Toolbar The application toolbar contains actions which you typically perform, e.g., creating Java resources or running Java projects. It also allows you to switch between perspectives.

3.2. Perspectives in Eclipse Eclipse provides different perspectives for different tasks. The available perspectives_depend on your installation. For Java development you usually use the Java Perspective, but Eclipse has much more predefined perspectives, e.g., the Debug perspective. Eclipse allows you to switch to another perspective via the Window+Perspective Open Perspective Other… menu entry. Open editors are typically shared between perspectives, i.e., if you have an editor open in the Java perspective for a certain class and switch to the Debug perspective, this editor stays open. You can switch perspectives via the Window+Perspective Open Perspective Other… menu entry. The main perspectives used for Java development are the Java perspective and the Debug perspective. The Java perspective can be opened via Window+Perspective Open Perspective Java.

On the left hand side, this perspective shows the Package Explorer view, which allows you to browse your projects and to select the components you want to open in an editor via a double-click. For example, to open a Java source file, open the tree under src, select the corresponding .java file and double-click it. This will open the file in the default Java editor. The following picture shows the default Java perspective. The Package Explorer view is on the left. In the middle you see the open editors. Several editors are stacked in the same container and you can switch between them by clicking on the corresponding tab. Via drag and drop you can move an editor to a new position in the Eclipse IDE.

To the right and below the editor area you find more views which were considered useful by the developer of the perspective. For example, the Javadoc view shows the Javadoc of the selected class or method.

3.3. Resetting and customizing a perspective A common problem is that you changed the arrangement of views and editors in your perspective and you want to restore its original state. For example, you might have closed a view. You can reset a perspective to its original state via the Window Perspective Reset Perspective… menu entry. You can change the layout and content within a perspective by opening or closing parts and by re-arranging them. To open a new part in your current perspective, use the Window Show View Other… menu entry. This opens the Show View dialog which allows you to search for certain parts.

If you want to reset your current perspective to its default, use the Window Reset Perspective menu entry. You can save the currently selected perspective via Window+Perspective Save Perspective As….

The Window+Perspective Customize Perspective… menu entry allows you to adjust the selected perspective. For example, you can hide or show toolbar and menu entries.

4. The Eclipse Java perspective 4.1. Package Explorer view The Package Explorer view allows you to browse the structure of your projects and to open files in an editor via a double-click on the file. It is also used to change the structure of your project. For example, you can rename files or move files and folders via drag and drop. A right-click on a file or folder shows you the available options.

For more info on the Package Explorer see Chapter Source Navigation and Link Package Explorer with editor.

4.2. Outline view The Outline view shows the structure of the currently selected source file.

4.3. Problems view The Problems view shows errors and warning messages. Sooner or later you will run into problems with your code or your project setup. To view the problems in your project, you can use the Problems view which is part of the standard Java perspective. If this view is closed, you can open it via Window Show View Problems.

The messages which are displayed in the Problems view can be configured via the drop-down menu of the view. For example, to display the problems from the currently selected project, select Configure Contents and set the Scope to On any element in the same project.

The Problems view also allows you to trigger a Quick fix via a right mouseclick on several selected messages. See chapter Quick Fix for details on the Quick fix functionality.

4.4. Javadoc view The Javadoc view shows the documentation of the selected element in the Java editor.

4.5. Java editor The Java editor is used to modify the Java source code. Each Java source file is opened in a separate editor.

If you click in the left column of the editor, you can configure its properties, for example, that line number should be displayed.

5. Create your first Java program The following section describes how to create a minimal Java application using the Eclipse IDE.

5.1. Create project Select File New Java project from the menu. Enter com.vogella.eclipse.ide.first as the project name and press the Finish button to create the project.

A new project is created and displayed as a folder. Open the com.vogella.eclipse.ide.first folder and explore the content of this folder. In this tutorial the project is typically named the same as the top-level Java package in the project. This makes is easier to find a project related to a piece of code.

5.2. Create package A good naming convention is to use the same name for the top level package and the project. For example, if you name your project com.example.javaproject you should also use com.example.javaproject as the top-level package name. Create the com.vogella.eclipse.ide.first package by seleting the src folder, right-click on it and select New Package.

Press the

Finish

button.

5.3. Create Java class Right-click on your package and select New Class to create a Java class.<...


Similar Free PDFs