Interesting Short Codes and Shortcuts in NetBeans for Beginners

Before you get started with Java in NetBeans IDE you must know some interesting shortcuts for a speedy development, if you are a beginner you should remember these shortcuts on your fingertips. NetBeans is a user-friendly environment; it has a list of predefined shortcuts for instant statements. It also supports the users to create their own shortcuts for the editor.

As a beginner, you will be surprised to see these shortcuts as you can write commonly written statements on just a few keystrokes.

Here I have a list of commonly used shortcuts to save time while coding.

Printing a String (System.out.println(“”));

Instead of writing complete line of code i.e. System.out.println(“”); you can simply type sout(all small alphabets) and press Tab immediately after typing sout. NetBeans will automatically type System.out.println(“”); for you.

Printing a String along with a variable (System.out.println(“variable = ” + variable);)

Similarly, as you can write the print statement for a string with sout, you can display print statement for String along with a variable by using soutv(all small alphabets) and pressing Tab immediately after typing soutv, will type System.out.println(“variable = ” + variable);you can change the variable as required.

Printing error statements (System.err.println(“”);)

For printing error statement you can type serr and press Tab, it will auto generate System.err.println (“”);


for Loop

Instead of writing complete code for the for loop, along with variable condition and increment, you can type forand by pressing Tab immediately will type the complete structure of for loop.

dowhile loop

Type dowhile and press Tab immediately will type complete syntax of the dowhile loop. You just need to put on the condition.

switch statement

Type sw and press Tab immediately will generate full switch case statement set for you. With one case in it.

Custom Short Codes

NetBeans gives another option to facilitates its users. You can create your own shortcodes in NetBeans all you have to do is to

Open Options from Tools

Interesting Short Codes and Shortcuts in NetBeans for Beginners

In the Editor menu, click on Code Templates tab

Interesting Short Codes and Shortcuts in NetBeans for Beginners

A list of all the default code templates will be shown to you.

On the right side in code template, you will have a ‘New’ button to create a new code template.

It will ask for the abbreviation of the new code template on which you want to get desired code in the editor.

Interesting Short Codes and Shortcuts in NetBeans for Beginners

I wrote sal for string ArrayList.

Now in Expanded text tab below the code templates table, enter desired code for the new abbreviation.

Interesting Short Codes and Shortcuts in NetBeans for Beginners


As I want an ArrayList of type String on sal so I wrote

ArrayList<String> ${IDX newVarName} = new ArrayList();

$(IDX newVarName) writes down a new related variable name i.e. for ArrayList it will type arrayList as a variable name.

Now whenever I will type sal in the editor and press tab, it will write down complete code for String ArrayList

ArrayList<String>arrayList= new ArrayList<String>();

Search or Replace

Ctrl-F and Ctrl-H are used for finding and replacing contents in a file.

Ctrl-R is used to rename selection.

You can also convert selection to upper or lower cases by using Ctrl-U then U and Ctrl-U then L respectively.

Source Code Navigation 

You can also jump to specific line number by using Ctrl-G.

There is always a problem of finding matching brackets in the code this problem is now solved by Ctrl-[

Ctrl-Shift-C Or Ctrl-/ will add or remove line comments for you

Compile, run, test and Debugging

Use Alt-insert for code generates options

Alt-shift-I will now fix imports for you

Shift-F6 will Run main project or file

Ctrl-F5 will Start debugging your main file

Ctrl-shift-F8 will add new breakpoints for you

Toggling views

Ctrl-shift-F4 will close all windows

Ctrl-Alt-T will reopen recently closed files

Shift-Escape will maximize your window