Netbeans – Tips & tricks

Here’s a few I know and find to be useful:

Removing a package:
After you remove a package in NetBeans, it sticks around as a grayed-out package in your Project view. To get rid of that, switch to Files view and delete the directory.

Alt-Insert (in Windows) opens up a Generate submenu at your cursor. A nice shortcut for quickly generating getters/setters (among other things).

Selecting a chunk of code, right-clicking and then clicking “Refactor > Introduce Method” will have NetBeans introduce a method, complete with arguments and return value. Of course you have to make sure the chunk of code only has one return value.

Sometimes when you run a build and it crashes, the Java window sticks around at the bottom. I used to just click X until Windows let me End Task, but there’s a nicer way to get rid of them. Click “Run > Stop Build/Run” and NetBeans will close the window for you. It’ll even let you close multiple applications at once.

These may seem obvious to grizzled NetBeans developers, but I thought they might be useful for NetBeans newbs like me. Anyone else have any tips/tricks to share?

Here are some from the comments:

NetBeans allows for code templates. You can even add yours on the Code Templates tab under the Editor settings on the Options window. Some examples:

Type sout and hit the tab key as a shorcut for System.out.println(“”)

Type psvm and hit the tab key as a shorcut for public static void main(String args[]) {}

Ctrl Shift C: Comments out the selected block of code.

Alt Shift F: Formats the selected block of code.

Ctrl E: Deletes current line.

Ctrl Shift I: Fixes your imports, handy if you’ve just written a piece of code that needs a lot of packages imported.

Server side debug (handy especially for Web Services) by attaching a debugger to the project.

Macro recording for repetitive tasks(Really useful for advanced replace kind of tasks)

Adding TODO tasks

Alt + Shift + F for auto format

Ctrl + K for previously used matching word

Ctrl + arrowkeys for scroll without caret position change

Ctrl + P for function parameters tooltip. Applicable inside a function call’s paranthesis

Ctrl + Shift + Right/Left Arrow to select words based on camel casing

Ctrl + Shift + (UP/DOWN ) duplicate line up/down

Ctrl + E deletes the current line (very useful)

Ctrl + F9 Evaluate expression (Very useful while debugging – apart from the value of variables displayed on hover)

Alt + Shift + O Goto file

Ctrl + Space (after a class name) for auto-suggested variable names

Ctrl + F4 Close Editor Window

Alt + F7 Find Usages

Ctrl + / Toggle Comment

Shift + Ctrl + I Fix all Imports (Very convenient)

Ctrl + Del and Ctrl + BackSpace Delete next/previous word

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*