Book Image

Mastering Netbeans

5 (1)
Book Image

Mastering Netbeans

5 (1)

Overview of this book

Table of Contents (17 chapters)
Mastering NetBeans
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Code templates and code snippets


In the previous section, we saw how to create and customize templates for different file types. This can be very useful when creating new files.

NetBeans takes automatic code creation even further, however, with the ability to define both code templates and code snippets. Code templates allow a short piece of code to be entered within the main source code editor that is expanded into a larger template upon pressing the Tab key.

Inserting code using code templates

First, let's take a look at code templates. NetBeans provides over 100 code templates for the Java language and many more for JavaScript, HTML, and others. Some of the more common code templates are shown in the following table:

Code template

Description

pf

Expands to public final

do

Expands into a do … while loop

fori

Expands to a for loop

log

Expands to a Logger class to output a log entry

serr

Expands to System.err.println("");

sout

Expands to System.out.println("");

...