Getting Started with the Eclipse Workbench

Getting Started with the Eclipse Workbench

he Eclipse Workbench, at the most fundamental level, is merely a platform for software development tools and provides little functionality on its own. With the appropriate plug-in components, however, it’s capable of supporting any type of software development. It is most commonly used for developing using the Java programming language, in large part because the SDK version of Eclipse, (which you can download from the Eclipse site), includes the Java Development Toolkit (JDT) which, together with the basic Eclipse platform, provide a full-featured Java IDE.

Eclipse is easy to use, but the key to using it effectively is to understand the way it is organized. This excerpt from Chapter 2 of Eclipse in Action: A guide for Java developers (Manning Publications) is designed to get you up to speed quickly by introducing you to the basic elements of Eclipse user interface?perspectives, views, and editors?and showing you how to create a Java project.

A Tour of the Workbench UI
Eclipse is made up of components, and the fundamental component is the Eclipse Workbench. This is the main window that appears when you start Eclipse. The Workbench has one simple job: to allow you to work with projects. It doesn’t know anything about editing, running, or debugging Java programs; it only knows how to navigate projects and resources (such as files and folders). Any tasks it can’t handle, it delegates to other components, such as the Java Development Tools (JDT).

Perspectives, Views, and Editors
The Eclipse Workbench is a single application window that at any given time contains a number of different types of panes called views plus one special pane, the editor. In some cases, a single pane may contain a group of views in a tabbed notebook. Depending on the perspective, one pane might contain a console window while another might contain an outline of the currently selected project. The primary component of every perspective, however, is the editor.

Just as there are different types of documents, there are different types of editors. When you select (or create) a document in Eclipse, Eclipse does its best to open the document using the most appropriate editor. If it’s a simple text document, the document will be opened using Eclipse’s built-in text editor. If it’s a Java source file, it will be opened using the JDT’s Java editor, which has special features such as the ability to check syntax as code is typed. If it’s a Microsoft Word document on a Windows computer and Word is installed, the document will be opened using Word inside Eclipse, by means of object linking and embedding (OLE).

You don’t directly choose each of the different views in the Workbench or how they are arranged. Instead, Eclipse provides several preselected sets of views arranged in a predetermined way; they are called perspectives, and they can be customized to suit your needs.

Dragging one view on top of another will cause them to appear as a single tabbed notebook of views.
Every perspective is designed to perform a specific task, such as writing or debugging a Java program, and each of the views in the perspective is chosen to allow you to deal with different aspects of that task. For example, in a perspective for debugging, one view might show the source code, another might show the current values of the program’s variables, and yet another might show the program’s output.

The first time you start Eclipse, it will be in the Resource perspective (see Figure 1). You might think of this as the home perspective. It is a general-purpose perspective useful for creating, viewing, and managing all types of resources?whether a resource is a Java project or a set of word processing documents doesn’t matter in this perspective, apart from which editor is used to open specific documents in the editor area.

The panel at upper left is called the Navigator view; it shows a hierarchical representation of your workspace and all the projects in it. At first this view will be empty, of course; but, as you’ll see, it is the starting point for creating projects and working with Eclipse.

Figure 1. The Resource Perspective: The initial view is a general-purpose perspective for creating, viewing, and managing all types of resources.

Within the Workbench, as you work, you can choose among the different perspectives by selecting Window > Open Perspective. Eclipse will also change the perspective automatically, when appropriate?such as changing from the Java perspective to the Debug perspective when you choose to debug a program from the Eclipse menu.

Menus and Toolbars
In addition to perspective, views, and editors, several other features of the Workbench UI are worth mentioning: the main menu, the main toolbar, and the shortcut toolbar. Like the views and editors in a perspective, the Workbench’s menu and toolbar can change depending on the tasks and features available in the current perspective.

The Eclipse main menu appears at the top of the Workbench window, below the title bar (unless you are using a Macintosh, in which case the menu appears, Mac style, at the top of the screen). You can invoke most actions in Eclipse from the main menu or its submenus. For example, if the document HelloWorld.java is currently being edited, you can save it by selecting File > Save HelloWorld.java from the main menu.

Below the main menu is a toolbar called the main toolbar, which contains buttons that provide convenient shortcuts for commonly performed actions. One, for example, is an icon representing a floppy disk, which saves the contents of the document that is currently being edited (like the File > Save menu selection). These tool buttons don’t display labels to indicate what they do unless you position the mouse pointer over them; doing so causes a short text description to display as a hovering tool tip.

Along the left side of the screen is another toolbar called the shortcut toolbar. The buttons here provide a quick way to open a new perspective and switch between perspectives. The top button, Open a Perspective, is an alternative to the Window > Open Perspective selection in the main menu. Below it is a shortcut to the Resource perspective. As you open new perspectives, shortcuts to those perspectives appear here, as well.

You can optionally add another type of shortcut to the shortcut toolbar: a Fast View button. Fast Views provide a way to turn a view in a perspective into an icon?similar to the way you can minimize a window in many applications. For example, you may find that in the Resource perspective, you need to look at the Outline view only occasionally. To turn the Outline view into a Fast View icon, click on the Outline icon in the view’s title bar and select Fast View from the menu that appears. The Outline view is closed, and its icon appears in the shortcut toolbar. Clicking on the icon alternately opens and closes the view. To restore the view in its previous place in the perspective, right-click on the Fast View icon and select Fast View.

In addition to the Workbench menu and toolbars, views can also have menus. Every view has a menu you can select by clicking on its icon. This menu lets you perform actions on the view’s window, such as maximizing it or closing it. Generally this menu is not used for any other purpose. Views can also have a view-specific menu, which is represented in the view’s title bar by a black triangle. In the Resource perspective, the Navigator view has a menu that lets you set sorting and filtering options.

Some views also have a toolbar. In the Resource perspective, the Outline view has tool buttons that let you toggle various display options on or off.

Changing Perspectives
As you work in the Eclipse Workbench, you’ll occasionally find that the different views aren’t quite the right size for the work you’re doing?perhaps your source code is too wide for the editor area. The solution is to click on the left or right window border and drag it so the window is the right size.

Sometimes you may want to supersize a view temporarily by double-clicking on the title bar; this will maximize it within the Eclipse Workbench. Double-clicking on the title bar again will reduce it back to its regular size.

You can also move views around by dragging them using their title bars. Dragging one view on top of another will cause them to appear as a single tabbed notebook of views. Selecting a view in a notebook is like selecting a document in the editor pane: Click its tab at the top or bottom of the notebook. Dragging a view below, above, or beside another view will cause the views to dock?the space occupied by the stationary view will be redistributed between the stationary view and the view you are dragging into place. As you drag the window you want to move, the mouse pointer will become a black arrow whenever it is over a window boundary, indicating that docking is allowed. For example, if you want to make the editor area taller in the Resource perspective, drag the Task view below the Outline view so the Navigator, Outline, and Task views share a single column on the left side of the screen.

In addition to moving views around, you can remove a view from a perspective by selecting Close from the view’s title bar menu. You can also add a new view to a perspective by selecting Window > Show View from the main Eclipse menu.

Eclipse will save the changes you make to perspectives as you move from perspective to perspective or close and open Eclipse. To restore the perspective to its default appearance, select Window > Reset Perspective.

If you find that your customized perspective is particularly useful, you can add it to Eclipse’s repertoire of perspectives. From the Eclipse menu, select Window > Save Perspective As; you will be prompted to provide a name for your new perspective.

Creating and Running a Java Program
Now that you understand how the different views in perspectives work together to allow you to perform a task, let’s take Eclipse out for a spin by writing and running a traditional “Hello, world” program.

Before you can do anything else in Eclipse, such as creating a Java program, you need to create a project. To create a new Java project, follow these steps:

  1. Right-click in the Navigator view to bring up a context menu and select New > Project.
  2. In the New Project dialog box, Eclipse presents the project options: Java > Plug-in Development, and Simple. Because you want to create a Java program, select Java on the left side of the dialog box.
  3. Select Java Project on the right. If you’ve installed other types of Java development plug-ins, various other types of Java projects may potentially be listed here (EJBs and servlets, for example). But the JDT that comes standard with Eclipse only offers support for standard Java applications, so you must choose the Java Project option.
  4. Click Next to start the New Java Project Wizard.
  5. The first dialog box prompts you for a project name. This is a simple “Hello, world” example, so enter “Hello.” Clicking Next would take you to a dialog box that lets you change a number of Java build settings, but for this example you don’t need to change anything.
  6. Click Finish.
  7. Eclipse notifies you that this kind of project is associated with the Java perspective and asks whether you want to switch to the Java perspective. Check the “Don’t Show Me This Message Again” box and click Yes.

The perspective changes to a Java perspective (see Figure 2). Notice that the view in the upper-left corner is no longer the Navigator view; it is now the Package Explorer view, and it displays the new Hello project. The Package Explorer is similar to the Navigator, but it’s better suited for Java projects; for one thing, it understands Java packages and displays them as a single entry, rather than as a nested set of directories. Notice also that a new icon has appeared on the left edge of the Workbench: a shortcut for the Java perspective.

Figure 2. The Package Explorer View: This perspective is better suited for Java projects because it displays Java packages as a single entry instead of a nested set of directories.

At the bottom of the window is a Tasks view. It is useful for keeping track of what needs to be done in a project. Tasks are added to this list automatically as Eclipse encounters errors in your code. You can also add tasks to the Task view by right-clicking in the Tasks view and selecting New Task from the context menu; this is a convenient way to keep a to-do list for your project.

Finally, notice the Outline view on the right side of the screen. The content of this view depends on the type of document selected in the editor. If it’s a Java class, you can use the outline to browse class attributes and methods and move easily between them. Depending on whether the Show Source of Selected Element button in the main toolbar is toggled on or off, you can view your source as part of a file (what is sometimes referred to as a compilation unit) or as distinct Java elements, such as methods and attributes.

Creating a Java Class

The Eclipse JDT includes a special incremental compiler and evaluates your source code as you type it.
Once you’ve created a project for it to live in, you can create your first Java program. Although doing so is not necessary, it’s a good practice to organize your Java classes into packages. It’s conventional to use a domain name as the package name because this reduces the likelihood of name collisions?that is, more than one class with exactly the same name. You can use a registered domain name if you have one, but if not, you can use any convenient, unique, ad hoc name, especially for private use. Here, we’ll use org.eclipseguide. To this, add a name for this particular project: hello. All together, the package name is org.eclipseguide.hello.

Follow these steps to create your Java program:

  1. Right-click on the project and select New > Class to bring up the New Java Class Wizard.
  2. The first field, Source Folder, is by default the project’s folder?leave this as it is.
  3. Enter org.eclipseguide.hello in the Package field.
  4. In the class name field, enter HelloWorld.
  5. In the section “Which Method Stubs Would You Like to Create?,” check the box for public static void main(String[] args). The completed New Java Class dialog box is shown in Figure 3.
  6. Click Finish and the New Java Class Wizard will create the appropriate directory structure for the package (represented in the Navigator by the entry org.eclipseguide.hello under the Hello project) and the source file HelloWorld.java under this package name.
Figure 3. Hello World: the HelloWorld class using the New Java Class Wizard is shown.

In the editor area in the middle of the screen, you see the Java code generated by the wizard. Also notice that tabs now appear at the top of the editor area, which allow you to select between the Welcome screen that first appeared and this new HelloWorld.java file. (You don’t need the Welcome screen anymore, so you can click on the Welcome tab and click the X in the tab to make it go away.) You may also want to adjust the size of your windows and views to get a more complete view of the source code and the other views.

The code that’s automatically generated includes a method stub for main(). You need to add any functionality, such as printing your “Hello, world!” yourself. To do this, alter the code generated by Eclipse by adding a line to main() as follows:

  /*   * Created on Feb 14, 2003   *   * To change this generated comment go to   * Window>Preferences>Java>Code Generation>Code and Comments   */  package org.eclipseguide.hello;  /**   * @author david   */  public class HelloWorld {        public static void main(String[] args) {              System.out.println("Hello, world!");        }  }

Running the Java program
You’re now ready to run this program. There are several things you might want to consider when running a Java program, including the Java runtime it should use, whether it will take any command-line parameters, and, if more than one class has a main() method, which one to use. The standard way to start a Java program in Eclipse is to select Run > Run from the Eclipse menu. Doing so brings up a dialog box that lets you configure the launch options for the program; before running a program, you need to create a launch configuration or select an existing launch configuration.

For most simple programs, you don’t need a special launch configuration, so you can use a much easier method to start the program: First make sure the Hello World source is selected in the editor (its tab is highlighted in blue) and then do the following from the Eclipse menu:

  1. Select Run > Run As > Java Application.
  2. Because you’ve made changes to the program, Eclipse prompts you to save your changes before it runs the program. Click OK.
  3. The Task view changes to a Console view and displays your program output (see Figure 4).
Figure 4. Displaying the Output: The Eclipse Console view displays the output from the HelloWorld program.

You may wonder why no separate step is required to compile the .java file into a .class file. This is the case because the Eclipse JDT includes a special incremental compiler and evaluates your source code as you type it. Thus it can highlight things such as syntax errors and unresolved references as you type. (Like Eclipse’s other friendly features, this functionality can be turned off if you find it annoying.) If compilation is successful, the compiled .class file is saved at the same time your source file is saved.

The key to using Eclipse effectively is to understand its organizational concepts of perspectives, views, and editors. The different views that appear at one time on the Workbench, which together are called a perspective, are especially selected to enable you to accomplish a specific task, such as creating a Java project, working with source files, and running a program.

devx-admin

devx-admin

Share the Post:
Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India,

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with

Software Development

Top Software Development Companies

Looking for the best in software development? Our list of Top Software Development Companies is your gateway to finding the right tech partner. Dive in and explore the leaders in

India Web Development

Top Web Development Companies in India

In the digital race, the right web development partner is your winning edge. Dive into our curated list of top web development companies in India, and kickstart your journey to

USA Web Development

Top Web Development Companies in USA

Looking for the best web development companies in the USA? We’ve got you covered! Check out our top 10 picks to find the right partner for your online project. Your

Clean Energy Adoption

Inside Michigan’s Clean Energy Revolution

Democratic state legislators in Michigan continue to discuss and debate clean energy legislation in the hopes of establishing a comprehensive clean energy strategy for the state. A Senate committee meeting

Chips Act Revolution

European Chips Act: What is it?

In response to the intensifying worldwide technology competition, Europe has unveiled the long-awaited European Chips Act. This daring legislative proposal aims to fortify Europe’s semiconductor supply chain and enhance its

Revolutionized Low-Code

You Should Use Low-Code Platforms for Apps

As the demand for rapid software development increases, low-code platforms have emerged as a popular choice among developers for their ability to build applications with minimal coding. These platforms not

Cybersecurity Strategy

Five Powerful Strategies to Bolster Your Cybersecurity

In today’s increasingly digital landscape, businesses of all sizes must prioritize cyber security measures to defend against potential dangers. Cyber security professionals suggest five simple technological strategies to help companies

Global Layoffs

Tech Layoffs Are Getting Worse Globally

Since the start of 2023, the global technology sector has experienced a significant rise in layoffs, with over 236,000 workers being let go by 1,019 tech firms, as per data

Huawei Electric Dazzle

Huawei Dazzles with Electric Vehicles and Wireless Earbuds

During a prominent unveiling event, Huawei, the Chinese telecommunications powerhouse, kept quiet about its enigmatic new 5G phone and alleged cutting-edge chip development. Instead, Huawei astounded the audience by presenting

Cybersecurity Banking Revolution

Digital Banking Needs Cybersecurity

The banking, financial, and insurance (BFSI) sectors are pioneers in digital transformation, using web applications and application programming interfaces (APIs) to provide seamless services to customers around the world. Rising

FinTech Leadership

Terry Clune’s Fintech Empire

Over the past 30 years, Terry Clune has built a remarkable business empire, with CluneTech at the helm. The CEO and Founder has successfully created eight fintech firms, attracting renowned

The Role Of AI Within A Web Design Agency?

In the digital age, the role of Artificial Intelligence (AI) in web design is rapidly evolving, transitioning from a futuristic concept to practical tools used in design, coding, content writing

Generative AI Revolution

Is Generative AI the Next Internet?

The increasing demand for Generative AI models has led to a surge in its adoption across diverse sectors, with healthcare, automotive, and financial services being among the top beneficiaries. These

Microsoft Laptop

The New Surface Laptop Studio 2 Is Nuts

The Surface Laptop Studio 2 is a dynamic and robust all-in-one laptop designed for creators and professionals alike. It features a 14.4″ touchscreen and a cutting-edge design that is over

5G Innovations

GPU-Accelerated 5G in Japan

NTT DOCOMO, a global telecommunications giant, is set to break new ground in the industry as it prepares to launch a GPU-accelerated 5G network in Japan. This innovative approach will

AI Ethics

AI Journalism: Balancing Integrity and Innovation

An op-ed, produced using Microsoft’s Bing Chat AI software, recently appeared in the St. Louis Post-Dispatch, discussing the potential concerns surrounding the employment of artificial intelligence (AI) in journalism. These

Savings Extravaganza

Big Deal Days Extravaganza

The highly awaited Big Deal Days event for October 2023 is nearly here, scheduled for the 10th and 11th. Similar to the previous year, this autumn sale has already created

Cisco Splunk Deal

Cisco Splunk Deal Sparks Tech Acquisition Frenzy

Cisco’s recent massive purchase of Splunk, an AI-powered cybersecurity firm, for $28 billion signals a potential boost in tech deals after a year of subdued mergers and acquisitions in the

Iran Drone Expansion

Iran’s Jet-Propelled Drone Reshapes Power Balance

Iran has recently unveiled a jet-propelled variant of its Shahed series drone, marking a significant advancement in the nation’s drone technology. The new drone is poised to reshape the regional

Solar Geoengineering

Did the Overshoot Commission Shoot Down Geoengineering?

The Overshoot Commission has recently released a comprehensive report that discusses the controversial topic of Solar Geoengineering, also known as Solar Radiation Modification (SRM). The Commission’s primary objective is to

Remote Learning

Revolutionizing Remote Learning for Success

School districts are preparing to reveal a substantial technological upgrade designed to significantly improve remote learning experiences for both educators and students amid the ongoing pandemic. This major investment, which

Revolutionary SABERS Transforming

SABERS Batteries Transforming Industries

Scientists John Connell and Yi Lin from NASA’s Solid-state Architecture Batteries for Enhanced Rechargeability and Safety (SABERS) project are working on experimental solid-state battery packs that could dramatically change the

Build a Website

How Much Does It Cost to Build a Website?

Are you wondering how much it costs to build a website? The approximated cost is based on several factors, including which add-ons and platforms you choose. For example, a self-hosted

Battery Investments

Battery Startups Attract Billion-Dollar Investments

In recent times, battery startups have experienced a significant boost in investments, with three businesses obtaining over $1 billion in funding within the last month. French company Verkor amassed $2.1