Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Useful Eclipse Code Templates

DZone's Guide to

Useful Eclipse Code Templates

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

Eclipse's Java editor allows you to define code templates. You can use them to code complete things that you type all the time, such as get logger, logger.debug, etc.

Go to Windows->Preferences->Java->Editor->Templates , and put in the following templates

name:getlog

private static final Log logger =
LogFactory.getLog( ${enclosing_type}.class );


name:debug

if (logger.isDebugEnabled()) {
logger.debug(${Message}, ${exception});
}


name:error

logger.error(${Message}, ${exception});



name:info

logger.info(${Message}, ${exception});


name:warn

logger.warn(${Message}, ${exception});


name:const

private static final ${type} ${name} = new ${type} ${cursor};

After you have these templates setup, type the first few characters of the template name and hit ctrl-space, the editor will code complete the template. For example, type getlog, ctrl-space, and enter will declare a logger variable named logge.

By the way, Eclipse has quite a few built-in templates out of the box. I use some of them all the time, such as

'main' - creates a main method
'trycatch' - try catch
'Test' - creates a junit4 test method
'sysout' - System.out.println

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}