The Netbeans IDE has a number of great features that are given a lot of attention. There are many features like the Netbeans profiler, GUI design tool, Visual Web Pack that can sometimes be invaluable. However, it is too easy to forget about learning the simple stuff. I would like to focus on the features of the editor itself, which individually slightly increase productivity, but together make a big difference. I thought I'd make it a bit more interesting by telling it in story format.
Bob the (code) builder wants to write a basic pair class. He wants to test it so he will make a main method, which will print it out. He begins by starting a new project in netbeans which creates a class with a main method. He begins typing pucl Pare to declare a public static class. Bob is clearly not a good speller.He then presses { and enter to start a new line - the editor automatically inserts the } at then end.
He types pr X x to declare a private variable of type X called x and repeats the process for Y. He types Alt-Insert, to get a menu of things to insert, then presses enter to select the first option, a constructor. He selects both fields then hits ok.
He then types pu St toString{ to create a method that returns a String. He simply wants to print the two values seperated by a comma. So he types re x.t whereupon the auto-suggest suggests he uses the toString method. So he then types + ", "+b.t; He notices the editor is giving him a warning about toString. He presses Alt-Enter to see that it is recommended that this method contain an @Override annotation. He presses enter to add this.
He then goes to his main method. He first wants to create a pair. If you initialise a class in Java you always have to type its name twice, even if they are the same. He avoids this by typing newo. This creates a template which he just fills in values for. He types P Ctrl-K. This searches backwards for the last word starting with P, finding Pair. He could have used it again to go back further or Ctrl-Shift-K to look forwards. He fills in the template >. Notice how Integer has no shortcut. Bob could go into the options and define one. He then presses tab again to move to the next section of the template, the name. He call it p then goes to the next line.
He then notices the above line is underlined red. He puts his cursor over it to get the following error
non-static variable this cannot be referenced from a static context.
His cursor happens to be over the first occurence of pair, so he click and presses Ctrl-Shift-B to get to the source. He soon realises the inner class Pare has to be declared static. which he does by typing st.
He wants to print stuff, so he types sout, which expands to System.out.println() and types p.t to get the toString operation. He hits Alt-Shift-I to handle imports - none are actually required. He then hits F6 to run and sees that it works. His friend Wendy then points pair is mispelt so he hits Ctrl-R which does an inplace rename (no dialog box) and types Pair.
All in all Bob feels he has had a very sucessful coding session.
hello, when i going to start a new project using netbean. the coding already there. so i'm confuse n felt difficult. so, how can i'll b familiar with it. what can i do?
Posted by siti on August 18, 2008 at 12:49 AM EST #
Hey, about netbeans, a lot of the code that is generated isn't that important and you could just delete it if you wanted.
Read here if you want to understand it more http://www.netbeans.org/kb/60/java/quickstart.html
Posted by Chris Leong on August 18, 2008 at 08:18 AM EST #