12. Tips and Tricks
Eclipse can make typing more efficient, if you enable a few preference settings.
Select → to open the preferences settings dialog. You can use the filter box to search for specific settings.
Select → → . In the section "Automatically insert at correct position”, check the "Semicolons" setting.
You can now type a semicolon in the middle of your code and Eclipse will position it at the end of the current statement.

Eclipse can automatically format source code and organize import statement automatically before the source code is saved. You can find this setting under → → .

Select → to open the preferences settings dialog. You can use the filter box to search for specific settings.
Select → → . In the section "Automatically insert at correct position”, check the "Semicolons" setting.
You can now type a semicolon in the middle of your code and Eclipse will position it at the end of the current statement.

Eclipse can automatically format source code and organize import statement automatically before the source code is saved. You can find this setting under → → .

If you have to frequently type the same code / part of the document, you can create templates which can be activated via autocomplete (Ctrl + Space).
For example, lets assume you are frequently creating
To create a template for this, select the menu → → → → .

Press New. Create the template show in the following screenshot.

In this example the name "npm" is your keyword.
Now every time you type "npm" in the Java editor and press Ctrl+Space the system will allow you to replace your keyword with your template.

For example, lets assume you are frequently creating
public void name(){}
methods. You could define a template which creates the method body for you.To create a template for this, select the menu → → → → .

Press New. Create the template show in the following screenshot.

${cursor}
indicates that the cursor should be placed at this position after applying the template.In this example the name "npm" is your keyword.
Now every time you type "npm" in the Java editor and press Ctrl+Space the system will allow you to replace your keyword with your template.
Eclipse generates lots of source code automatically. For example, in several cases comments are added to the source code.
Select → → → → to change the code generation templates.
In the code tree you have the templates. Select for example → and press "Edit" to edit this template and to remove the "todo" comment.

Select → → → → to change the code generation templates.
In the code tree you have the templates. Select for example → and press "Edit" to edit this template and to remove the "todo" comment.

You can export your preference settings from one workspace via → → → .
Similarly you can import them again into another workspace.
Similarly you can import them again into another workspace.
You can use
This indicates a task for Eclipse. You find those in the Task
You can open this
For example, add a TODO to your
Close the editor for the

// TODO
comments in your code to add task reminders.This indicates a task for Eclipse. You find those in the Task
View
of Eclipse. Via double-clicking on the task you can navigate to the corresponding code.You can open this
View
via → → .For example, add a TODO to your
MyFirstClass
class to see it in the Tasks View
.
package de.vogella.eclipse.ide.first;
public class MyFirstClass {
private static final String HELLO = "Hello Eclipse!";
public static void main(String[] args) {
// TODO Provide user interface
System.out.println(HELLO);
int sum = 0;
sum = calculateSum(sum);
System.out.println(sum);
}
private static int calculateSum(int sum) {
for (int i = 0; i <= 100; i++) {
sum += i;
}
return sum;
}
}
Close the editor for the
MyFirstClass
class. If you now double-click on the tasks, the Java editor opens again and the TODO comment is selected.
You will create more and more projects in your development career. Therefore the data in your workspace grows and it is hard to find the right information.
You can use working sets to organize your displayed projects / data. To set up your working set select the → →

Press "New" on the following dialog to create a working set.

On the next dialog select "Resource", press Next and select the projects you would like to see and give it a name.


You can now easily display only the files you want to see.

You can use working sets to organize your displayed projects / data. To set up your working set select the → →

Press "New" on the following dialog to create a working set.

On the next dialog select "Resource", press Next and select the projects you would like to see and give it a name.


You can now easily display only the files you want to see.
