DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Tools
  4. NetBeans in the Classroom: The Beginners Template (Part 2)

NetBeans in the Classroom: The Beginners Template (Part 2)

Ken Fogel user avatar by
Ken Fogel
·
May. 19, 14 · Interview
Like (0)
Save
Tweet
Share
6.40K Views

Join the DZone community and get the full member experience.

Join For Free
ken fogel is the program coordinator and chairperson of the computer science technology program at dawson college in montreal, canada. he is also a program consultant to and part-time instructor in the computer institute of concordia university 's school of extended learning. he blogs at omniprogrammer.com and tweets @omniprof .

in my previous article i showed how i like a new project to present its generated class that contains the main method. netbeans can be configured to do this for you by editing the code template for new java application projects.

begin by going to the tools menu and select templates . a dialog will appear with a tree of choices. locate java and click on the plus symbol to open the tree to reveal the list of code templates available.

we are interested in java main class . select it and the buttons duplicate and open in editor become active. first click on duplicate to preserve the original template. the new template will be named java main class 1 .

select java main class again and click on open in editor . this template will appear in the netbeans editor.

the first change is to delete lines 1 through 5. these are the lines that produce the following in the class:

* to change this license header, choose license headers in project properties.
* to change this template file, choose tools | templates
* and open the template in the editor.
*/

in a commercial or open source environment all files must be branded. for students starting out these lines just clutter the files. that is why i recommend deleting them.

now it’s time to change the template to match my recommendation. here is what it should look like:

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

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

    /**
     *  default constructor
     */
    public ${name}() {
        super();
    }

    /**
     * call upon the application logic
     */
    public void perform() {
        // todo code application logic here
    }

    /**
     * @param args the command line arguments
     */
    public static void main(string[] args) {
        ${name} obj = new ${name}();
        obj.perform();
        system.exit(0);
    }

}

save your changes and test that it has worked by creating a new java application .

in the template there are three expressions. the first is ${name} and that comes from the project name field. the second is ${package} and that comes from the filed next to the create main class checkbox and includes anything up until the final period. the third is ${user} and that is the name you used to log into your system. i will write about what should go here is another article.

if all has gone well you should have a file that contains the following code:

package changingtemplate;

/**
 *
 * @author ken
 */
public class changingtemplate {

    /**
     *  default constructor
     */
    public changingtemplate() {
        super();
    }

    /**
     * call upon the application logic
     */
    public void perform() {
        // todo code application logic here
    }

    /**
     * @param args the command line arguments
     */
    public static void main(string[] args) {
        changingtemplate obj = new changingtemplate();
        obj.perform();
        system.exit(0);
    }

}

this is what i want my students to see when they start a project. you can use this same technique to alter any of netbeans’ various other file templates.

Template NetBeans Classroom (Apple)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Easy Smart Contract Debugging With Truffle’s Console.log
  • Deploying Java Serverless Functions as AWS Lambda
  • Using AI and Machine Learning To Create Software
  • PHP vs React

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: