This document provides a summary of keyboard shortcuts and features in the NetBeans IDE 6.1 Java editor. It includes shortcuts for navigating, searching, formatting, and refactoring code as well as for debugging. The document also lists code templates that can be generated by typing abbreviations. Overall, the document is a reference for Java developers to maximize their productivity in the NetBeans editor.
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
NetBeans IDE 6.1 Java Editor Guide
1. Subscribe Now for FREE! refcardz.com
tech facts at your fingertips
CONTENTS INCLUDE:
n
About NetBeans IDE
Getting NetBeans IDE
NetBeans IDE 6.1 Java Editor
n
n
Development with NetBeans IDE
n
Keyboard Shortcuts and
Code Templates
n
Quick Options Windows Overview By Geertjan Wielenga and Patrick Keegan
n
Hot Tips and more...
ABOUT NETBEANS IDE
The NetBeans IDE has seen adoption snowballing over the past authors intended when creating it. It lists all the keyboard shortcuts
years. The icing on the cake has been the introduction of a com- in carefully thought out categories and it provides a thorough
pletely new, rewritten, slick Java editor. You’ll find this reference exposition of optimal handling of Java code in the editor,
card helpful if you want to get as much out of the Java editor as its covering viewing, navigation, source handling, and refactoring.
GETTING NETBEANS IDE
Go to http://download.netbeans.org/netbeans/6.1/final/
NetBeans Packs* Web & Java EE Mobility Java SE Ruby C/C++ Early Access for PHP All
Base IDE • • • • • • •
www.dzone.com
Java SE • • • •
Web & Java EE • — •
Mobility —
UML —
SOA •
Ruby • •
C/C++ • •
Early Access for PHP •
Bundled Servers
GlassFish V2 UR2 • •
Apache Tomcat 6.0.16 • •
NetBeans IDE 6.1 Java Editor
NETBEANS IDE JAvA
QUICk STArT TUTOrIAL Get More Refcardz
(They’re free!)
This tutorial provides a very simple and quick introduction to n Authoritative content
the NetBeans IDE workflow by walking you through the creation
n Designed for developers
of a simple “Hello World” Java console application. Once you
n Written by top experts
are done with this tutorial, you will have a general knowledge of
how to create, build, and run applications in the IDE.
n Latest tools & technologies
n Hot tips & examples
To follow this tutorial, you need the following software and
n Bonus content online
resources:
n New issue every 1-2 weeks
Software or Resource Version Required
NetBeans IDE Version 6.1 or version 6.0
Subscribe Now for FREE!
Refcardz.com
Java Developer Kit (JDK) Version 6 or version 5
DZone, Inc. | www.dzone.com
2. 2
NetBeans IDE 6.1 Java Editor
tech facts at your fingertips
NetBeans IDE Java Quick Start Tutorial, continued Navigating through Source Code
Ctrl-O/Alt-Shift-O Go to type/file
1. Start NetBeans IDE. In the IDE, choose File > New Project
(Ctrl-Shift-N). Ctrl-Shift-T Go to JUnit test
Alt-O Go to source
2. In the New Project wizard, expand the Java category and
select Java Application. Then click Next. Ctrl-B Go to declaration
Ctrl-G Go to line
3. In the Name and Location page of the wizard, type
quot;HelloWorldAppquot; in Project Name and type Ctrl-Shift-M Toggle add/remove bookmark
quot;helloworldapp.HelloWorldAppquot; in the Create Main Class Ctrl-Shift-Period/Comma Next/previous bookmark
field. Then Click finish. Ctrl-Period/Comma Next/previous usage/compile error
4. Because you have left the Create Main Class checkbox Ctrl-Shift-1/2/3 Select in Projects/Files/Favorites
selected in the New Project wizard, the IDE has created a Ctrl-[ Move caret to matching bracket
skeleton class for you. You can add the quot;HelloWorld!quot;
Ctrl-K/Ctrl-Shift K Next/previous word match
message to the skeleton code by replacing the line:
Alt-Left/Alt-Right/Ctrl-Q Go backward/forward/to last edit
// TODO code application logic here
with the line: Compiling, Testing, and Running
System.out.println(quot;Hello World!quot;); F9 Compile package/ file
5. From the IDE’s menu bar, choose Run > Run Main F11 Build main project
Project (F6). The Output window should show you the Shift-F11 Clean & build main project
quot;HelloWorld!quot; message. Ctrl-Q Set request parameters
Congratulations! Your program works! You now know how to Ctrl-Shift-U Create JUnit test
accomplish some of the most common programming tasks in Ctrl-F6/Alt-F6 Run JUnit test on file/project
the IDE.
F6/Shift-F6 Run main project/file
kEYBOArD SHOrTCUTS & CODE TEMPLATES Debugging
Ctrl-F5 Start debugging main project
Finding, Searching, and Replacing
Ctrl-Shift-F5 Start debugging current file
Ctrl-F3 Search word at insert point Ctrl-Shift-F6 Start debugging test for file (JUnit)
F3/Shift-F3 Find next/previous in file Shift-F5/F5 Stop/Continue debugging session
Ctrl-F/H Find/Replace in file F4 Run to cursor location in file
Alt-F7 Find usages F7/F8 Step into/over
Ctrl-F7 Step out
Ctrl-Shift-P Find/replace in projects
Ctrl-Alt-Up Go to called method
Alt-Shift-U Find usages results
Ctrl-Alt-Down Go to calling method
Alt-Shift-H Turn off search result highlights
Ctrl-F9 Evaluate expression
Ctrl-R Rename
Ctrl-F8 Toggle breakpoint
Ctrl-U, then U Convert selection to uppercase
Ctrl-Shift-F8 New breakpoint
Ctrl-U, then L Convert selection to lowercase
Ctrl-Shift-F7 New watch
Ctrl-U, then S Toggle case of selection
Alt-Shift-V Paste formatted
Coding in Java
Alt-Insert Generate code
Opening and Toggling Between Views Ctrl-Shift-I Fix all class imports
Alt-Shift-I Fix selected class’s import
Ctrl-Tab (Ctrl-`) Toggle between open documents
Alt-Shift-F Format selection
Shift-Escape Maximize window (toggle)
Alt-Shift Left/Right/Up/Down Shift lines left/right/up/down
Ctrl-F4/Ctrl-W Close currently selected window
Ctrl-Shift-Up/D Copy lines up/down
Ctrl-Shift-F4 Close all windows
Ctrl/Alt-F12 Inspect members/hierarchy
Shift-F10 Open contextual menu Ctrl-/ Add/remove comment lines
Alt-Shift-D Undock window Ctrl-E Delete current line
DZone, Inc. | www.dzone.com
3. 3
NetBeans IDE 6.1 Java Editor
tech facts at your fingertips
Keyboard Shortcuts & Code Templates, continued Java Editor Code Templates, continued
St String
Refactoring
ab abstract
This table provides short descriptions of the refactoring
bo boolean
operations that are available in the IDE, mostly from under
br break
the Refactoring menu and within the Java editor itself,
ca catch (
when you right-click within it.
cl class
Refactoring Operation Description cn continue
Rename Enables you to change the name of a class, df default:
variable, or method to something more dowhile do {
meaningful. In addition, it updates all source
} while (condition);
code in your project to reference the element
by its new name. eq equals
Introduce Variable, Enables you to generate a statement based ex extends
Constant, Field, or on the selected code and replace that block fa false
Method of code with a call to the statement.
fi final
Change Method Enables you to add parameters to a method
Parameters and change the access modifier. fl float
forc for (Iterator it = collection.iterator();
Encapsulate Fields Generates a getter method and and a setter
it.hasNext( );) {
method for a field and optionally updates all
referencing code to access the field using the Object elem = (Object) it.next( );
getter and setter methods. }
fore for (Object elem : iterable) {
Pull Up Moves methods and fields to a class that their
}
current class inherits from.
fori for (int i = 0; i < arr.length; i++) {
Push Down Moves inner classes, methods, and fields to all
}
subclasses of their current class.
fy finally
Move Class Moves a class to another package or into
another class. In addition, all source code in ie interface
your project is updated to reference the class ifelse if (condition){ }else {
in its new location. }
Copy Class Copies a class to the same or a different im implements
package.
iof instanceof
Move Inner to Outer Level Moves an inner class one level up in hierarchy.
ir import
Convert Anonymous Converts an anonymous class to an inner class le length
Class to Inner that contains a name and constructor. The
anonymous inner class is replaced with a call newo Object name = new Object(args);
to the new inner class. pe protected
Extract Interface Creates a new interface from the selected pr private
public non-static methods in a class or
interface. psf private static final
psfb private static final boolean
Extract Superclass Creates a new abstract class, changes the
current class to extend the new class, and psfi private static final int
moves the selected methods and fields to the
new class. psfs private static final String
pst printStackTrace();
Use Supertype Where Changes code that references the selected
Possible class (or other type) to instead use a psvm public static void main(String[ ] args){
supertype of that type. }
Safely Delete Checks for references to a code element and pu public
then automatically deletes that element if no re return
other code references it.
serr System.err.println (quot;|quot;);
When typing in the Source Editor, you can generate the sout System.out.println (quot;|quot;);
text in the right-column of the following list by typing st static
the abbreviation that is listed in the left-column and then sw switch (
pressing Tab. sy synchronized
tds Thread.dumpStack();
Java Editor Code Templates th throws
En Enumeration trycatch try {}
catch (Exception e) {}
Ex Exception
tw throw
Ob Object
twn throw new
Psf public static final
wh while (
Psfb public static final boolean
whileit while (it.hasNext()) {
Psfi public static final int
Object elem = (Object) it.next();
Psfs public static final String }
DZone, Inc. | www.dzone.com
4. 4
NetBeans
Published on NetBeans Zone (http://netbeans.dzone.com) IDE 6.1 Java Editor
tech facts at your fingertips
10 Handy Editor Shortcuts in NetBeans IDE
6.0
Mac OS Keyboard Shortcuts 10 Handy Editor Shortcuts, continued
By geertjan
10 Handy Editor Shortcuts in NetBeans IDE 6.0 http://netbeans.dzone.com/prin
In most cases, working with the IDE on the Mac is no different Created 2008/01/16 - 10:13pm
1. Move/copy up/down. Press Ctrl-Shift-Up and the current
from working on other operating systems. Two significant
selectiontois copiedoncethe knowNetBeans aboveall of these are new that no some were
The following are some of the many cool
will be able do without, to you lines right
IDE 6.0 keyboard shortcuts
they're there. Not the current in 6.0,
programmer
differences do exist, however. Firstly, the Options window on there before, but deserveZone (http://netbeans.dzone.com) is moved instead
Published on NetBeans to be highlighted because often they're overlooked.
selection. Press Alt instead of Ctrl and it
the Mac is found under NetBeans > Preferences. Secondly,
ofMove/copy up/down. Press Ctrl-Shift-Upof Up and the lines of code lines right
1. copied. Press Down instead and the current selection is copied to the
the About box is under NetBeans > About. above the current selection. Press Alt Shortcuts is moved instead of copied. IDE
10 Handy Editor instead of Ctrl and it in NetBeans Press Down
will be copied below code will be copied below the current selection, as below:
instead of Up and the lines of the current selection, as below:
Scrolling and Selecting
6.0
By geertjan
Keys Action Created 2008/01/16 - 10:13pm
Cmd-[ Moves the insertion point to the highlighted matching bracket.
The following are some of the many cool NetBeans IDE 6.0 keyboard shortcuts that no programmer
Note that this shortcut only works when the insertion point is will be able to do without, once you know they're there. Not all of these are new in 6.0, some were
located immediately after the opening bracket. there before, but deserve to be highlighted because often they're overlooked.
Cmd-Shift-[ Selects the block between a pair of brackets. Note that this shortcut 1. Move/copy up/down. Press Ctrl-Shift-Up and the current selection is copied to the lines right
only works when the insertion point is located immediately after above the current selection. Press Alt instead of Ctrl and it is moved instead of copied. Press Down
either the opening or closing bracket. instead of Up and the lines of code will be copied below the current selection, as below:
2. Capture inner/outer syntactic element. Each time you press Alt-Shift-Period, the selection
Ctrl-G Jumps to any specified line. 2. Capture successively widersyntactic element. Each time you
expands to a inner/outer syntactic element. For example, below one statement was selected,
the key combination Alt-Shift-Period was pressed, and then the complete content of the surrounding
Cmd-A Selects all text in the file. press Alt-Shift-Period, the selection expands to a the current statement to
block statement was shown to be selected. The selection expands from succes-
surrounding block statements to the surrounding method and, from there, to the surrounding class
sively wider syntactic element. Forpress Alt-Shift-Comma, instead of
and further. To successively narrow the selection, example, below one
Code Folding statement was selected, the key combination Alt-Shift-Period
Alt-Shift-Period.
Keys Action was pressed, and then the complete content of the
Cmd-Minus (-) Collapses the block of code in which the insertion point surrounding block statement was shown to be selected.
is currently located. The selection expands from the current statement to
2. Capture inner/outer syntactic element. Each time you press Alt-Shift-Period, the selection
Cmd-Plus (+) Expands the block of code which is adjacent to the surrounding blockwider syntactic element. Forsurrounding one statement was selected,
expands to a successively statements to the example, below method
insertion point. the key combination Alt-Shift-Period was pressed, and then the complete content of the surrounding
and,statement was shown to be selected. The selection expands from the current statement to
block from there, to the surrounding class and further.
Cmd-Shift-Minus (-) Collapses all blocks of code in the current file.
To successively narrowto the surrounding methodAlt-Shift-Comma,to the surrounding class
surrounding block statements the selection, pressand, from there,
and further. To successively narrow the selection, press
Alt-Shift-Comma, of
instead
Cmd-Shift-Plus (+) Expands all blocks of code in the current file.
instead of Alt-Shift-Period.
Alt-Shift-Period.
Cutting, Copying, Pasting, and Deleting Text
3. Generate code skeletons. Whenever you want to generate commonly needed pieces of code, such
Keys Action
Cmd-Z Undo. Reverses a series of editor actions one at a time
(excluding Save). 1 of 4 4/21/08 10:44
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. 3. Generate code skeletons. Whenevergenerate commonly needed pieces of code, such
3. Generate code skeletons. Whenever you want to you want to generate
10 Handy Editor Shortcuts needed pieces of
commonly in NetBeans IDE 6.0 code, such as constructors, http:/
Cmd-E Deletes the current line.
Cmd-K Copies the word preceding the insertion point and then
1 of 4 getters, and setters, simply click Alt-Insert, and a small popup 4/21/08 10:44
pastes it after the insertion point (the insertion point must appears with agetters, items fromsimply click Alt-Insert, and a small popup appears
as constructors, list of and setters, which you can select:
be in the whitespace preceeding or following a word). items from which you can select:
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 10 Handy Editor Shortcuts in NetBeans IDE 6.0 http://netbeans.dzo
whitespace preceeding or following a word.) Press L multiple
times to cycle through consecutive following words.
as constructors, getters, and setters, simply click Alt-Insert, and a small popup appears with a list
items from which you can select:
To Change Default Settings:
1. Choose Tools > Options from the main menu.
2. For code templates, select Editor and click the Code 4. Inplace rename. If you want to change a variable, method, or other item, of which
4. Inplace in your code,you want to change will see that all instances of the item turn
are used rename. If press Ctrl-R, and you a variable, method,
Templates tab. Here you can also change the expansion
or other item, of which more than one are used inselected item, all the other ins
same time, as shown below. Now, when you change the your
key, from Tab to something else. at the same time, until you press Escape, at which point the inplace rename mode come
code, press Ctrl-R, and you will see that all instances of the
3. For keyboard shortcuts, select Keymap and choose a item turn blue at the same time, as shown below. Now,
profile from the Profile drop-down list. when you change you want to change a variable, method, or other item, of which more than
4. Inplace rename. If the selected item, all the other instances
changein your code, press Ctrl-R, andyou will see Escape, at which item turn blue at the
are used at the same time, until you press that all instances of the
same time, as shown below. Now, when you change the selected item, all the other instances cha
pointsame time, until rename Escape, at which point the inplace rename mode comes to an end
at the the inplace you press mode comes to an end.
10 HANDY EDITOr SHOrTCUTS
The following are some of the many cool NetBeans IDE 6.0
keyboard shortcuts that no programmer will be able to do 5. Add/Remove comment lines. Select one or more lines, press Ctrl-/ and then the se
without, once you know they’re there. Not all of these are commented out, as shown below. Press the same keys again and the commented lines
new in 6.0, some were there before, but deserve to be be commented. This was, of course, also possible in previous releases, but previously
different keyboard shortcuts, one for commenting and one for uncommenting. Now th
highlighted because often they’re overlooked. been combined into one shortcut, you can quickly toggle between comment and uncom
5. Add/Remove comment lines. Select more efficient. press Ctrl-/ and then the selected lines
makes this activity much faster and one or more lines,
commented out, as shown below. Press the same keys again and the commented lines will no lon
DZone, Inc. | www.dzone.com This was, of course, also possible in previous releases, but previously there were
be commented.
different keyboard shortcuts, one for commenting and one for uncommenting. Now that they hav
5. 5
NetBeans IDE 6.1 Java Editor
tech facts at your fingertips
4. Inplace rename. If you want to change a variable, method, or other item, of which more than one
are used in your code, press Ctrl-R, and you will see that all instances of the item turn blue at the
same time, as shown below. Now, when you change the selected item, all the other instances change
at the same time, until you press Escape, at which point the inplace rename mode comes to an end.
10 Handy Editor Shortcuts, continued 8. Jump to last edit. Often, you find yourself in a situation
where you have edited in one document, while you
5. Add/Remove comment lines. Select one or more lines, currently find yourself in a completely different document.
press Ctrl-/ and then the selected lines are commented How do you get back to the place where you were last
out, as shown below. Press the same keys again and the editing your code? That is likely to be the place where you
commented lines will no longer be commented. This want to get backedit. Often, you find yourself in a situation where you hav
8. Jump to last to, in order to do some more editing.
while you currently find yourself in a completely different document. How
was, of course, also possible in previous releases, but Now, whenever you click Ctrl-Q, the last edited document to be the place
place where you were last editing your code? That is likely
previously there were two different keyboard shortcuts, is found, and the cursormore editing. Now, whenever you click Ctrl-Q, the
to, in order to do some lands on the line where the last
5. Add/Remove comment lines. Select one or more lines, press Ctrl-/ and edit theand the cursorare
then took place. lines lands on you line wherethe button took place. Alter
found, selected Alternatively, the can click the last edit
one for commenting and one for uncommenting. Now
commented out, as shown below. Press the same keys again and the commented lines will in the top the top left of the SourceSource Editor:
shown below, no longer left corner corner of the Editor:
button shown below, in
that they have been was, of course, also possible inyou can releases, but previously there were two
be commented. This combined into one shortcut, previous
quickly toggle between comment and uncomment, one for uncommenting. Now that they have
different keyboard shortcuts, one for commenting and which
been combined into one shortcut, you can quickly toggle between comment and uncomment, which
makes this activity much faster and more efficient.
makes this activity much faster and more efficient.
9. Bookmarks. When you you press Ctrl-Shift-M,current line line is quot;bookma
9. Bookmarks. When press Ctrl-Shift-M, the the current
6. Inspect members/hierarchy. Both the members of the current class as well as its can later quickly cycle back/forward to it (with Ctrl-Shift-Period a
that you hierarchy can be
is “bookmarked”. What this means is that you can later
6. Inspect members/hierarchy. Both the members of the of the current file are shown. linethe a small icon in the left sidebar, as shown below, unt
displayed and then filtered. Press Alt-F12 and the ancestors bookmarked On gets
quickly cycle back/forward to it (with Ctrl-Shift-Period and
on the line again, to remove the bookmark:
current class as well as Ctrl-F12, the current file's members are displayed, as shown here:
other hand, if you press its hierarchy can be displayed and
Ctrl-Shift-Comma). The bookmarked line gets a small
then filtered. Press Alt-F12 and the ancestors of the current icon in the left sidebar, as shown below, until you press
10 Handy Editor Shortcuts in NetBeans IDE 6.0
10 Handy Editor are shown. On the IDE 6.0 hand, if you press Ctrl-F12,
file Shortcuts in NetBeans other Ctrl-Shift-M on the line again, to remove the bookmark:
http://netbeans.dzone.com/print/280
the current file’s members are displayed, as shown here:
10 Handy Editor Shortcuts in NetBeans IDE 6.0 http://netbeans.d
3 of 4
10 Handy Editor Shortcuts in NetBeans IDE 6.0 http://netbeans.dzone.com/print/280
2 of 4 10. 10.Highlightexitexit points.the cursor on cursor thethe return type and you will ei
Highlight points. Place the cursor on on return type
Highlight exit points. Place Place the
points highlighted: 4/21/08 10:44 AM the return type and you will immediately see all
10.
pointsyou will immediately see all exit points highlighted:
and highlighted:
7. Switch between documents. When you have multiple documents open at the same time, press
7. Ctrl and between then a small popup appears. You can scroll through the popup, which displays all
Switch Tab, and documents. When you have multiple
documents open at the same time, press Ctrl and Tab,
the open documents, and then choose the document that you want to open:
and then a small popup appears. You can scroll through
the popup, which documents. When you have multiple and
7. Switch between displays all the open documents, documents open at the same time, press
Ctrl and Tab, and then a small popup appears. You can scroll through the popup, which displays all
then choose the document choose thewant to open: you want to open:
the open documents, and then that you document that
Source URL: http://netbeans.dzone.com/news/10-handy-editor-shortcuts-netbeans-ide-60
QUICk OPTIONS WINDOW OvErvIEW
The Options window lets you customize NetBeans IDE in a
number of URL: Most people don’t know how much can be
Source ways. http://netbeans.dzone.com/news/10-handy-editor-shortcuts-n
customized there. The table below provides an overview.
General
8. Jump to last edit. Often, you find yourself in a situation where you have edited inSets the IDE-wide browser and the
one document, Web Browser
n
proxy settings. Proxy Settings
n
while you currently find yourself in a completely different document. How do you get back to the
place where you were last editing your code? That is likely to be the place where you Sets theto get back options,
Editor want editor-specific n Code Folding
to, in order to do some more editing. Now, whenever you click Ctrl-Q, the last edited specifically those relating to code
document is n Code Completion
8. Jump tothe cursorOften, on the line where the last edit where you Alternatively, you can click the
and last edit. lands you in a completely different document. How do you in back to theindentation, code templates,
found,you currently find yourselffind yourself in a situation took place.have editedget onefolding, code completion, camel case
document, n Camel Case Behavior
while behavior, n Indentation
buttonwhere you were in the top left corner of the is likely Editor: place where you want tomacros.
place shown below, last editing your code? That Source to be the and get back n Code Templates
Source URL:
to, in order to do some more editing. Now, whenever you click Ctrl-Q, the last edited document is
n Macros
FYI http://netbeans.dzone.com/news/10-handy-
found, and the cursor lands on the line where the last edit took place. Alternatively, you can click the
Java Code Sets options specifically for the Java n Formatting
button shown below, in the top left corner of the Source Editor: editor, relating to the formatting, hints, Hints
editor-shortcuts-netbeans-ide-60
n
mark occurrences, and task list. n Mark Occurrences
n Tasklist
DZone, Inc. | www.dzone.com