Monday, April 14, 2008

NETBEANS 6.1 - what lies beneath....

CAUTIONARY NOTE: This section of blog deals with the non explicitly visible features of the Netbeans IDE. These features are by no means 'new'.

Since any novice can figure out his way through this IDE, i thought i would show you a few cool shortcuts to exploit a few hidden features of this very powerful java IDE.

1) The intelligent code text replacer

Consider the following code for the area application. Consider the scenario in which you need to replace your class variable 'length' with another name say 'l'. Finding all instances of 'length' in the code and replacing it would be nonsensically time consuming. However using a replace all in a text editor causes us problems as we have used the method length to get the no of arguments. However netbeans 6.1 editor has a new feature that helps you out of this situation.

package area;
class dimension
{


float length;
float breadth;
float height;

public void getdim(float ... d)


{

int i=0;
length=d[i++];

breadth=d[i++];
//height=d[i++];

}

public static void perimeter(float ... d)
{
float p=0;

for(int i=0;i<=d.length;i++) { p+=d[i]; } System.out.println("perimeter="+p); } } public class Area { public static void main(String[] args) { float area,volume; dimension obj=new dimension(); obj.getdim(1,2); obj.perimeter(1,2); area=obj.length*obj.breadth; volume=obj.length*obj.breadth*obj.height; System.out.println("area="+area+"volume="+volume); } }

Just select an instance of length and press Ctrl+R which brings up the Rename field dialog.


Give the new name that you desire, 'l' here in our example. And voila, what an intelligent replacement. The variable name successfully changed with the line
"for(int i=0;i<=d.length;i++)" in our code intact. This is an IDE with awesome power people!!!

2. The next not so easily seen feature is the code insertion/generation feature. Just try pressing Alt+Insert keys and you'll find a few insertion options. I really don't understand why good things aren't that easily spot able ;-)

Check the constructor feature in our area program. Truly functional, check the generated code

public dimension(float l, float height) {

this.l = l;

this.height = height;

}

Lets try the most common job we do in classes, i.e. add properties. Relatively easy, and highly customizable options presented.OMG!! What are you making us? Programmers or just intelligent typists? I mean you got even a getter and a setter code block!!!

What else can you possibly ask for?

3 comments:

2djv2EYwk43rfJIAQXjYt_vfuOU- said...

ouaou... I am impressed!!!

The feature has been live in Eclipse for at least 3-4 years!

Congrats to the Netbeans teams, we can't wait to see you implement a colorized java editor! :-/

Rohan said...

Kindly make sure what you call "new" is indeed a new feature. You are talking about a feature which has existed for many years in NetBeans as well. So, you eclipse mongers, tough luck, the author is wrong, and Eclipse is not so great.

Kiran Bhat said...

Hey guys cut it!! I'm speaking of non-explicitly visible features not exactly "new". Netbeans gives you everything that eclipse can give you plus the added support for swings and mobility. Ecplise is plain, and netbeans, well the team hasn't done that a good job in showing their features out in open too.