Platinum Partner
netbeans

NetBeans in the Classroom: Code Templates

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.

I have had to reveal an ugly truth about being a programmer to my students. The truth is that all the errors that occur in their code are their own fault. It’s not Java’s fault, not Oracle’s fault, and not even Microsoft’s fault. It’s their fault. Or to put it another way, they are responsible for the bugs in their code.

Ants at the Montreal Insectarium, photographed by Ken Fogel

Rather than teach them about the debugger and breakpoints, I present a simple technique for debugging: use System.out.println().

For someone just starting out, there is no better way to learn about what is going on inside your machine. In my second Java course, I introduce the Logger but, for finding problems in their first assignment in their first programming course, nothing beats System.out.println().

Code Templates in NetBeans

One of the best features of NetBeans is the Code Templates. A template allows you to enter an abbreviated form of a statement or expression, followed by the Tab key, and then NetBeans writes it out for you.

You can find the list of supplied templates by going to Tools->Options->Editor->Code Templates. You can edit any of the templates or create new ones. For the beginning programmer, the favourite template is "sout".



Place your cursor at the point in the code where you want to display the value of a variable, type the letters s o u t and then press Tab. System.out.println(“”); appears on the line and all you need to do is fill in what you want to examine.

A last point that I make to my students is to comment out the statement when they are done with it rather than delete it. I explain that there is a fundamental law of programming that states that five minutes after you delete a line of code you wish you hadn’t!

{{ tag }}, {{tag}},

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

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}