Over a million developers have joined DZone.

NetBeans in the Classroom: Code Templates

· Java Zone

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.

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!

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 best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

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

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

{{ parent.tldr }}

{{ parent.urlSource.name }}