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

NetBeans in the Classroom: Code Templates

DZone's Guide to

NetBeans in the Classroom: Code Templates

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

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!

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.

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 }}