Concepts / Finding Errors With the Eclipse Debugger

Finding Errors With the Eclipse Debugger

A workspace is the directory where your work is stored, and you can use several workspaces and choose one at startup.

  • Programming

Where Your Eclipse Work Lives

Imagine you have just installed Eclipse and written your first Java program. When you close the program, where does that work go, and how would you find it again next week? Eclipse answers this with a single idea: every piece of work you do in Eclipse is kept inside one place on your computer. Understanding that place, and the way the Eclipse window is arranged around your work, is the foundation for everything you will do in the environment.

This article builds that understanding in three steps. First you will look at the workspace, which is where your work is kept. Then you will look at the window, which is made of sections and views. Finally you will look at perspectives, which group those views for different jobs. Each step is followed by a short trace of what happens on screen, so you can follow the mechanism rather than memorize labels.

What do you think happens?

When you start Eclipse for the first time, what do you expect it to ask you for?

  • Nothing. It silently creates a hidden folder for your work.

  • A workspace, which is the place where your work will be kept.

  • The name of your first Java class.

Reveal answer
Answer:

A workspace, which is the place where your work will be kept.

The workspace is not created in the background without asking you. The first time you start Eclipse, it asks you to specify a workspace. You can accept the default name that is offered or type a name of your own.

Choosing a Workspace at Startup

Definition

A workspace is the directory where your work is stored. Because the workspace is a directory, the name you choose tells you where to look for your work later.

  1. 1
    Start Eclipse. Because this is your first launch, Eclipse asks you to specify a workspace.
  2. 2
    Accept the default name that Eclipse offers, or type a name of your own.
  3. 3
    Remember the name you chose, because it tells you the directory where your work is kept.
  4. 4
    On later launches, select the workspace you want. The workspace you select is the one whose contents appear in the environment for that session.

A single installation of Eclipse is not limited to one workspace. You can use multiple workspaces and select the one you want at startup. This means one installation can keep work for different purposes separate from each other, and you choose between them each time you launch the program.

Worked example

Keeping Coursework and a Separate Project Apart

You use one Eclipse installation for a course and also for a separate personal project. How do you keep the two sets of work apart?

  1. 1
    Create two workspaces

    Give one workspace a name that points to coursework, and give the other a name that points to the separate project. Each name tells you where that work lives.

  2. 2
    Choose at startup

    When you launch Eclipse, select the coursework workspace for a coursework session, or the project workspace for the project session.

  3. 3
    Check what appears

    Only the contents of the workspace you selected appear in the environment for that session. The other workspace's work is kept in its own directory and is not shown during this session.

Result

One installation holds two separate sets of work, and the workspace you select at startup decides which set you are working with.

The Eclipse Window as Sections and Views

The Eclipse graphical user interface is best understood as one large window that has been divided into several sections. Each section is not empty space waiting to be filled; it holds one or more views. A view is the component that actually shows you something. Read the picture from the outside in: the window contains sections, and each section contains views.

Eclipse windowSection oneText editor viewshows source codeSection twoI/O viewprogram input and outputProject list viewlists workspace projectscontainscontainscontainscontainscontains
What contains what? How do the sections and the views nest inside the Eclipse window?

The diagram shows one possible arrangement. The source does not fix which view appears in which section; it only says that each section holds one or more views. What the source does specify is that a view can take several forms: it can be a text editor, a place where a program can do input and output, or a list of your projects.

In the real world

Think of views as specialist panels. A text editor view shows the source code you are writing. An I/O view is the place where a running program can read input and write output. A project list view shows the projects that the workspace contains. Each view has a different job, so the window needs several of them at once, and that is why it is divided into sections in the first place.

Views Versus Perspectives

The word perspective is easiest to grasp as a grouping. Views are the individual panels. A perspective is one arrangement of those panels that suits a particular job. Changing perspective therefore changes which views make up the window, which in turn changes what the window is good for at that moment.

Text editor viewshows source codeJava Perspectivedefault for compiling andrunningI/O viewprogram input and outputDebug Perspectivehelps find semantic errorsProject list viewlists workspace projects
What is the difference between a single view and a perspective, and which perspective compiles and runs programs?

What do you think happens?

Which perspective is the default one used for compiling and running programs?

  • The Debug Perspective

  • The Java Perspective

  • The Project list view

Reveal answer
Answer:

The Java Perspective

The Java Perspective is the default for compiling and running. The Project list view is a single view, not a perspective, so it cannot be the answer.

TermWhat it isExample from the source
ViewOne panel that shows one type of informationA text editor, an I/O area, or a project list
SectionA division of the window that holds one or more viewsA section with a text editor view and tabs for other views
PerspectiveThe whole set of views in the window, arranged for a jobThe Java Perspective for compiling and running

Terms used to describe the Eclipse window

Tracing the Switch to the Debug Perspective

Suppose you are working in the Java Perspective and compiling and running a program as usual. You now want to use the Debug Perspective, which the source says helps find semantic errors. Trace what changes as you move from one perspective to the other.

  1. 1
    State one: the window shows the views that make up the Java Perspective, which is the default for compiling and running.
  2. 2
    Action: you switch to the Debug Perspective.
  3. 3
    State two: the window now shows a different arrangement of views, grouped for finding semantic errors. Your workspace and your project are still the same.
  4. 4
    Action: you switch back to the Java Perspective to compile and run again.
  5. 5
    State three: the window returns to the Java Perspective arrangement. The work itself was never moved, only the grouping of views changed.

Why might an experienced programmer switch? The source's stated purpose for the Debug Perspective is finding semantic errors. Because a perspective is a grouping of views suited to one job, moving to a grouping designed for finding errors is the natural step when the work at hand is error hunting rather than compiling and running.

Mistakes When Reading the Eclipse Window

  • Common mistake

    Treating a view and a perspective as the same thing

    What it looks like

    Saying you are in the Text editor view when you mean you are in the Java Perspective.

    Why it fails

    A view is one panel. A perspective is the whole set of views in the window, arranged for a job.

    Do this instead

    Ask whether you are talking about one panel or the whole arrangement, and use the right word.

  • Common mistake

    Assuming Eclipse silently creates your workspace

    Why it fails

    The source states that Eclipse asks you to specify a workspace the first time you start it.

    Do this instead

    Pay attention to the name you accept or type, because it tells you where your work is kept.

  • Common mistake

    Thinking switching perspectives moves your work

    Why it fails

    A perspective changes which views make up the window. It does not change the workspace or the projects in it.

    Do this instead

    Switch perspective to change the arrangement of views, and switch workspace at startup to change which set of work you are using.

  • Common mistake

    Assuming every installation shows views in the same places

    Why it fails

    The source does not fix which view appears in which section. The diagram shows one possible arrangement.

    Do this instead

    Read the window you actually have, identify the sections and the views in them, and do not rely on a fixed picture.

Practice: Sorting Views and Perspectives

EASY

A friend says, I am in the Project list view, so I am compiling my program in the Debug Perspective. Explain what is wrong with this statement, and state which perspective is used for compiling and running programs.

Hints
  • A view is one panel, while a perspective is the whole set of views arranged for a job.
  • Look up which perspective the source names as the default for compiling and running.
  • Ask whether the Debug Perspective is described as the one for compiling and running, or for finding semantic errors.
MEDIUM

You keep a coursework workspace and a separate project workspace in one Eclipse installation. Describe the steps you would take at startup to resume the project, and say what happens to the coursework work during that session.

Hints
  • The workspace you select at startup is the one whose contents appear for that session.
  • Work in the other workspace is kept in its own directory.

Key Takeaways

  • An Eclipse workspace is the directory where your work is stored. Eclipse asks you to specify one the first time you start it, and you can keep several and choose one at each startup.
  • The Eclipse window is one large window divided into sections, and each section holds one or more views. A view shows one type of information, such as a text editor, an I/O area, or a project list.
  • A perspective is the whole set of views in the window arranged for a job. The Java Perspective is the default for compiling and running programs.
  • The Debug Perspective is the arrangement the source identifies for finding semantic errors, and switching to it changes the grouping of views without moving your work.