You are on page 1of 6

#14

Get More Refcardz! Visit refcardz.com


CONTENTS INCLUDE:
n

brought to you by...

JDK 7 Features Keyboard Shortcuts & Code Templates 10 Handy Editor Shortcuts Resources and more!

Update for NetBeans IDE 7.0

Programming in Java 7
Integer literals and underscores Binary integer literals are now
available in addition to octal, decimal, and hexadecimal literals. Underscores make code more readable.

NetBeans IDE 7:
By Geertjan Wielenga

INTRODUCTION

NetBeans IDE 7 is an Oracle sponsored free and open-source Java integrated development environment. Developers from the Java Development Kit (JDK) team have worked closely with developers from the NetBeans team to create a well-aligned JDK 7 development experience for Java developers in NetBeans IDE. NetBeans IDE 7 introduces support for new JDK 7 language features, such as the diamond syntax for constructors, strings in switch, and multicatch. When you use these constructs in your code, NetBeans IDE recognizes them, offers correct classes in code completion, correctly highlights errors, and lets you automatically migrate old syntax. Youll find this reference card helpful if you want to get as much out of JDK 7 and NetBeans IDE 7 as their creators intended. This card focuses on all the new JDK 7 language features and on how NetBeans IDE 7 has been tuned to support them. In addition, you will find lists of NetBeans IDE keyboard shortcuts in carefully thought-out categories, together with expositions of optimal handling of Java code in the editor, covering viewing, navigation, source handling, and refactoring. Go to http://www.netbeans.org to get NetBeans IDE 7. Multicatch Variable Declaration Support Code completion is supported for the multicatch variable declaration. Hints to join multiple catches into one multicatch are provided if the handling code is the same.

Try-with-resources Correctly and robustly manage resources that


otherwise need to be explicitly closed. This form of the try statement obviates the need for manual resource closing.

JDK 7 FEATURES

NetBeans IDE 7: Programming in Java 7

This section introduces all the JDK 7 language enhancements in Project Coin and how you can start using them in NetBeans IDE 7. Strings in Switch In previous versions of Java, the argument of
switch had to be only of the primitive data types: byte, short, char, int, or enum. Now, with JDK 7, the String data type is added. NetBeans IDE 7 recognizes when if-then-else statements are used instead of switch statements and offers to convert them to the switch statement.

Diamond Syntax Support The new diamond syntax for


constructors allows for more compact and readable code by saving repeated type arguments. Included is new support for LinkedList<>().

DZone, Inc.

www.dzone.com

NetBeans IDE 7: Programming in Java 7

JAVA EDITOR OVERVIEW

NetBeans IDE 7 is a powerful and intuitive Java development environment. To the left, you see the parts of the IDE that are most commonly used, in particular the rich code editor. Combined with the popular Matisse GUI Builder, Profiler, Java debugger, and tools for generating Java EE 6 applications, the NetBeans IDE provides a complete & productive environment for developing all types of Java applications.

KEYBOARD SHORTCUTS & CODE TEMPLATES


Finding, Searching, and Replacing
Ctrl-F3 F3/Shift-F3 Ctrl-F/H Alt-F7 Ctrl-Shift-F/H Alt-Shift-U Alt-Shift-H Ctrl-R Ctrl-U, then U Ctrl-U, then L Ctrl-U, then S Alt-Shift-V Search word at insert point Find next/previous in file Find/Replace in file Find usages Find/replace in projects Find usages results Turn off search result highlights Inplace Rename Convert selection to uppercase Convert selection to lowercase Toggle case of selection Paste formatted

Ctrl-B Ctrl-G Ctrl-Shift-M Ctrl-Shift-Period/Comma Ctrl-Period/Comma Ctrl-Shift-1/2/3 Ctrl-[ Ctrl-K/Ctrl-Shift K Alt-Left/Alt-Right/Ctrl-Q

Go to declaration Go to line Toggle add/remove bookmark Next/previous bookmark Next/previous usage/compile error Select in Projects/Files/Favorites Move caret to matching bracket Next/previous word match Go backward/forward/to last edit

Compiling, Testing, and Running


F9 F11 Shift-F11 Ctrl-Q Ctrl-Shift-U Compile package/ file Build main project Clean & build main project Set request parameters Create JUnit test Run JUnit test on file/project Run main project/file

Opening and Toggling Between Views


Ctrl-Tab (Ctrl-`) Shift-Escape Ctrl-F4/Ctrl-W Ctrl-Shift-F4/Ctrl-Shift-W Shift-F10 Alt-Shift-D Ctrl-4 Ctrl-8 Toggle between open documents Maximize window (toggle) Close currently selected window Close all windows Open contextual menu Undock window Open Output window Open Kenai Dashboard

Ctrl-F6/Alt-F6 F6/Shift-F6

Debugging
Ctrl-F5 Ctrl-Shift-F5 Ctrl-Shift-F6 Shift-F5/F5 F4 F7/F8 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

Navigating through Source Code


Ctrl-O/Alt-Shift-O Ctrl-Shift-T Alt-O Go to type/file Go to related JUnit test, if any Go to source

Ctrl-F7 Ctrl-Alt-Up Ctrl-Alt-Down Ctrl-F9

DZone, Inc.

www.dzone.com

NetBeans IDE 7: Programming in Java 7

Ctrl-F8 Ctrl-Shift-F8 Ctrl-Shift-F7

Toggle breakpoint New breakpoint New watch

cn df dowhile eq ex fa fi fl forc

continue default: do { } while (condition); equals extends false final float for (Iterator it = collection.iterator(); it.hasNext();) { Object elem = (Object) it.next(); } for (Object elem : iterable) { } for (int i = 0; i < arr.length; i++) { } finally interface if (condition){}else { } implements instanceof import length Object name = new Object(args); protected private private static final private static final boolean private static final int private static final String printStackTrace(); public static void main(String[] args){ } public return System.err.println ("|"); System.out.println ("|"); static switch ( synchronized Thread.dumpStack(); throws try {} catch (Exception e) {} throw throw new while (

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
Rename

Description
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. Enables you to generate a statement based on the selected code and replace that block of code with a call to the statement. Enables you to add parameters to a method and change the access modifier. Generates a getter method and a setter method for a field and optionally updates all referencing code to access the field using the getter and setter methods. Moves methods and fields to the superclass. Moves inner classes, methods, and fields to all subclasses of their current 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. Copies a class to the same or a different package. Moves an inner class one level up in hierarchy. 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. Creates a new interface from the selected public non-static methods in a class or interface. 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. Changes code that references the selected class (or other type) to instead use a supertype of that type. Checks for references to a code element and then automatically deletes that element if no other code references it.

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

Pull Up Push Down Move Class

Copy Class Move Inner to Outer Level Convert Anonymous Class to Inner

Extract Interface Extract Superclass

Use Supertype Where Possible Safely Delete

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 Ex Ob Psf Psfb Psfi Psfs St ab bo br ca cl Enumeration Exception Object public static final public static final boolean public static final int public static final String String abstract boolean break catch ( class

while (it.hasNext()) {

Object elem = (Object) it.next(); }

JSP Code Templates


ag ap ar cfgi application.getAttribute(|) application.putAttribute(|,) application.removeAttribute(|) config.getInitParameter(|)

DZone, Inc.

www.dzone.com

NetBeans IDE 7: Programming in Java 7

jspf jspg jspi jspp jsps jspu oup oupl pcg pcgn pcgs pcr pcs pg pga pgb pgc pgerr pgex pgie pgim pgin pgit pgl pgs rg sg sp sr tglb

<jsp:forward page=|/> <jsp:getProperty name=| property= /> <jsp:include page=|/> <jsp:plugin type=| code= codebase=></jsp:plugin> <jsp:setProperty name=| property=/> <jsp:useBean id=I type=/> out.print(|) out.println(|) pageContext.getAttribute(|) pageContext.getAttributeNamesInScope(|) pageContext.getAttributesScope(|) pageContext.removeAttribute(|) pageContext.setAttribute(|,) <%@page |%> <%@page autoFlush=false%> <%@page buffer=|kb%> <%@page contentType=|%> <%@page errorPage=|%> <%@page extends=|%> <%@page isErrorPage=true%> <%@page import=|%> <%@page info=|%> <%@page isThreadSafe=false%> <%@page language=java%> <%@page session=false%> request.getParameter(|) session.getAttribute(|) session.setAttribute(|, ) session.removeAttribute(|) <%@taglib uri=|%>

Ctrl-G Cmd-A

Jumps to any specified line. Selects all text in the file.

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.

Cutting, Copying, Pasting, and Deleting Text


Keys Cmd-Z Cmd-Y Cmd-X the clipboard. Cmd-C Cmd-V Backspace Delete Cmd-E Cmd-K Action Undo. Reverses a series of editor actions one at a time (excluding Save). Redo. Reverses a series of Undo commands one at a time. Cut. Deletes the current selection and places it on Expands all blocks of code in the current file. Copy. Copies the current selection to the clipboard. Paste. Pastes the contents of the clipbard at the insert point. Deletes the current selection. Deletes the current line. 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. 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.

Cmd-Shift-K

Changing Default Settings Each code template can be customized and new ones can be easily created. 1. Choose Tools > Options from the main menu. 2. For code templates, select Editor and click the Code Templates tab. Here you can also change the expansion key from Tab to something else. 3. For keyboard shortcuts, select Keymap and choose a profile from the Profile drop-down list. 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. First, the Options window on the Mac is found under NetBeans > Preferences. Second, the About box is under NetBeans > About.
.

10 HANDY EDITOR SHORTCUTS

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.

Scrolling and Selecting


Keys Cmd-[ Action 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. 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.

2.Capture inner/outer syntactic element Each time you press AltShift-Period, the selection expands to a successively wider syntactic element. For example, one statement was selected below, the key combination Alt-Shift-Period was pressed, and then the complete content of the surrounding block statement was shown to be selected.

Cmd-Shift-[

DZone, Inc.

www.dzone.com

NetBeans IDE 7: Programming in Java 7

The selection expands from the current statement to surrounding block statements to the surrounding method and, from there, to the surrounding class and further. To successively narrow the selection, press AltShift-Comma instead of Alt-Shift-Period.

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 file are shown. On the other hand, if you press Ctrl-F12, the current files members are displayed, as shown here: Source URL: http://netbeans.dzone.com/news/10handy-editor-shortcuts-netbeans-ide-60

3.Generate code skeletons Whenever you want to generate commonly needed pieces of code, such as constructors, getters, and setters, simply click Alt-Insert and a small popup appears with a list of items from which you can select.

7.Switch between documents When you have multiple documents open at the same time, press Ctrl and Tab and a small popup appears. You can scroll through the popup, which displays all the open documents, and then choose the document that you want to open.

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. 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.

5. Add/Remove comment lines Select one or more lines, press Ctrl-/ and then the selected lines are commented out. Press the same keys again and the commented lines will no longer be commented.

8.Jump to last edit Often, youll recently have coded in one Java file, while you currently find yourself in a completely different file. How do you get back to the place where you were last editing your code? That is likely to be the place where you want to get back to so that you can do some more editing. Whenever you click Ctrl-Q, the last edited document is found and the cursor lands on the line where the last edit took place. Alternatively, you can click the button in the top left corner of the Source Editor.

DZone, Inc.

www.dzone.com

NetBeans IDE 7: Programming in Java 7

9. Bookmarks When you press Ctrl-Shift-M, the current line is bookmarked. This means that you can later quickly cycle back/ forward to it (with Ctrl-Shift-Period and Ctrl-Shift-Comma). The bookmarked line gets a small icon in the left sidebar until you press Ctrl-Shift-M on the line again to remove the bookmark.

RESOURCES

NetBeans DZone Community NetBeans Weekly Newsletter: NetBeans Blogs NetBeans and Project Coin at JDK 7 Launch Event

http://netbeans.dzone.com/ http://www.netbeans.org/community/news/newsletter/latest. html http://planetnetbeans.org/ http://www.oracle.com/us/corporate/events/java7/index.html

10. Highlight exit points Place the cursor on the return type and you will immediately see all exit points highlighted.

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, Tom Wheeler, Tushar Joshi, and Joe Darcy.

ABOUT THE AUTHOR

RECOMMENDED BOOK

Geertjan Wielenga is a Principal Product Manager at Oracle, focused on NetBeans. He has been part of the NetBeans team, as product manager, evangelist, and technical author, for the past 7 years. He lives in Amsterdam, in the Netherlands.

The Well-Grounded Java Developer is a unique guide written for developers with a solid grasp of Java fundamentals. It provides a fresh, practical look at new Java 7 features along with the array of ancillary technologies that a working developer will use in building the next generation of business software.

#82
Get More Refcardz! Visit refcardz.com
CONTENTS INCLUDE:

by... Data Tier Technologies t to you brough Platform Management and more...

About Cloud Computing Usage Scenarios Underlying Concepts Cost

Aldon
Chan ge. Colla borate. Comply.

#6 Cloud 4Computing
By Daniel Rubio
also minimizes the need to make design changes to support CON TEN TS one time events. INC

Getting Started with

Browse our collection of over 100 Free Cheat Sheets


Upcoming Refcardz
Core HTML
By An dy Ha rris

Ge t Mo re Re fca

ref ca

E: INC LUD gration NTS ous Inte Change CO NTE Continu at Every ns About Software i-patter Build and Ant Patterns Control ment Version e... Manage s and mor Build tice Prac Build

Cloud Computing

active Repo are within units This Refcard will introduce to you to clouddcomputing, with an softw riente loping ine task-o e Deve Mainl es you emphasis oncodelines providers, so by Commit better understand these softwar chang Level can e code ding Task what it is a cloud computingaplatform can offer your web trol ut line Policy nize sourc es as of buil NTINU Orga Code e witho it chang cess ion con e name sourc T CO applications. and subm it the pro jects vers are from with uniqu ABOU softw (CI) is um the build evel Comm build a pro minim Label Task-L ies to gration ed to activit blem the bare ion ate all cies to t ous Inte committ USAGE SCENARIOS to a pro Autom congurat nden ymen Build depe al tion deplo t Continu ry change ive manu Label d tool nmen the same stalle , a solu , ineffect ) Build eve t, use target enviro ated s (i.e. ce pre-in blem with ymen (i.e. Redu Autom ory. d deploEAR) each lar pro pattern tterns Pay only what you consume in tagge or cies reposit particu tions that e ed via each t nden WAR anti-pa For es lain al Depe ge (e.g. and x the are solu t duc Web application deployment untillibrari yearsenvironmen similar packa Minim be exp nden a few target ago was text) to ns to pro all rity all depe used CI can ticular con le that alize y i-patter they tend es, but can toInteg late Centr Binar most phone services: plans with alloted resources, with an ts etimes , temp s. Ant nt nmen a par ctic in geme t enviro e a single based on hes som incurred cost whether such resources were consumedto thenot. or proces in the end bad pra enting Creat cy Mana nt targe es rties are rily nden implem approac ed with the cial, but, chang prope Depe into differe itting er necessa pared to e te builds e comm late Veri remo associat to be ben befor com are not Cloud computing asRun known etoday has changed this. etc. its Temp n Build ually, They Privat contin lts whe appear effects. rm a The various resources consumed by webperiodically, applications (e.g.nt team Perfo opme ed resu tion d Builds sitory Build to devel Repo Stage adverse unintend Integra bandwidth, memory, CPU) areIntegration on from CI server basis tallied a per-unit e ous e Build rm an ack produc Privat Continu Refcard feedb on (starting from zero) by Perfomajor cloud computing platforms. all tern. ated occur term based autom e, this as as they the pat builds Build gration Send of the soon cycl such ration ion with ors as Integ entat ous Inte tional use and test concepts docum oper Continu conven build include the rate devel to the Gene CI to While efers ion of the not s on expand

Vis it

Ge t

Mo re

ww w.dzone.com

INTEG OUS

RATION

space n e Work riptio itory a Desc These companies have Privat deployed webmanage applications are in long trol repos to n-con lop softw ing and Deve a versio that adapt and scale to large user bases, making them rn les to ize merg Patte it all to minim space Comm many aspects related tomultiple computing. s cloud e Work knowledgeable in a mainline Privat that utilize lop on Deve code lines a system sitory of work

to isolat

rdz !

on: grati s s Inte -Patternvall nuou d Anti Paul M. Du By ContiPatterns an


ABOUT CLOUD COMPUTING

dz. com

ref car

Web applications have always been deployed on servers connected to what is now deemed the cloud. However, the demands and technology used on such servers has changed substantially in recent years, especially with the entrance of service providers like Amazon, Google and es Microsoft. e chang

Vis it

ation Having the capability to support one time events, cloud Useful Open computing platforms also facilitate the gradual growth curves Page Source Stru Tools faced by web applications. cture Key

HTML Automated growth & scalable technologies vs XHT


HTML

Basics

LUD E:

Valid

ML

ents and Large scale growth scenarios involving specialized equipment more... (e.g. load balancers and clusters) are all but abstracted away by relying on a cloud computing platforms technology.

Structur

Elem al Elem ents

ICS In addition, several cloud computing platforms support data HTM tier technologies that L and the precedent set by Relational exceed XHT HTML Database Systems (RDBMS): Map Reduce, web service APIs, is used ML are the prog etc. Some platforms rams writ large scale RDBMS deployments. support as the grap foundation The src of all hical and Java ten attribute and the also recein JavaScri user interfac web develop desc as the e in clien ment. ive data pt. Server-s the ima alt attribute ribes whe output likew ge is describe re the ima mechan from CLOUD COMPUTING PLATFORMS AND ide languag t-side ise unavaila ge le ism. The web pag s alte Nested es like was onc use HTML ble. rnate can be emergin es and use UNDERLYING CONCEPTS and XHT PHP text that e tags found, Tags standard a very loos g Ajax HTML ML as is disp can tech ely-de thei ization, layed cannot be (and freq need ned lang r visual eng nologies if but as for overlap uen it has ine. b></ Amazon EC2: ther stanstandard software and uage with whe Industry dard , so <a>< tly are) nest become virtualization HTM a> is s has ne. b></ ed insid bec heavily based on very little L more Amazons cloud computing ose the curr you cho platform isome a></ imp e b> is mor ent stan to writ not lega each othe that will industry standard software and virtualization technology. ortant, the e HTM e apparen dards HTM r. Tags l, but t. Reg L or XHT will help L VS <a>< and XHT simplify all XHTM b></ ML, und ardless you prov you ML physical r othe L erstand of Virtualization allows aare actu piece of hardware idebe to HTML much a solid of the ing has ally simp r web cod foundati utilized by multiple operating systems. This allows resources function job adm been arou ing. commo on nd for ality has ler than they Fortuna irably, (e.g. bandwidth,n elem CPU) to be mov memory, allocated exclusively to expecte tely som that job used Every d. Earl to be, HTML ent instances. ed to CSS has exp e time. Whi pag Brow individual operating system s because le it . ser man y HTML anded common e (HTML had very far mor has done or XHT ufac web dev its extensio .) All are e than ML shar limit elopers turers add As a user of Amazons EC2 cloud computing platform, you are result anybody es cert ed man ed layout n. HTM essentia came is proc lly plai supp L les assigned essor an operating system in the same wayain on all hosting as elements ort. The late a lack of stan up with clev y competi n text should ng stan st web in dar er wor not be dar kar standar cr

HTM

L BAS

Continuous Delivery CSS3 NoSQL Android Application Development


DZone, Inc. 140 Preston Executive Dr. Suite 100 Cary, NC 27513 888.678.0399 919.678.0300 $7.95 Refcardz Feedback Welcome refcardz@dzone.com Sponsorship Opportunities sales@dzone.com

Re fca

rd z!

DZone communities deliver over 6 million pages each month to more than 3.3 million software developers, architects and decision makers. DZone offers something for everyone, including news, tutorials, cheat sheets, blogs, feature articles, source code and more. DZone is a developers dream, says PC Magazine.
Copyright 2011 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.

e.com

Version 1.0

You might also like