A short name is easier to remember than a line of Java you keep typing. In Eclipse on Linux, you can create a Java editor template that lets Content Assist replace that name with a snippet.
The context of a template controls where Eclipse can offer it. The Java context makes the template available in Java code. A snippet that prints a line belongs inside a method.
Eclipse saves editor templates in the current workspace. When a template expands, the inserted text becomes ordinary Java source that you can edit in the file.
Steps to create a Java editor template in Eclipse:
Start with a Java source file open in Eclipse and an indented blank line inside a method. The pictures show Hello.java in the hello project in ~/eclipse-workspace.
- Open Window > Preferences….

- Enter
Templatesin the Preferences tree filter in place of any existing filter text.
- Select Templates under Java > Editor in the filtered tree.

- Click New… beside the Java editor templates table.

- Enter a short, unused name such as
greetlinein the Name field.
- Open the Context drop-down.

- Select Java in the Context list.

- Clear Automatically insert if it is checked.
With this box clear, Eclipse offers the template for you to choose even when it is the only match.
- Click inside the Pattern field.

- Enter the following Java statement in the Pattern field.
System.out.println("Hello");
- Click OK in the New Template dialog.

- Click Apply and Close to save the template to your workspace.

- Place the caret on the indented blank line inside a method in your Java file.

- Type your template name,
greetlinein this case, at the caret.
- Press Ctrl+Space immediately after the name to open Content Assist.

- Choose your template from the Content Assist list.
When
greetlineis highlighted, Enter inserts that proposal. - Verify that your
System.out.printlnstatement replaces the template name inside the method.