NetBeans is an optimal Java development environment. Just recently, while visiting the JAX Conference in Mainz/Germany, I attended a live coding session by Adam Bien. I was telling later a fellow developer and Eclipse user how convenient NetBeans is and how Adam, even though he broke his arm in a bicycle accident, used NetBeans during his live coding session. Later I met my colleague again during lunch time: he just had installed NetBeans on his notebook and was already fond of the NetBeans usage experience.
And yes, numerous keyboard shortcuts and code templates make editing and writing java classes with NetBeans a breeze. Here are my favourites to give you a quick start within the NetBeans Code Editor (in brackets the Eclipse pendants) :
- Alt+ENTER (Ctrl+1)
Fixes Code – whenever there is a yellow light bulb on the left hand side of the editor, try Alt+ENTER: a list of suggestions how NetBeans can fix the code for you pops up. It also may add missing JavaDoc and assigns a variable to the returned value of a method call.
The code generation menu opens up and let’s you insert getters and setter, equals and hashCode, toString and many more.
- Shift+ENTER (same)
Insert a new line and move the cursor to the new lines beginning. Shift+ENTER may be pressed at any position on the current line without splitting it.
- Ctrl+e (Ctrl+d)
Removes the current line.
- Shift+Alt+period/comma (Alt + Shift + Arrow Left/Right)
Selects next/previous element (such as name, expression, line, method body, method etc).
- Ctrl-r (Alt+Shift+r)
- Ctrl-o (Ctrl+Shift+t)
- Shift+Alt+o (Ctrl+Shift+r)
- Shift+Ctrl+Arrow Up/Down (Ctrl+Alt+Arrow Up/Down)
Copy line up/down
- Shift+Alt+Arrow Up/Down (Alt+Arrow Up/Down)
Move line up/down
- Ctrl+Arrow Up/Down (same)
Scroll without loosing cursor position
- Shift+Ctrl+c (same)
- Shift+Alt+f (Shift+Ctrl+f)
- Shift+Ctrl+i (Shift+Ctrl+o)
Insert clipboard content formatted
- Ctrl+F12 (Ctrl+o)
Select Navigator Window. Inside start typing method names and the matching method will be selected. Press ENTER to navigate to it in your source file. Very handy!
- F7/F8 (F5/F6)
Debugger: Step into/Step over
- Ctrl+Shift+ENTER (Ctrl+m)
Show only Editor (hit key combination a second time to return to normal)
- Ctrl+s (same)
- Ctrl+g (Ctrl+l)
Code Templates may be entered at any line in the current file. After hiting the TAB-Key, the template is expanded.
Expands to “public”
Expands to “private”
Expands to “return”
Creates a for-each loop wih smart detection of collection classes to use.
Creates a skeleton public method declaration.
Creates a skeleton private method declaration.
Expands to “System.out.println(“|”)”
If you never tried the code templates before, you should at least try the method declaration templates (pm and Pm). They are clever implemented and really convenient to use.