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

My Weekly NetBeans Tip (5): Fiddling with Predefined Code Template Variables

DZone's Guide to

My Weekly NetBeans Tip (5): Fiddling with Predefined Code Template Variables

· Java Zone ·
Free Resource

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

When you create a new class in NetBeans IDE, you automatically get some variables filled in, such as the user name and package name. That's possible because if you go to Tools | Templates, the Java Class template is like this:

<#assign licenseFirst = "/*">
<#assign licensePrefix = " * ">
<#assign licenseLast = " */">
<#include "../Licenses/license-${project.license}.txt">

<#if package?? && package != "">
package ${package};

</#if>
/**
 *
 * @author ${user}
 */
public class ${name} {

}

Here you see predefined template variables such as ${package} and ${user}. In this User FAQ, you can find all the other predefined variables for templates. And more info (including about "project.license") can be found here and here.

But this week I found something new: you can change the display of the date and of the time. So if you use this:

${time?time?string("h/m/s a z")} 

You will get this:

4/53/54 PM CET

Instead of the default provided by ${time}, which is this:

4:53:54 PM  

So, both the predefined variable for time and date can be tweaked quite easily, if you're willing to experiment a bit. 

How do you break a Monolith into Microservices at Scale? This ebook shows strategies and techniques for building scalable and resilient microservices.

Topics:

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}