D
NetBeans Code Templates

NetBeans IDE 6.1 Code Templates

NetBeans provides a means to generate text via code templates. Code templates provide abbreviated strings that expand into fuller strings or blocks of code. The expansion occurs when the abbreviation is followed by a user-defined key or key sequence. The keys may be SHIFT, SHIFT-SPACE, TAB, or ENTER, as defined. To edit or view NetBeans’ code templates, choose Tools | Options, click Editor, and select the Code Templates tab.

Code template language categories have been provided for many languages. Those provided with the NetBeans 6.1 “Web & Java EE” bundle are shown in Table D-1. Remember that the current version of the exam targets NetBeans 6.1.

TABLE D-1 NetBeans 6.1 “Web & Java EE” Bundle Code Template Categories

Image

Many of the language categories do not yet have content because they have been provided as a means to guide you in organizing your self-created templates in a more maintainable fashion. The category where you put new templates is important because the different categories relate to different file types. For example, you can’t use an HTML code template in an HTML file (for instance, [name].html) if you save it in the Java code template language category. Varying categories appear based on module installations and bundle selection. NetBeans 6.8 provides a means to import and export the code templates.

The NetBeans IDE exam is concerned only with Java code templates. Chapter 6 on the Source Editor covers the code templates. This appendix has been included to provide a fuller listing of available Java code templates. Note that future releases of the IDE may add, remove, or modify code templates for the various language categories including the Java category. Therefore, you should focus on the NetBeans 6.1 Java language code templates for the exam.

Java Code Templates

This section covers the NetBeans 6.1 Java code templates. They have been grouped in this book by relationships to ease the task of memorization. The groupings are as follows:

Image Methods and Members

Image Primitives

Image Interfaces and Classes

Image Class Construction Keywords

Image Modifier Usages

Image Literals

Image Exception Handling Elements

Image Transfer of Control Statement Elements

Image Conditional Statement Elements

Image Iteration Statement Elements

Image System Messages

Image Miscellaneous Elements

Code templates are either expanded to fixed text or are dynamically expanded based on conditions associated with the Special Code Template Syntax. This syntax is best described by documentation produced by NetBeans but is touched on in Chapter 6. You can find the documentation from the IDE Help menu (Help | Help Contents) or by clicking the Help button in the Options window.

Just search for the “Special Code Template Syntax” page. This appendix provides the dynamic code templates for your benefit, but does not explain the syntax because it’s outside of the scope of the exam.

Methods and Members

Commonly used operations in Java have code templates associated with their methods. Table D-2 details six methods that can be expanded from short abbreviations. Remember that length is commonly used as both a method and an instance variable. For example, the length() method is used with the String class (for instance, string.length()), and the length field attribute is associated with arrays (for example, stringArray.length). Also, notice that a code template special syntax element is represented here, ${cursor}. After the psvm abbreviation is invoked, the cursor is placed in the body of the main method where the syntax has been provided. The super code template was added in NetBeans 6.9.

TABLE D-2 Code Templates for Methods and Members

Image

Primitives

Eight primitives are in Java: boolean, char, byte, short, int, long, double, and float. In NetBeans 6.1, two primitives over five characters in length have code templates, boolean and float. Code templates for double and short were added in NetBeans 6.9 Table D-3.

TABLE D-3 Code Templates for Primitives

Image

Interfaces and Classes

Commonly used classes and interfaces have code templates as represented in Table D-4. Enumeration has a template and is an interface. Exception, Object, and String have templates and are classes.

TABLE D-4 Code Templates for Interfaces and Classes

Image

Class Construction Keywords

When creating classes, the code templates in Table D-5 can be used.

TABLE D-5 Code Templates for Class Construction Keywords

Image

Modifier Usages

Access modifiers public, private, and protected have code templates (Table D-6). Various other (non-access) modifiers also have code templates. A useful NetBeans feature is code templates that exist for commonly used combinations of modifiers, as in Psfs for public static final String. As previously mentioned, code templates come in handy for any keyword over five characters. Code templates for the native, transient, and volatile keywords were added in NetBeans 6.9.

TABLE D-6 Code Templates for Modifier Usages

Image

Literals

There are three reserved Java literals (null, true, and false). Since code templates are not necessary for strings under five characters, only the literal false has a template, as shown in Table D-7.

TABLE D-7 Code Templates for Literals

Image

Exception Handling Elements

Exceptions are related to anomalous conditions that affect the flow of execution of your software. Exception handling in Java makes use of various keywords, as shown with the various code templates in Table D-8. You will also notice that the code template for the trycatch abbreviation has special code template syntax. Remember, for this and the other tables that have special code template syntax, you’ll need to reference the NetBeans documentation to fully understand the grammar.

TABLE D-8 Code Templates for Exception Handling Elements

Image

Transfer of Control Statement Elements

Transfer of control statements provides a means to stop or interrupt the normal flow of control. Common keywords used in transfer of control statements are break, continue, and return. The associated code templates are shown in Table D-9. These code templates can be optimized because break is always followed by a semicolon, and so is return, but with an optional return value. For example, consider the following code template ret refinement: return ${cursor};. The cursor is placed between the return keyword and the semicolon, after the ret abbreviation is invoked.

TABLE D-9 Code Templates for Transfer of Control Statement Elements

Image

Conditional Statement Elements

Conditional statements are used when you need to determine the direction of flow based on conditions. Table D-10 includes code templates in support of conditional statements.

TABLE D-10 Code Templates for Conditional Statement Elements

Image

Iteration Statement Elements

Iteration statements are used when you need to iterate through pieces of code. Table D-11 includes code templates in support of iteration statements.

TABLE D-11 Code Templates for Iteration Statement Elements

Image

Image

System Messages

System messages provide notifications to the developer/user. If you don’t use a logging API, you’ve probably typed out System.out.println("[message]"); to produce these messages. Code templates now provide shortcuts for standard error and system messages as detailed in Table D-12.

TABLE D-12 Code Templates for System Messages

Image

Miscellaneous Elements

The following NetBeans 6.1 Java code template abbreviations are related to code templates that are well outside of the scope of the exam, so they are not detailed in this appendix: bcom, fcom, iof, jaxbm, jaxbu, newo, and runn. Code templates have the option of having a description associated with them. Look for detailed descriptions being associated with code templates in future versions of the IDE.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.150.2