Subscribe Now for FREE! refcardz.com
tech facts at your fingertips
CONTENTS INCLUDE:
About NetBeans IDE
n
Getting NetBeans IDE
NetBeans IDE 6.1 Java Editor
n
Development with NetBeans IDE
n
Keyboard Shortcuts and
n
Code Templates
By Geertjan Wielenga and Patrick Keegan
Quick Options Windows Overview
n
Hot Tips and more...
n
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
Get More Refcardz
QUICk STArT TUTOrIAL
(They’re free!)
This tutorial provides a very simple and quick introduction to
Authoritative content
n
the NetBeans IDE workflow by walking you through the creation
Designed for developers
n
of a simple “Hello World” Java console application. Once you
Written by top experts
n
are done with this tutorial, you will have a general knowledge of
Latest tools & technologies
n
how to create, build, and run applications in the IDE.
Hot tips & examples
n
To follow this tutorial, you need the following software and
Bonus content online
n
resources:
New issue every 1-2 weeks
n
Software or Resource Version Required
Subscribe Now for FREE!
NetBeans IDE Version 6.1 or version 6.0
Refcardz.com
Java Developer Kit (JDK) Version 6 or version 5
www.dzone.com
DZone, Inc. |
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-T Go to JUnit test
(Ctrl-Shift-N).
Alt-O Go to source
2. In the New Project wizard, expand the Java category and
Ctrl-B Go to declaration
select Java Application. Then click Next.
Ctrl-G Go to line
3. In the Name and Location page of the wizard, type
\"HelloWorldApp\" in Project Name and type Ctrl-Shift-M Toggle add/remove bookmark
\"helloworldapp.HelloWorldApp\" 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 \"HelloWorld!\"
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
Compiling, Testing, and Running
with the line:
F9 Compile package/ file
System.out.println(\"Hello World!\");
F11 Build main project
5. From the IDE’s menu bar, choose Run > Run Main
Project (F6). The Output window should show you the Shift-F11 Clean & build main project
\"HelloWorld!\" 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)
Shift-F5/F5 Stop/Continue debugging session
F3/Shift-F3 Find next/previous in file
F4 Run to cursor location in file
Ctrl-F/H Find/Replace in file
F7/F8 Step into/over
Alt-F7 Find usages
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
Coding in Java
Alt-Shift-V Paste formatted
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
www.dzone.com
DZone, Inc. |
3
NetBeans IDE 6.1 Java Editor
tech facts at your fingertips
Java Editor Code Templates, continued
Keyboard Shortcuts & 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
cn continue
Refactoring Operation Description
df default:
Rename Enables you to change the name of a class,
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
eq equals
by its new name.
ex extends
Introduce Variable, Enables you to generate a statement based
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
fl float
Parameters and change the access modifier.
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
Object elem = (Object) it.next( );
referencing code to access the field using the
}
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
ie interface
another class. In addition, all source code in
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
newo Object name = new Object(args);
anonymous inner class is replaced with a call
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
psf private static final
interface.
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
psfs private static final String
new class.
pst printStackTrace();
Use Supertype Where Changes code that references the selected
psvm public static void main(String[ ] args){
Possible class (or other type) to instead use a
supertype of that type. }
pu public
Safely Delete Checks for references to a code element and
then automatically deletes that element if no re return
other code references it.
serr System.err.println (\"|\");
When typing in the Source Editor, you can generate the sout System.out.println (\"|\");
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
trycatch try {}
En Enumeration
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
www.dzone.com
DZone, Inc. |
4
NetBeans IDE 6.1 Java Editor
Published on NetBeans Zone (http://netbeans.dzone.com)
tech facts at your fingertips
10 Handy Editor Shortcuts in NetBeans IDE
6.0
10 Handy Editor Shortcuts, continued
Mac OS Keyboard Shortcuts
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 IDE 6.0 keyboard shortcuts programmer
will be able do without, to you lines right they're there. Not the current in 6.0,
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
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
the About box is under NetBeans > About.
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:
6.0
Scrolling and Selecting
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
2. Capture successively widersyntactic element. Each time you
expands to a inner/outer syntactic element. For example, below one statement was selected,
Ctrl-G Jumps to any specified line.
the key combination Alt-Shift-Period was pressed, and then the complete content of the surrounding
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-
Cmd-A Selects all text in the file.
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.
was pressed, and then the complete content of the
Keys Action
surrounding block statement was shown to be selected.
Cmd-Minus (-) Collapses the block of code in which the insertion point
The selection expands from the current statement to
is currently located.
2. Capture inner/outer syntactic element. Each time you press Alt-Shift-Period, the selection
surrounding blockwider syntactic element. Forsurrounding one statement was selected,
expands to a successively statements to the example, below method
Cmd-Plus (+) Expands the block of code which is adjacent to the
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,
Alt-Shift-Comma, of
and further. To successively narrow the selection, press 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.
3. Generate code skeletons. Whenevergenerate commonly needed pieces of code, such
3. Generate code skeletons. Whenever you want to you want to generate
Backspace Delete Deletes the current selection.
10 Handy Editor Shortcuts needed pieces of
commonly in NetBeans IDE 6.0 code, such as constructors, http:/
Cmd-E Deletes the current line.
getters, and setters, simply click Alt-Insert, and a small popup
1 of 4 4/21/08 10:44
Cmd-K Copies the word preceding the insertion point and then
appears with agetters, items fromsimply click Alt-Insert, and a small popup appears
as constructors, list of and setters, which you can select:
pastes it after the insertion point (the insertion point must
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
be commented. This was, of course, also possible in previous releases, but previously
new in 6.0, some were there before, but deserve to be
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
www.dzone.com This was, of course, also possible in previous releases, but previously there were
DZone, Inc. be commented.
|
different keyboard shortcuts, one for commenting and one for uncommenting. Now that they hav
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
editing your code? That is likely to be the place where you
out, as shown below. Press the same keys again and the
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.
commented lines will no longer be commented. This while you currently find yourself in a completely different document. How
Now, whenever you click Ctrl-Q, the last edited document to be the place
was, of course, also possible in previous releases, but place where you were last editing your code? That is likely
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
previously there were two different keyboard shortcuts,
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 \"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
bookmarked On gets
displayed and then filtered. Press Alt-F12 and the ancestors 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
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
2 of 4 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 Browser
one document, n Web
proxy settings. Settings
n Proxy
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,
want editor-specific
Editor Folding
n Code
to, in order to do some more editing. Now, whenever you click Ctrl-Q, the last edited specifically those relating to code Completion
document is n Code
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, Case Behavior
n Camel
behavior,
while n Indentation
buttonwhere you were in the top left corner of the is likely Editor: place where you want tomacros.
shown below, last editing your code? That Source to be the and get back Templates
place n Code
Source URL: n Macros
to, in order to do some more editing. Now, whenever you click Ctrl-Q, the last edited document is
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
editor, relating to the formatting, hints,
button shown below, in the top left corner of the Source Editor:
editor-shortcuts-netbeans-ide-60
n Hints
mark occurrences, and task list. Occurrences
n Mark
asklist
n T
www.dzone.com
DZone, Inc. |
0 comments
Post a comment