Reputation: 15432
Sometimes you would like to run a single file to test some code quickly. Typing in public static void main(String[] args) {
each time is tedious. How to do it quicker?
Upvotes: 23
Views: 48481
Reputation: 61
"psvm" is not the most intuitive abbreviation I can think of when I want to quickly insert a main method, so I created a new one more to my liking in the Code Templates library.
"main" seemed to be more natural for me, and since there's nothing else like it in the list of templates, I used it as an abbreviation and copied the same code from "psvm" in.
Now when I type "main" + TAB (without the quotes of course) I get my main method.
It is redundant, but more intuitive for me.
To create "main" go to Tools->Options, click the "Editor" Icon, then the "Code Templates" tab.
my entry looks like this:
main
public static void main(String[] args) {$cursor}
public static void main(String[] args) {
${cursor}
}
Of course, you can always have Netbeans create your application's main class with the main method inserted by default.
You do that by Choosing "Java Main Class" from the "New File" dialog instead of "Java Class". That will do it.
Cheers!
Upvotes: 6
Reputation: 1641
If you want to just run some test why not use your testing framework? like JUnit:
@Test
public void test() {
// do something
}
This way you can even store the test for later usage. It is properbly in most cases not a good idear to think of tests as something to execute once and then throw away.
Upvotes: 2
Reputation: 15432
Thanks to predefined code templates in Netbeans it's simple:
just type psvm
and press Tab.
psvm
is an acronym for: public
static
void
main
Upvotes: 63