Want to Code Faster in NetBeans? Use These 3 Hacks

December 15, 2016

For those of you not familiar with NetBeans, it is a popular Integrated Development Environment (IDE) used by programmers to write code in Java (as well as a few other languages, such as Scala).

If you use it often, like many coders do, it quickly becomes about efficiency. How do I code faster in NetBeans? What hacks out there can I use to get more done?

This article is intended to help you out. Here are a few techniques I’ve found that will allow you to code more efficiently in NetBeans.

Use code templates

When programming, you often find yourself typing certain commands many times in a single program.  One typical example in almost all programming languages is a command to print a message to the console, such as the infamous task of printing the message “Hello World!”

To print this statement in Java using NetBeans, this statement would look like this:

System.out.println("Hello World!");

Java is case sensitive, so it must be exactly as seen here in this example.

The print line (println) statement is often used, especially when you are debugging your program in order to print your results or to provide the user with a prompt to enter information. 

As a programming teacher, students often need to type the statement System.out.println(""); So, when I introduce this shortcut to the class, they are usually pretty happy. 

I instruct them to type "sout" and then hit the tab key.  The word expands to: System.out.println("");

This can save a lot of time and typing!

And the really good news is that there are many more code templates that exist and can be found by going to NetBeans -> Preferences -> Editor -> Code Templates. 

Another great example is used to create a loop. Try typing "for" then "tab" and it automatically expands to:

for (int i = 0; i < 10; i++) {

}

The really good news is that you can add your own code templates based on your needs. Maybe you use the following code snippet frequently:

try{…}

catch()

{..}

finally {…}

Add a new code template by clicking new, give your template a name and then add your code to the expanded text section. Here is an example:

Use this technique to format your code faster

Have you ever finished up a program and realized that the code formatting is all over the place, and you want an easy way to fix it? Hit CTL-SHIFT-F and all the code is automatically formatted! 

Before:                                                   After:

How to quickly change the color of your IDE

Okay, this one isn’t so much about speed and more about personal preference. But, if you aren’t happy with the color scheme of your NetBeans IDE, you can easily change it.

To do that, go to NetBeans -> Preferences -> Fonts & Colors. From here, you can change the color scheme by choosing an option from the Profile menu.

I have recently changed it to "City Lights" (see how it looks below). Also note that changes can be made to individual categories too, so feel free to play around with it.

Peggy Fisher is a staff author for LinkedIn Learning in the developer segment, covering topics like fundamentals for C++, Java and Arduino. See all of Fisher's classes here

Topics