One of the good features of Eclipse is its auto fill property. This can be further enhanced using its code template feature. Creation of code templates is necessary to improve development productivity. Templates add consistency and uniformity to your code. Eclipse has so many ready-to-use templates. And you can create your own code templates according to your requirements. To use these templates just type the starting characters of the template and then press “CTRL+SPACE”. For example in Eclipse IDE type “tr” and then press “CTRL+SPACE”, It will add “try-catch” block to the code.
This article will guide you to create your own code template. Let us take an example to generate a “if-else” template with one “else if” condition.
- Go to the Templates ( Window –> Preference –> Java –> Editor –> Templates) .
- Click “New”. A window similiar to below appears.
- Fill the details as shown above.
- Click “OK”.
- Now you can use your custom template in the program like any other template by pressing “CTRL+SPACE” as shown in the below given screenshots.