Professional Documents
Culture Documents
CONTENTS INCLUDE:
n
About NetBeans IDE
Java Editor Overview
n
NetBeans IDE Java Updated for
Quick Start Tutorial NetBeans IDE 6.8
n
Keyboard Shortcuts and
Code Templates
By Geertjan Wielenga and Patrick Keegan
n
Hot Tips and more...
The NetBeans IDE has seen adoption snowballing over the shortcuts in carefully thought out categories and it provides
past years and now comes to you with deep Java EE 6 support a thorough exposition of optimal handling of Java code in
in NetBeans IDE 6.8. You’ll find this reference card helpful if you the editor, covering viewing, navigation, source handling, and
want to get as much out of the Java editor (and related tools) refactoring. Go to http://www.netbeans.org/downloads/ to get
as its authors intended when creating it. It lists all the keyboard NetBeans IDE.
The following features are new in NetBeans IDE 6.8 and can be
of particular use to you in the context of creating Java-based ap-
plications
Java EE 6 Support The IDE provides tools for developing applications complying
with the new Java Enterpise Edition 6, specifically web, EJB, web
service, and JPA support. The Java EE 6 compliant server bundled
with the IDE is GlassFish v3.
Facelets Editor For Facelets (JavaServer Faces 2.0), a complete editor with coloring,
code completion, namespace support, component palette, code
folding, error checking, and code templates is provided.
Other Related JavaFX editor, JIRA support, instant messaging, new UI for Kenai
Enhancements projects, and code completion enhancements in SQL editor.
Ctrl-B Go to declaration
NETBEANS IDE JAVA QUICK START TUTORIAL
Ctrl-G Go to line
This tutorial provides a very simple and quick introduction to the Ctrl-Shift-M Toggle add/remove bookmark
NetBeans IDE workflow by walking you through the creation of a
Ctrl-Shift-Period/Comma Next/previous bookmark
simple “Hello World” Java console application.
Ctrl-Period/Comma Next/previous usage/compile error
1. Start NetBeans IDE. In the IDE, choose File > New Project
(Ctrl-Shift-N). Ctrl-Shift-1/2/3 Select in Projects/Files/Favorites
2. In the New Project wizard, expand the Java category and Ctrl-[ Move caret to matching bracket
select Java Application. Then click Next.
Ctrl-K/Ctrl-Shift K Next/previous word match
3. In the Name and Location page of the wizard, type
Alt-Left/Alt-Right/Ctrl-Q Go backward/forward/to last edit
"HelloWorld" in Project Name. Then click Finish.
4. Because you have left the Create Main Class checkbox Compiling, Testing, and Running
selected in the New Project wizard, the IDE has created a
F9 Compile package/ file
skeleton class for you. You can add the "Hello World!"
message to the skeleton code by replacing the line: F11 Build main project
// TODO code application logic here Shift-F11 Clean & build main project
5. From the IDE’s menu bar, choose Run > Run Main Ctrl-F6/Alt-F6 Run JUnit test on file/project
Project (F6). The Output window should show you the
F6/Shift-F6 Run main project/file
"Hello World!" message.
Debugging
KEYBOARD SHORTCUTS & CODE TEMPLATES
Ctrl-F5 Start debugging main project
Ctrl-F3 Search word at insert point Ctrl-Shift-F6 Start debugging test for file (JUnit)
Ctrl-Tab (Ctrl-`) Toggle between open documents Ctrl-Shift-I Fix all class imports
Introduce Variable, Enables you to generate a statement based on forc for (Iterator it = collection.iterator();
Constant, Field, or the selected code and replace that block of code it.hasNext( );) {
Method with a call to the statement. Object elem = (Object) it.next( );
}
Change Method Enables you to add parameters to a method and
Parameters change the access modifier. fore for (Object elem : iterable) {
}
Encapsulate Fields Generates a getter method and and a setter fori for (int i = 0; i < arr.length; i++) {
method for a field and optionally updates all }
referencing code to access the field using the
getter and setter methods. fy finally
ie interface
Pull Up Moves methods and fields to the superclass.
ifelse if (condition){ }else {
Push Down Moves inner classes, methods, and fields to all }
subclasses of their current class.
im implements
Move Class Moves a class to another package or into another iof instanceof
class. In addition, all source code in your project
is updated to reference the class in its new ir import
location. le length
Copy Class Copies a class to the same or a different newo Object name = new Object(args);
package.
pe protected
Move Inner to Outer Level Moves an inner class one level up in hierarchy.
pr private
Convert Anonymous Converts an anonymous class to an inner class psf private static final
Class to Inner that contains a name and constructor. The
anonymous inner class is replaced with a call to psfb private static final boolean
the new inner class. psfi private static final int
Extract Interface Creates a new interface from the selected public psfs private static final String
non-static methods in a class or interface.
pst printStackTrace();
Extract Superclass Creates a new abstract class, changes the current
psvm public static void main(String[ ] args){
class to extend the new class, and moves the
selected methods and fields to the new class. }
pu public
Use Supertype Where Changes code that references the selected class
Possible (or other type) to instead use a supertype of that re return
type.
serr System.err.println ("|");
Safely Delete Checks for references to a code element and sout System.out.println ("|");
then automatically deletes that element if no
other code references it. st static
sw switch (
When typing in the Source Editor, you can generate the text in sy synchronized
the right-column of the following list by typing the abbreviation tds Thread.dumpStack();
that is listed in the left-column and then pressing Tab. th throws
trycatch try {}
Java Editor Code Templates
catch (Exception e) {}
En Enumeration tw throw
Ex Exception twn throw new
Ob Object wh while (
Psf public static final whileit while (it.hasNext()) {
Object elem = (Object) it.next();
Psfb public static final boolean
}
Psfi public static final int
Psfs public static final String JSP Code Templates
St String ag application.getAttribute(“|”)
ab abstract ap application.putAttribute(“|”,)
bo boolean ar application.removeAttribute(“|”)
pcgs pageContext.getAttributesScope(“|”) 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
pcr pageContext.removeAttribute(“|”) preceeding or following a word.) Press L multiple times to cycle
pcs pageContext.setAttribute(“|”,) through consecutive following words.
pgex <%@page extends=”|”%> 3. For keyboard shortcuts, select Keymap and choose a
pgie <%@page isErrorPage=”true”%> profile10 Handy
from Editor
the Profile Shortcuts
drop-down list. in NetBeans IDE
pgim <%@page import=”|”%>
6.0
pgin <%@page info=”|”%>
10 HANDY EDITOR SHORTCUTS
By geertjan
Created 2008/01/16 - 10:13pm
pgit <%@page isThreadSafe=”false”%> 10 Handy Editor Shortcuts in NetBeans IDE 6.0 http://netbeans.dzone.co
1. Move/copy up/down. Press Ctrl-Shift-Up and the current
The following are some of the many cool NetBeans IDE 6.0 keyboard shortcuts that no programmer
pgl <%@page language=”java”%>
selection
will beisable
copied to theonce
to do without, lines
you right above
know they're the
there. Notcurrent
all of these are new in 6.0, some were
pgs <%@page session=”false”%> there before, but deserve to be highlighted because often they're overlooked.
selection. Press
Published Alt instead
on NetBeans of Ctrl and it is moved instead
Zone (http://netbeans.dzone.com)
rg request.getParameter(“|”) 1. Move/copy up/down. Press Ctrl-Shift-Up and the current selection is copied to the lines right
of copied. Press Down instead ofinstead
Up and the andlines of code of copied. Press Down
sg session.getAttribute(“|”) 10
will beinstead
copied
Handy
above the current
of Upbelow Editor
selection. Press Alt
theofcurrent
and the lines Shortcuts
code will
of Ctrl
selection,
be copied belowasthe
in
below:
NetBeans
it is moved
current selection, as below:IDE
instead
sp session.setAttribute(“|”, ) 6.0
sr session.removeAttribute(“|”)
By geertjan
tglb <%@taglib uri=”|”%> Created 2008/01/16 - 10:13pm
The following are some of the many cool NetBeans IDE 6.0 keyboard shortcuts that no programmer
Mac OS Keyboard Shortcuts will be able to do without, once you know they're there. Not all of these are new in 6.0, some were
there before, but deserve to be highlighted because often they're overlooked.
In most cases, working with the IDE on the Mac is no different from
working on other operating systems. Two significant differences 1. Move/copy up/down. Press Ctrl-Shift-Up and the current selection is copied to the lines right
above the current selection. Press Alt instead of Ctrl and it is moved instead of copied. Press Down
do exist, however. Firstly, the Options window on the Mac is 2. Capture
2. inner/outer
Capture
instead of Upinner/outer syntactic
syntactic
and the lines element.
of code element.
will Each
Each time
be copied belowyou time
thepress you as below:
Alt-Shift-Period,
current selection, the selection
found under NetBeans > Preferences. press the
Alt-Shift-Period,
expands to a successivelythe
widerselection expands
syntactic element. to a
For example, succes-
below one statement was selected,
key combination Alt-Shift-Period was pressed, and then the complete content of the surrounding
Secondly, the About box is under NetBeans > About. sively block
wider syntactic
statement element.
was shown to be selected. The selection expands from the current statement to
surrounding block statements to the surrounding method and, from there, to the surrounding class
Scrolling and Selecting and further. To successively narrow the selection, press Alt-Shift-Comma, instead of
For example, below one statement was selected, the key
Alt-Shift-Period.
Keys Action combination Alt-Shift-Period was pressed, and then the
Cmd-[ Moves the insertion point to the highlighted matching bracket.
complete content of the surrounding block statement was
Note that this shortcut only works when the insertion point is shown to be selected.
located immediately after the opening bracket.
Cmd-Shift-[ Selects the block between a pair of brackets. Note that this shortcut
The selection expandssyntactic
2. Capture inner/outer from the current
element. statement
Each time to sur
you press Alt-Shift-Period, the selection
expands to a successively wider syntactic element. For example, below one statement was selected,
only works when the insertion point is located immediately after rounding block statements to the surrounding method and,
the key combination Alt-Shift-Period was pressed, and then the complete content of the surrounding
either the opening or closing bracket.
from there, to the
block statement wassurrounding class
shown to be selected. Theand further.
selection expandsTofromsuc-
the current statement to
surrounding block statements to the surrounding method and, from there, to the surrounding class
Ctrl-G Jumps to any specified line.
cessively narrow
and further. Tothe selection,
successively narrowpress Alt-Shift-Comma,
the selection, instead
press Alt-Shift-Comma, of of
instead
Cmd-A Selects all text in the file. Alt-Shift-Period.
Alt-Shift-Period.
Code Folding 3. Generate code skeletons. Whenever you want to generate commonly needed pieces of code, such
Keys Action
Cmd-Minus (-) Collapses the block of code in which the insertion point is 1 of 4 4/21/08
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.
3. Generate 10 code
Handy
skeletons. Whenever you want to generate
3. Generate codeEditor Shortcuts
skeletons. in NetBeans
Whenever you wantIDE 6.0
to generate commonly needed pieces of code, such
Cutting, Copying, Pasting, and Deleting Text commonly needed pieces of code, such as constructors,
getters, and setters, simply click Alt-Insert, and a small popup
Keys Action as constructors, getters, and setters, simply click Alt-Insert, and a
1 ofappears
4
with a list of items
items fromfrom
whichwhich youselect:
you can can select: 4/21/08
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 Deletes the current selection.
Delete
4. Inplace rename. If you want to change a variable, method, 8. Jump to last edit. Often, you find yourself in a situation
or other item, of which more than one are used in your where you have edited in one document, while you
code, press Ctrl-R, and you will see that all instances of currently find yourself in a completely different document.
4. Inplace rename. If you want to change a variable, method, or other item, of which more than one
the are used in your code, press Ctrl-R, and you will see that all instances of theHow
item turn blue at the same time, as shown below. Now, item doturnyou
blueget back to the place where you were last
at the
whensameyou change
4.
time, Inplace
as the
shown selected
rename.
below.If you
Now,item,
want toall
when the other
change
you instances
a variable,
change themethod,
selected or other
item,item, the
all ofediting
which yourthan
othermore code?
instances one That is likely to be the place where you
change
aretime,
used in youryou
code, pressEscape,
Ctrl-R, and you willpoint
see that
theallinplace
instances of the item turncomes
blue at thean8.end.
Jump to last
at the same
change atsame
the same until
time, astime,
press
shownuntil
below.youNow,press at which
whenEscape,
you change atthe
which
selected
rename
item, mode
all the other to getto
wantinstances back to,
change in order toedit. Often,
do some you editing.
more find yourself
in a situation w
while you currently find yourself in a completely different do
point the inplace rename mode comes to an end.
at the same time, until you press Escape, at which point the inplace rename Now, wheneverplace
mode comes to an end. you click
whereCtrl-Q, the last
you were lastedited
editingdocument
your code? That is likely to
is found, and the to,cursor lands
in order onsome
to do the line
more where the Now,
editing. last whenever you clic
edit took place.found, Alternatively, you can
and the cursor click
lands onthe
thebutton
line where the last edit took
shown below, inbutton the topshown below,ofinthe
left corner the Source
top leftEditor:
corner of the Source Edito
5. Add/Remove
5. Add/Remove comment
5. Add/Remove
comment lines.
lines.Select
comment lines.
Select one
Select or or
oneone
or more
more lines,
morelines, Ctrl-/
lines,press
press Ctrl-/and
andthen the the
then selected lines are
selected lines are
press Ctrl-/commented
and then out,the
as shown below.lines
selected Pressare
the same keys again and
commented the commented lines will no longer
commented be commented. This was, of course, also possible in previous releases, but previously there werenotwo
out, as shown below. Press the same keys again and the commented lines will longer
out,be commented.
as shown This
below.
different was,shortcuts,
keyboard of course, onealso possible inand
for commenting previous
one for releases, but previously
uncommenting. Now that theythere
havewere two
different keyboard shortcuts,
been combined into oneone for commenting
shortcut, you can quickly and onebetween
toggle for uncommenting. Now that which
comment and uncomment, they have
Press
been the samethis
combined
makes keys
into again
one
activity and
shortcut,
much the
you
faster commented
can
and quickly
more linesbetween
toggle
efficient. will no comment and uncomment, which
makes be
longer thiscommented.
activity much faster and more efficient. 9. Bookmarks. When you press Ctrl-Shift-M, the current line
9. Bookmarks. When you press Ctrl-Shift-M, the current lin
is “bookmarked”. thatWhat this later
you can means is thatcycle
quickly you can later
back/forward to it (with Ctrl-S
quickly cycle back/forward
bookmarkedtoline it (with
getsCtrl-Shift-Period andleft
a small icon in the sidebar, as show
Ctrl-Shift-Comma). on theThe bookmarked
line line gets
again, to remove the abookmark:
small
icon
10 Handy in the
Editor left sidebar,
Shortcuts as shown
in NetBeans IDE 6.0below, until you press
6. Inspect members/hierarchy. Both the members of the current class as well as its hierarchy can be
displayed and then filtered. Press Alt-F12 and the ancestors of the current fileCtrl-Shift-M
10 Handy
are shown.Editor on the inline
Shortcuts
On the again,
NetBeans IDE to
6.0 remove the bookmark: http:/
6. Inspect members/hierarchy. Both the
other hand, if you press Ctrl-F12, the members
current file's of the are displayed, as shown here:
members
6. Inspect members/hierarchy. Both the members of the current class as well as its hierarchy can be
current
displayedclass
andasthen
wellfiltered.
as its hierarchy
Press Alt-F12 can and
be displayed
the ancestors and current file are shown. On the
of the
thenotherfiltered.
hand, if Press Alt-F12
you press and the
Ctrl-F12, ancestors
the current file'sofmembers
the current
are displayed, as shown3 of here:
4
file are shown.
10 Handy Editor
On theShortcuts
otherinhand,
NetBeans IDE press
if you 6.0 Ctrl-F12, the current file’s http://netbeans.dzone.com/print/280
2 of 4 4/21/08 10:44 AM
8. Jump to last edit. Often, you find yourself in a situation where you have edited in one indentation, code templates,
document, n Code Templates
n Diff
8. Jump to last edit. Often, you find yourself in a situation where you have edited in one document,
4 of 4
while you currently find yourself in a completely different
DZone, Inc. | document. How do you get back to the
www.dzone.com
place where you were last editing your code? That is likely to be the place where you want to get back
6
NetBeans Java Editor 6.8
Miscellaneous Sets the options for Ant n Ant NetBeans Video Tutorials http://www.netbeans.org/kb/60/screencasts.html
processing, appearance, diffing, n Appearance
NetBeans TV http://netbeans.tv/
JavaScript, Maven, Profiler, n GUI Builder
n Maven
Geertjan Wielenga is the NetBeans technical Pro NetBeans IDE 6 Rich The Definitive Guide to
writer responsible for documentation related Client Platform Edition NetBeans™ Platform is
to the NetBeans Java editor. He is co-author of focuses on the new a thorough and defini-
the book Rich Client Programming: Plugging features of NetBeans tive introduction to the
into the NetBeans Platform. He is known for his 6 as well as what has NetBeans Platform,
popular blog at http://blogs.sun.com/geertjan, changed since NetBeans covering all its major
as well as for his role as a Zone Leader at Javalobby. 5.5, empowering you to APIs in detail, with
be a more effective and relevant code examples
Patrick Keegan has been writing about the productive developer. used throughout.
NetBeans IDE for over 9 years. In addition
to writing help and tutorials, he is co-author
of the NetBeans IDE Field Guide and has BUY NOW
contributed to other books on NetBeans books.dzone.com/books/pronetbeans
and Java. books.dzone.com/books/definitive-guide-netbeans