Easy Tutorial
❮ Eclipse Tutorial Eclipse Create Jar Files ❯

Eclipse Code Templates

Using Code Templates

Eclipse offers the capability to enhance productivity and code predictability by defining and utilizing code templates.

When developing Java programs, we often need to write the main method:

public static void main(String[] args) {

}

Typing it letter by letter would be repetitive and meaningless. Instead, we can use Eclipse code templates to quickly accomplish this task.

Simply type main within the class body and use Eclipse's code assist shortcut (default is Alt+/). Press Enter, and Eclipse will automatically complete the full definition of the main function:

If we want to use System.out.println(), we just need to type syso and then press Alt+/:


Customizing Code Templates

Eclipse provides many code templates. You can view all predefined templates by navigating to Windows->Preferences->Java->Editor->Templates (you can search for "Templates" in the search box).

Select the sysout template in the popup window and click Edit on the right, which displays:

The edit panel is the focal point as all configurations are done here. Let's familiarize ourselves with the five key elements in this panel:

For more details on customizing code templates, you can click on the Help menu, select Help Contents, and in the dialog box, search for "Java Editor Template Variables" and choose Java Editor Template Variables to view the specific documentation.

❮ Eclipse Tutorial Eclipse Create Jar Files ❯