Organizing import statements

In this section you will organize the import declarations in your source code.  Open junit.samples/ file in the Java editor if you do not already have it open.

  1. By default, import declarations are hidden in the Outline view. Select View Menu > Filters... and un-check Import declarations. Click OK to make them visible in the Outline view.
  2. Delete the import declarations by selecting them in the Outline view and selecting Delete from the context menu. Confirm the resulting dialog with Yes. You will see numerous compile warnings in the vertical ruler since the types used in the method are no longer imported.

    Outline view context menu

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

    Organize imports

    You can also choose Organize Imports from the context menu of the import declarations in the Outline view.
    Note: You can specify the order of the import declarations using the Goto the organize imports preference page Java > Code Style > Organize Imports preference page.
  4. Save the file.
Java editor
Organize Imports Preferences