Jon Jon - 1 year ago 195
Java Question

Useful Eclipse Java Code Templates

You can create various Java code templates in Eclipse via the

Window->Preferences->Java -> Editor -> Templates


is expanded to:


You can activate this by typing
followed by

What useful Java code templates do you currently use?

Include the name and description of it and why it's awesome.

There's an open bounty on this for an original/novel use of a template rather than a built-in existing feature.

  • Create Log4J logger

  • Get swt color from display

  • Syncexec - Eclipse Framework

  • Singleton Pattern/Enum Singleton Generation

  • Readfile

  • Const

  • Traceout

  • Format String

  • Comment Code Review

  • String format

  • Try Finally Lock

  • Message Format i18n and log

  • Equalsbuilder

  • Hashcodebuilder

  • Spring Object Injection

  • Create FileOutputStream

Answer Source

The following code templates will both create a logger and create the right imports, if needed.


private static final Logger LOGGER = LoggerFactory.getLogger(${enclosing_type}.class);

Log4J 2

private static final Logger LOG = LogManager.getLogger(${enclosing_type}.class); 


private static final Logger LOGGER = Logger.getLogger(${enclosing_type}.class);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download