Finding, Searching, and Replacing
Ctrl-F3 |
Search word at insert point |
F3/Shift-F3 |
Find next/previous in file |
Ctrl-F/H |
Find/Replace in file |
Alt-F7 |
Find usages |
Ctrl-Shift-P |
Find/replace in projects |
Alt-Shift-U |
Find usages results |
Alt-Shift-H |
Turn off search result highlights |
Ctrl-R |
Rename |
Ctrl-U, then U |
Convert selection to uppercase |
Ctrl-U, then L |
Convert selection to lowercase |
Ctrl-U, then S |
Toggle case of selection |
Alt-Shift-V |
Paste formatted |
Opening and Toggling Between Views
Ctrl-Tab (Ctrl-`) |
Toggle between open documents |
Shift-Escape |
Maximize window (toggle) |
Ctrl-F4/Ctrl-W |
Close currently selected window |
Ctrl-Shift-F4 |
Close all windows |
Shift-F10 |
Open contextual menu |
Alt-Shift-D |
Undock window |
Navigating through Source Code
Ctrl-O/Alt-Shift-O |
Go to type/file |
Ctrl-Shift-T |
Go to JUnit test |
Alt-O |
Go to source |
Ctrl-B |
Go to declaration |
Ctrl-G |
Go to line |
Ctrl-Shift-M |
Toggle add/remove bookmark |
Ctrl-Shift-Period/Comma |
Next/previous bookmark |
Ctrl-Period/Comma |
Next/previous usage/compile error |
Ctrl-Shift-1/2/3 |
Select in Projects/Files/Favorites |
Ctrl-[ |
Move caret to matching bracket |
Ctrl-K/Ctrl-Shift K |
Next/previous word match |
Alt-Left/Alt-Right/Ctrl-Q |
Go backward/forward/to last edit |
Compiling, Testing, and Running
F9 |
Compile package/ file |
F11 |
Build main project |
Shift-F11 |
Clean & build main project |
Ctrl-Q |
Set request parameters |
Ctrl-Shift-U |
Create JUnit test |
Ctrl-F6/Alt-F6 |
Run JUnit test on file/project |
F6/Shift-F6 |
Run main project/file |
Debugging
Ctrl-F5 |
Start debugging main project |
Ctrl-Shift-F5 |
Start debugging current file |
Ctrl-Shift-F6 |
Start debugging test for file (JUnit) |
Shift-F5/F5 |
Stop/Continue debugging session |
F4 |
Run to cursor location in file |
F7/F8 |
Step into/over |
Ctrl-F7 |
Step out |
Ctrl-Alt-Up |
Go to called method |
Ctrl-Alt-Down |
Go to calling method |
Ctrl-F9 |
Evaluate expression |
Ctrl-F8 |
Toggle breakpoint |
Ctrl-Shift-F8 |
New breakpoint |
Ctrl-Shift-F7 |
New watch |
Coding in Java
Alt-Insert |
Generate code |
Ctrl-Shift-I |
Fix all class imports |
Alt-Shift-I |
Fix selected class's import |
Alt-Shift-F |
Format selection |
Alt-Shift Left/Right/Up/Down |
Shift lines left/right/up/down |
Ctrl-Shift-Up/D |
Copy lines up/down |
Ctrl/Alt-F12 |
Inspect members/hierarchy |
Ctrl-/ |
Add/remove comment lines |
Ctrl-E |
Delete current line |
Refactoring
This table provides short descriptions of the refactoring operations that are available in the IDE, mostly from under the Refactoring menu and within the Java editor itself, when you right-click within it.
Refactoring Operation |
Description |
Rename |
Enables you to change the name of a class, variable, or method to something more meaningful. In addition, it updates all source code in your project to reference the element by its new name. |
Introduce Variable, Constant, Field, or Method |
Enables you to generate a statement based on the selected code and replace that block of code with a call to the statement. |
Change Method Parameters |
Enables you to add parameters to a method and change the access modifier. |
Encapsulate Fields |
Generates a getter method and and a setter method for a field and optionally updates all referencing code to access the field using the getter and setter methods. |
Pull Up |
Moves methods and fields to a class that their current class inherits from. |
Push Down |
Moves inner classes, methods, and fields to all subclasses of their current class. |
Move Class |
Moves a class to another package or into another class. In addition, all source code in your project is updated to reference the class in its new location. |
Copy Class |
Copies a class to the same or a different package. |
Move Inner to Outer Level |
Moves an inner class one level up in hierarchy. |
Convert Anonymous Class to Inner |
Converts an anonymous class to an inner class that contains a name and constructor. The anonymous inner class is replaced with a call to the new inner class. |
Extract Interface |
Creates a new interface from the selected public non-static methods in a class or interface. |
Extract Superclass |
Creates a new abstract class, changes the current class to extend the new class, and moves the selected methods and fields to the new class. |
Use Supertype Where Possible |
Changes code that references the selected class (or other type) to instead use a supertype of that type. |
Safely Delete |
Checks for references to a code element and then automatically deletes that element if no other code references it. |
When typing in the Source Editor, you can generate the text in the right-column of the following list by typing the abbreviation that is listed in the left-column and then pressing Tab.
Java Editor Code Templates
En |
Enumeration |
Ex |
Exception |
Ob |
Object |
Psf |
public static final |
Psfb |
public static final boolean |
Psfi |
public static final int |
Psfs |
public static final String |
St |
String |
ab |
abstract |
bo |
boolean |
br |
break |
ca |
catch ( |
cl |
class |
cn |
continue |
df |
default: |
dowhile |
do { } while (condition); |
eq |
equals |
ex |
extends |
fa |
false |
fi |
final |
fl |
float |
forc |
for (Iterator it = collection.iterator(); it.hasNext( );) { Object elem = (Object) it.next( ); } |
fore |
for (Object elem : iterable) { } |
fori |
for (int i = 0; i < arr.length; i++) { } |
fy |
finally |
ie |
interface |
ifelse |
if (condition){ }else { } |
im |
implements |
iof |
instanceof |
ir |
import |
le |
length |
newo |
Object name = new Object(args); |
pe |
protected |
pr |
private |
psf |
private static final |
psfb |
private static final boolean |
psfi |
private static final int |
psfs |
private static final String |
pst |
printStackTrace(); |
psvm |
public static void main(String[ ] args){ } |
pu |
public |
re |
return |
serr |
System.err.println ("|"); |
sout |
System.out.println ("|"); |
st |
static |
sw |
switch ( |
sy |
synchronized |
tds |
Thread.dumpStack(); |
th |
throws |
trycatch |
try {} catch (Exception e) {} |
tw |
throw |
twn |
throw new |
wh |
while ( |
whileit |
while (it.hasNext()) { Object elem = (Object) it.next(); } |
Mac OS Keyboard Shortcuts
In most cases, working with the IDE on the Mac is no different from working on other operating systems. Two significant differences do exist, however. Firstly, the Options window on the Mac is found under NetBeans > Preferences. Secondly, the About box is under NetBeans > About.
Scrolling and Selecting
Keys |
Action |
Cmd-[ |
Moves the insertion point to the highlighted matching bracket. Note that this shortcut only works when the insertion point is located immediately after the opening bracket. |
Cmd-Shift-[ |
Selects the block between a pair of brackets. Note that this shortcut only works when the insertion point is located immediately after either the opening or closing bracket. |
Ctrl-G |
Jumps to any specified line. |
Cmd-A |
Selects all text in the file. |
Code Folding
Keys |
Action |
Cmd-Minus (-) |
Collapses the block of code in which the insertion point is currently located. |
Cmd-Plus (+) |
Expands the block of code which is adjacent to the insertion point. |
Cmd-Shift-Minus (-) |
Collapses all blocks of code in the current file. |
Cmd-Shift-Plus (+) |
Expands all blocks of code in the current file. |
Cutting, Copying, Pasting, and Deleting Text
Keys |
Action |
Cmd-Z |
Undo. Reverses a series of editor actions one at a time (excluding Save). |
Cmd-Y |
Redo. Reverses a series of Undo commands one at a time. |
Cmd-X |
Cut. Deletes the current selection and places it on the clipboard. |
Cmd-C |
Copy. Copies the current selection to the clipboard. |
Cmd-V |
Paste. Pastes the contents of the clipbard at the insert point. |
Backspace Delete |
Deletes the current selection. |
Cmd-E |
Deletes the current line. |
Cmd-K |
Copies the word preceding the insertion point and then pastes it after the insertion point (the insertion point must be in the whitespace preceeding or following a word). Press K multiple times to cycle through preceding words in succession. |
Cmd-Shift-K |
Copies the word following the insertion point and pastes it at the insertion point (the insertion point must be located in the whitespace preceeding or following a word.) Press L multiple times to cycle through consecutive following words. |
To Change Default Settings:
- Choose Tools > Options from the main menu.
- For code templates, select Editor and click the Code Templates tab. Here you can also change the expansion key, from Tab to something else.
- For keyboard shortcuts, select Keymap and choose a profile from the Profile drop-down list.
{{ parent.title || parent.header.title}}
{{ parent.tldr }}
{{ parent.linkDescription }}
{{ parent.urlSource.name }}