Professional Documents
Culture Documents
CONTENTS INCLUDE:
n
About NetBeans IDE Java Editor Overview NetBeans IDE Java Quick Start Tutorial Keyboard Shortcuts and Code Templates Hot Tips and more...
Updated for NetBeans 6.5
www.dzone.com
Right-click inside the editor to produce a list of menu items, for refactoring and more.
Common colors for common syntax elements, which can be modified in the Options window.
Error marks in the right sidebar can be clicked to jump to the line in which the error/warning occurs.
latest release of Suns award-winning open-source IDE that enables developers to rapidly create Web, enterprise, desktop, and mobile applications with Java, C/C++, JavaScript, Ruby, Groovy and PHP.
DZone, Inc.
www.dzone.com
2
tech facts at your fingertips
1. Start NetBeans IDE. In the IDE, choose File > New Project (Ctrl-Shift-N). 2. In the New Project wizard, expand the Java category and select Java Application. Then click Next. 3. In the Name and Location page of the wizard, type "HelloWorldApp" in Project Name and type "helloworldapp.HelloWorldApp" in the Create Main Class field. Then Click finish. 4. Because you have left the Create Main Class checkbox selected in the New Project wizard, the IDE has created a skeleton class for you. You can add the "HelloWorld!" message to the skeleton code by replacing the line:
// TODO code application logic here
5. From the IDEs menu bar, choose Run > Run Main Project (F6). The Output window should show you the "HelloWorld!" message.
Debugging
Ctrl-F5 Ctrl-Shift-F5 Ctrl-Shift-F6 Shift-F5/F5 F4 F7/F8 Ctrl-F7 Ctrl-Alt-Up Ctrl-Alt-Down Ctrl-F9 Ctrl-F8 Ctrl-Shift-F8 Ctrl-Shift-F7 Start debugging main project Start debugging current file Start debugging test for file (JUnit) Stop/Continue debugging session Run to cursor location in file Step into/over Step out Go to called method Go to calling method Evaluate expression Toggle breakpoint New breakpoint New watch
Coding in Java
Alt-Insert Ctrl-Shift-I Alt-Shift-I Alt-Shift-F Alt-Shift Left/Right/Up/Down Ctrl-Shift-Up/D Ctrl/Alt-F12 Ctrl-/ Ctrl-E Generate code Fix all class imports Fix selected classs import Format selection Shift lines left/right/up/down Copy lines up/down Inspect members/hierarchy Add/remove comment lines Delete current line
DZone, Inc.
www.dzone.com
3
tech facts at your fingertips
Introduce Variable, Constant, Field, or Method Change Method Parameters Encapsulate Fields
fore fori fy ie ifelse im iof ir le newo pe pr psf psfb psfi psfs pst psvm pu re serr sout st sw sy tds th trycatch tw twn wh whileit
Copy Class Move Inner to Outer Level Convert Anonymous Class to Inner
Extract Interface
Extract Superclass
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.
DZone, Inc.
www.dzone.com
4
tech facts at your fingertips
1. Move/copy up/down. Press Ctrl-Shift-Up and the current The following are some of the many cool IDE 6.0 keyboard shortcuts programmer selectiontois copiedoncethe knowNetBeans aboveall of these are new that no some were will be able do without, to you lines right they're there. Not the current in 6.0, Published on NetBeans to be highlighted because often they're overlooked. there before, but deserveZone (http://netbeans.dzone.com) moved instead selection. Press Alt instead of Ctrl and it is 1. copied. Press Down instead of Up and the ofMove/copy up/down. Press Ctrl-Shift-Up and the currentinlines is copied to the lines right 10 Handy Editor instead of Ctrl and it selection of code Press Down NetBeans above the current selection. Press Alt Shortcuts is moved instead of copied. IDE 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:
http://netbeans.dzone.com/prin
6.0
By geertjan Created 2008/01/16 - 10:13pm The following are some of the many cool NetBeans IDE 6.0 keyboard shortcuts that no programmer 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. 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 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 expands to a successively widersyntactic element. Each time you Capture 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 press Alt-Shift-Period, the selection expands to a the current statement to block statement was shown to be selected. The selection expands from successurrounding block statements to the surrounding method and, from there, to the surrounding class sively wider syntactic element. For example, below one of and further. To successively narrow the selection, press Alt-Shift-Comma, instead Alt-Shift-Period. statement was selected, the key combination Alt-Shift-Period
Cmd-Shift-[
Ctrl-G Cmd-A
2.
Code Folding
Keys Cmd-Minus (-) Cmd-Plus (+) Cmd-Shift-Minus (-) Cmd-Shift-Plus (+) Action Collapses the block of code in which the insertion point is currently located. Expands the block of code which is adjacent to the insertion point. Collapses all blocks of code in the current file. Expands all blocks of code in the current file.
was pressed, and then the complete content of the surrounding block statement was shown to be selected. The selection expands from the current statement to 2. Capture inner/outer syntactic element. Each time you press Alt-Shift-Period, the selection expands to a successively statements to the surrounding one statement surrounding block wider syntactic element. For example, below method was selected, 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. surrounding block statements the selection, pressand, from there, To successively narrowto the surrounding methodAlt-Shift-Comma,to the surrounding class Alt-Shift-Comma, of and further. To successively narrow the selection, press instead Alt-Shift-Period. instead of Alt-Shift-Period.
3. Generate code skeletons. Whenever you want to generate commonly needed pieces of code, such
1 of 4
4/21/08 10:44
3. Generate code skeletons. Whenever you want to generate 3. Generatecode skeletons. Whenever you want to generate commonly needed pieces of code, such http:/ code, such as constructors, 1 of 4 4/21/08 10:44 getters, and setters, simply click Alt-Insert, and a small popup as constructors, list of and setters, which you can select: appears with agetters, items fromsimply click Alt-Insert, and a small popup appears items from which you can select:
Cmd-Shift-K
http://netbeans.dzo
as constructors, getters, and setters, simply click Alt-Insert, and a small popup appears with a list items from which you can select:
4. Inplace rename. If you want to change a variable, method, or other item, of which 4. Inplace in your code, press Ctrl-R,change a variable, method, are used rename. If you want to and you will see that all instances of the item turn same time, as shown below. Now, when you change the selected or other item, of which more than one are used in your item, all the other ins 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 item turn blue at the same time, as shown below. Now, when you change you want to change a variable, method, instances of which more than 4. Inplace rename. If the selected item, all the other or other item, are used at the same time, until you press that all instances of the changein your code, press Ctrl-R, andyou will see Escape, at which item turn blue at 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.
5. Add/Remove comment lines. Select one or more lines, press Ctrl-/ and then the se 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 different keyboard shortcuts, one for commenting and one for uncommenting. Now th been combined into one shortcut, you can quickly toggle between comment and uncom makes this activity much faster and one or more lines, 5. Add/Remove comment lines. Select more efficient. press Ctrl-/ and then the selected lines
commented out, as shown below. Press the same keys again and the commented lines will no lon
be commented. www.dzone.com This was, of course, also possible in previous releases, but previously there were
different keyboard shortcuts, one for commenting and one for uncommenting. Now that they hav
5
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 10 at the same time, until you press Escape, at which point the inplace rename mode comes to an edit. Often, you find yourself in a situation Handy Editor Shortcuts, continued 8. Jump to last end. 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 8. Jump to last to, in order to do some more editing. want to get backedit. Often, you find yourself in a situation where you hav 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 lastcode? That is likely to be the place was, of course, also possible in previous releases, but place where you were last editing your edited document 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, edit selectedthe cursor lands on you line wherethe button took place. Altern 5. Add/Remove comment one Select one or more lines, press Ctrl-/ and thenfound, and lines Alternatively, the can click the last edit the took place. are one for commenting andlines. for uncommenting. Now button shown below, shown below, in the in left corner corner of the Editor: commented out, as shown below. Press the same keys again and the commented lines will no longer top the top left of the SourceSource Editor: that they have been combined into one shortcut, you canreleases, but previously there were two be commented. This was, of course, also possible in previous quickly toggle between comment commenting and one for uncommenting. Now that they have different keyboard shortcuts, one for and uncomment, which been combined into much faster and more efficient. makes this activity one shortcut, you can quickly toggle between comment and uncomment, which makes this activity much faster and more efficient.
9. Bookmarks. When press Ctrl-Shift-M, the current line 9. Bookmarks. When you you press Ctrl-Shift-M, the current line is "bookma that you can later What this means is that you can later 6. Inspect members/hierarchy. Both the members of the current class as wellis bookmarked. quickly cycle back/forward to it (with Ctrl-Shift-Period a as its hierarchy can be bookmarked line 6. Inspect members/hierarchy. Both the members of the of the current file are shown. Onback/forward to iticon in the left sidebar,and displayed and then filtered. Press Alt-F12 and the ancestors quickly cycle the gets a small (with Ctrl-Shift-Period as shown below, unti on the line remove the bookmark: other hand, if as press Ctrl-F12, the current file's members are current class youwell as its hierarchy can be displayed and displayed, as shown here: again, toThe bookmarked line gets a small Ctrl-Shift-Comma). then filtered. Press Alt-F12 and the ancestors of the current 10 Handy Editor Shortcuts in NetBeans IDE 6.0 icon in the left sidebar, as shown below, until you press file are shown. On the other hand, if you press Ctrl-F12, Ctrl-Shift-M on the line again, to remove the bookmark: 10 Handy Editor Shortcuts in NetBeans IDE 6.0 http://netbeans.dzone.com/print/280 the current files members are displayed, as shown here:
10 Handy Editor Shortcuts in NetBeans IDE 6.0
http://netbeans.dz
3 of 4
10 Handy Editor Shortcuts in NetBeans IDE 6.0 http://netbeans.dzone.com/print/280
2 of 4
Highlight points. Place the cursor on on return type 4/21/08 AM 10. 10.Highlightexitexit points.the cursor on cursor thethe return type and you will ex Highlight exit points. 10:44Place the the return type and you will immediately see all i 10. points highlighted: Place pointsyou will immediately see all exit points highlighted: and highlighted:
7. Ctrl and betweenthen a small popup appears. You can scroll through the popup, which displays all Switch Tab, and documents. When you have multiple the open documents, and then choose the document that you want to open: documents open at the same time, press Ctrl and Tab, and then a small popup appears. You can scroll through 7. Switch between displays all the open documents, documents open at the same time, press the popup, which documents. When you have multiple and 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
7. Switch between documents. When you have multiple documents open at the same time, press
The Options window lets you customize NetBeans IDE in a Source URL: http://netbeans.dzone.com/news/10-handy-editor-shortcuts-n number of ways. Most people dont know how much can be customized there. The table below provides an overview for 6.1 only. 8. Jump to last edit. Often, you find yourself in a situation where you have edited in one document,
while you currently find yourself in a completely different document. How do you get back to the General Sets get back place where you were last editing your code? That is likely to be the place where you want to the IDE-wide browser and the proxy settings. to, in order to do some more editing. Now, whenever you click Ctrl-Q, the last edited document is found, and the cursor Often,on the line where the a situation where you have edited in one document, 8. Jump to last edit. lands you find yourself in last edit took place. Alternatively, you can click the Editor the button you currently findthe top left corner of the different document. How do you get backSets the editor-specific options, while shown below, in yourself in a completely Source Editor: to specifically those relating to code place where you were last editing your code? That is likely to be the place where you want to get backcompletion, camel case folding, code Source URL: to, in order to do some more editing. Now, whenever you click Ctrl-Q, the last edited document is indentation, code templates, behavior, found, and the cursor lands on the line where the last edit took place. Alternatively, you canand macros. click the http://netbeans.dzone.com/news/10-handyFYIshown below, in the top left corner of the Source Editor: button
Web Browser Proxy Settings Code Folding Code Completion Camel Case Behavior Indentation Code Templates Macros
editor-shortcuts-netbeans-ide-60
DZone, Inc.
www.dzone.com
6
tech facts at your fingertips
rESOUrCES
Resource NetBeans DZone Community NetBeans Tutorials NetBeans Video Tutorials NetBeans Blogs URL http://netbeans.dzone.com/ http://www.netbeans.org/kb/index.html http://www.netbeans.org/kb/60/screencasts.html http://planetnetbeans.org/ http://netbeans.tv/ http://www.netbeans.org/community/news/ newsletter/latest.html
Keymap
Miscellaneous
Ant Appearance n Diff n GUI Builder n Profiler n ToDo Tasks n JavaScript n Versioning
n n
Thanks to the following people who kindly gave of their time and expertise in reviewing this refcard: Adam Bien, Tonny Kohar, Varun Nischal, Kristian Rink, and Tom Wheeler.
rECOMMENDED BOOKS
Rich Client Programming will help you get started with NetBeans module development, master NetBeans key APIs, and learn proven techniques for building reliable desktop software. Pro NetBeans IDE 6 Rich Client Platform Edition focuses on the new features of NetBeans 6 as well as what has changed since NetBeans 5.5, empowering you to be a more effective and productive developer.
BUY NOW
books.dzone.com/books/richclientprog books.dzone.com/books/pronetbeans
Available:
Getting Started with Hibernate Search Core Seam Essential Ruby Essential MySQL JUnit and EasyMock Getting Started with MyEclipse Spring Annotations Core Java Core CSS: Part II PHP Getting Started with JPA JavaServer Faces Core CSS: Part I Struts2 Core .NET Very First Steps in Flex C# Groovy NetBeans IDE 6.1 Java Editor
frEE
Design Patterns
Published June 2008
DZone communities deliver over 4 million pages each month to more than 1.7 million software developers, architects and decision makers. DZone offers something for everyone, including news, tutorials, cheatsheets, blogs, feature articles, source code and more. DZone is a developers dream, says PC Magazine.
9 781934 238134
Version 1.1
Copyright 2008 DZone, Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
$7.95