The code template feature of netbeans allows us to quickly write the frequently used code.
It is like the abbreviation that gets expanded to its long form on using that abbreviation. So in this article I will tell you some of the code templates that are already defined in the Netbeans, which are frequently used and the one which are useful and I will also tell you how to create our own code templates.
Before knowing the default code templates in Netbeans, we should first know how to use the code templates.
So suppose we want to use the code template for Boolean. The abbreviation used is bl. So to write Boolean we just need to write bl and then press TAB. So as soon as TAB is pressed, the Netbeans will write the complete Boolean word for you.
Netbeans is an intelligent editor which on expanding automatically identifies the variable on which the code is to be written. For example for the” for each” loop, the abbreviation used is fore. So whenever fore and TAB is pressed, it will automatically write the for each loop for you and it will automatically find the the variables for which you are writing that loop. So it is an intelligent editor.
Here are some of the code templates :
- en = Enumeration
- ex =Exception
- ob = object
- pf = public final
- pfm = this will write the method structure as :
{
}
- pm = this expand the abbreviation as
Public void method
{
}
- ps=public static
- psf public static final
- st = String
- al = to create a new array list.
- bl = Boolean
- br =break
- dowhile = it will expand this abbreviation for do while loop
- for = for loop
- fore = for each loop
- trycatch = it will expand it to try catch block
- psvm= this will write main method.
- sout = this will expand to “System.out.println(“”);
- soutv=this is used when we want to print the values of variables. So this will be expanded to
System.out.println(“variableName=”+variableName);
So this will automatically take the variable name and will write the code as above.
So these were the templates already present in Netbeans. Now suppose we want to create our own templates. So how to do? How to create our own templates.
I will show you how to create it.
Go to Tools->options.
No go to editor tab and then select code template.
The window will look like :
(click on image to enlarge)
This will show you the list of all the code templates present.
Now to add the new template, click on new and enter the abbreviation. And click on OK. Now in the expanded text area, write the code you want to be expand on writing that abbreviation.
Below you can see a combo box named “Expand template on”. This combo box lets you decide when to expand the text. Here default tab is selected. This means that whenever you will press TAB, your abbreviated code will be expanded.
Click on Ok to save the newly created template.
No comments:
Post a Comment