---
title: "Useful Eclipse Java Code Templates"  
description: "Useful Eclipse Java Code Templates"  
author: "Anonymous User"  
published: 2015-07-16  
updated: 2015-07-17  
canonical: https://www.mindstick.com/forum/23347/useful-eclipse-java-code-templates  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Useful Eclipse Java Code Templates

You can create various [Java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) [templates](https://www.mindstick.com/articles/12874/crucial-benefits-of-using-powerpoint-templates-in-your-business-presentations) in Eclipse via the\
*[Window](https://www.mindstick.com/forum/161285/how-does-the-window-console-object-work-in-javascript)->Preferences->Java -> [Editor](https://www.mindstick.com/forum/78/how-avoid-the-html-tag-and-remove-the-formating-of-copy-in-ajax-editor) -> Templates*e.g.\
sysout is expanded to:\

```
System.out.println(${word_selection}${});${cursor}
```

You can activate this by typing **sysout** followed by **CTRL+SPACE**\
What [useful](https://www.mindstick.com/articles/12694/how-dolomite-mineral-is-useful-in-human-life) Java code templates do you currently use?Include the [name](https://yourviews.mindstick.com/view/87450/how-to-generate-a-brand-name-using-linkedin-comprehensive-guide) and description of it and why it's awesome.

## Replies

### Reply by Anonymous User

Create **Log4J** logger:\

```
${:import(org.apache.log4j.Logger)}private static final Logger LOGGER = Logger.getLogger(${enclosing_type}.class);
```

It both creates the Logger with a proper category and imports it.\
For those using SLF4J:\
${:import(org.slf4j.Logger,org.slf4j.LoggerFactory)}private static final Logger LOGGER = LoggerFactory.getLogger(${enclosing_type}.class);\
\
**Read file:**

```
${:import(java.nio.file.Files,          java.nio.file.Paths,          java.nio.charset.Charset,          java.io.IOException,          java.io.BufferedReader)}try (BufferedReader in = Files.newBufferedReader(Paths.get(${fileName:var(String)}),                                                 Charset.forName("UTF-8"))) {    String line = null;    while ((line = in.readLine()) != null) {        ${cursor}    }} catch (IOException e) {    // ${todo}: handle exception}
```


---

Original Source: https://www.mindstick.com/forum/23347/useful-eclipse-java-code-templates

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
