Beruflich Dokumente
Kultur Dokumente
JDK 7 Features Keyboard Shortcuts & Code Templates 10 Handy Editor Shortcuts Resources and more!
Programming in Java 7
By the NetBeans Team
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:
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.
JDK 7 FEATURES
NetBeans IDE 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.
DZone, Inc.
www.dzone.com
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. In NetBeans IDE 7.0, the Java Editor provides tools for using JDK 7, in NetBeans IDE 7.0.1, you can run the IDE itself on JDK 7, and NetBeans IDE 7.1 brings great enhancements, such as block selection, bulk refactoring, and an import organizer.
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
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
DZone, Inc.
www.dzone.com
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
Copy Class Move Inner to Outer Level Convert Anonymous Class to Inner
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()) {
DZone, Inc.
www.dzone.com
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
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.
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.
.
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.
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
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 Alt-Shift-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/10-handyeditor-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
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
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.
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:
Cost by... Data Tier Technologies t to you ply. brough Platform Management and more... te. Com bora
Aldon
ge. Colla Chan
#6 Cloud 4Computing
By Daniel Rubio
also minimizes the need to make design changes to support CON TEN TS one time events. INC
Vis i
ION EGRAT
www.dzone.com
Re fca
rd z!
Ge t
Mo re
Cloud Computing
expand
s on
e.com
Ge t Mo re
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 Practice Build
to isolat 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 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 S INT e code ding Task what it is a cloud computingaplatform can offer your web INUOU trol ut line Policy nize sourc es as of buil Orga Code e witho it chang cess CONT ion con e name sourc T 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 Redu Autom ns (i.e. ory. d deploEAR) in each lar pro that pattern ticu tagge via or cies -patter s reposit t nden For each (e.g. WAR es lained ) and anti the par solution duce al Depe ge t Web application deployment untillibrari yearsenvironmen similar x packa Minim be exp nden a few target ago was text ns are d to to pro all rity all depe CI can ticular con alizeplans with le that y Integ es use Anti-patter they tend es, but can to late alloted resources, with an Centr Binar most phone services: ts etim , temp s. nt nmen ctic in a par hes som geme t enviro e a single based on incurred cost whether such resources were consumedto thenot. or proces in the end bad pra enting Creat cy Mana nt targe es rties are nden implem approac ed with the cial, but, chang prope Depe essarily into differe itting d to er nec e te builds pare e comm late Veri associat to be ben befor are not Cloud computing asRun remo its known etoday has changed this. etc. Temp n com Build ually, They Privat lts whe y, contin appear effects. rm a The various resources consumed by webperiodicall applications (e.g.nt team Perfo opme ed resu d Builds sitory Build gration r to devel Repo Stage adverse unintend bandwidth, memory, CPU) areIntegration on from CI serve basis tallied a per-unit e ous Inte e Build rm an ack produc Privat . feedb Continu Refcard on (starting from zero) by Perfomajor cloud computing platforms. all ated occur term pattern based autom tion e, this as as they the builds Build gra 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 to the s Gene While of CI
Re fca
rdz !
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
atio Having the capability to support one time events, cloud Useful n Open computing platforms also facilitate the gradual growth curves Page Source Stru Tools faced by web applications. ctur Key
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.
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 HTML a> is s has ne. b></ ed insid bec heavily based on very little 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 simplify will help L VS <a>< and XHT ardless XHTM b></ all you ML, ML physical r othe you prov to L Virtualization allows aare actu piece of hardware idebe understand of 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 ler than ing. Fort commo on nd for unately they (e.g. bandwidth,n elem CPU) to be mov memory, ality has allocated exclusively to expecte irably, that some used Every job time. d. Earl to be, HTML ent instances. ed to CSS page Brow individual operating system s While y HTM has expand because . ser (HTM common it has ed far L or XHT done web dev manufacture L had very more its extensio .) All are ML shar limit than rs add elopers 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
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
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.
Version 4.0