Opening a Java editor

In this section, you will learn how to open an editor for Java files. You will also learn about some of the basic Java editor features.

  1. Expand the package junit.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 Java editor for Java files, types, methods and fields by simply double clicking on them. For example, 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 are rendered in unique colors.  Examples of Java source elements that are rendered differently are:

    Syntax highlighting

  3. Look at the Outline view. It displays an outline of the Java file including the package declaration, 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 (S), abstract (A), or final (F).  Different icons show you whether a method overrides a method from a base class (overridden ) or when it implements a method from an interface (implements ).

    Outline view

  4. Toggle the Hide Fields, Hide Static Members, and Hide Non-Public Members buttons in the Outline view toolbar to filter the view's display. Before going to the next step make sure that Hide Non-Public Members button is not pressed.

    Outline view tool bar

  5. You can edit source code by viewing the whole Java file, or you can narrow the view to a single Java element. The toolbar includes a button, Show Source of Selected Element Only, that will cause only the source code of the selected outline element to be displayed in the Java editor.  In the example below, only the setUp() method is displayed.

    Show selected element only tool bar button

  6. Press the Show Source of Selected Element Only button again to see the whole Java file again. In the Outline view, select different elements and note that they are again displayed in a whole file view in the editor. The Outline view selection now contains a range indicator on the vertical ruler on the left border of the Java editor that indicates the range of the selected element.

    Range indicator

Related concepts

Java views
Java editor

Related tasks

Using the Java editor
Showing and hiding elements
Showing single elements or whole Java files
Sorting elements in Java views

Related reference

Java Outline View
Java Editor Preferences