Most important feature of professional IDEs is the hints feature. They enable me to develop my programs driven by expectations. NetBeans IDE 6.1 Beta supports hints for programming languages. This is an important feature and I use this feature in a particular way which I call expectation driven development.
Before I write my program I like to make a mental picture of the complete program I am going to develop. Modeling tools help me visualize the mental design . I use ArgoUML for modeling the design. The class diagram thus drawn in ArgoUML is a complete picture of the program I want to write. Once this picture is ready the development of the source code becomes piece of cake.
This class diagrams explains that I expect an EquationExample class to contain my main method. I expect an interface IEquation to be implemented by two concrete classes named SquareEquation and CubeEquation. I also have mentioned my expectation of class EquationFactory through the method declarations which says the class EquationFactory shall be a factory class returning objects of concrete classes SquareEquation and CubeEquation in terms of IEquation reference.
I start my program with the settings as EquationExample as my project name and com.mycompany.equation.EquationExample.main as my main method in the NetBeans IDE 6.1 Beta new project dialog box.
In the main method provided by NetBeans wizard through automatic code generation I write the first expectation that I need an variable equationFactory and instanciate it. The NetBeans editor will not help me autocomplete my statement but I know that and do not want to use the autocomplete feature deliberately. Instead I want to exercise a different feature that is hints feature to create the code I want automatically through NetBeans IDE.
So when I write this statement obviously NetBeans shows me hint in the left side of the editor. As soon as I click on the hint NetBeans offers me options for solving the error by adding some code to my project. This time it asked whether NetBeans shall create a class named EquationFactory for me in the same package. This the exact expectation I have so I clicked on the hint suggested and NetBeans created the class for me.
We can see the class EquationFactory created and opened in the editor of its own. We can see NetBeans has not added public access specifier to the class which I will add eventually while completing the code.
Now I again return back to where we started. I want to complete my main method so I will continue writing the main method as if all the elements already exists and as soon as NetBeans find something not written yet it will offer me hint to complete it. This is great feature and this way I will be using it to fulfill my wishes.
This time I created a reference of IEquation interface named squareEquation and called the method createSquareEquation from equationFactory object. Note that IEquation interface is not written yet and even the createSquareEquation method is not there in the EquationFactory class. NetBeans promptly offers me hints for what is not there and still used.
This time NetBeans offered me to write IEquation class. NetBeans has no way to understand that this is an interface so it is offering a class. Anyway I will accept this option.
So here is my IEquation class. Now I will add the public access specifier to the class and replace the word class with interface. This completes my expectation of having an interface named IEquation.
Coming back to the main method again now NetBeans offers me to write the method createSquareEquation and I will accept the offer again.
NetBeans completed my method with the boilerplate code. I will now write new expectation that this method shall create an object of SquareEquation class and return it as IEquation.
As soon as I write the expectation even if the class does not exists NetBeans offers me a hint to write the class and I will accept again.
The hind to write a SquareEquation class.
Now coming back to main method again. I will complete my program by calling the solve method from the squareEquation reference, note that the method solve is not yet written in the IEquation interface. NetBeans offers hind to write that method.
As soon as I accept the offer a method with name solve is written in IEquation interface. Now coming to the SquareEquation class. I will implement the IEquation interface in this class and NetBeans hints me about the missing method solve. As I am implementing the IEquation as per contract I must write solve method and NetBeans hints me for this. I accept the offer again and the method is written for me as a boiler plate method.
I added some code to the method to complete the expectation of returning a square value of the parameter.
In this way I will go on writing the complete program as expected and NetBeans will help me write my program driven by my expectations.
Even if auto completion feature of NetBeans is powerful, I prefer this way of programming where I already know what is to be developed and then NetBeans offering me code writing hints. I call this way of programming as expectation driven development.
with regards
Tushar Joshi, Nagpur
UPDATE:
Now you can watch a video demo of this post. Please visit Expectation driven development through Netbeans IDE video demo.
Monday, March 31, 2008
Expectation driven developement in NetBeans IDE 6.1 Beta
Tuesday, March 25, 2008
Logging issue found in Netbeans IDE 6.1 Beta
While working with the Eclipse Project Importer and Spring Framework 2.5 support in NetBeans IDE 6.1 Beta I found one issue.
When we import an Eclipse project from an Eclipse workspace NetBeans makes a reference to the source folder of Eclipse project. This means that NetBeans makes a folder for the imported project but only to keep the nbproject folder, project.properties and build.xml files which are needed to build the project and are overall NetBeans project configuration files.
The actual Java source code remains on the same place where the Eclipse workspace is located. Now I added the Spring Framework 2.5 support library and tried to Add the configuration file in the project properties dialog box and selecting the Spring Framework node. This functionality does not work beacuse may be the dialog box is assuming the source code to be available in the same directory where the nbproject directory is located.
This is a possible bug in the release. Now if I can pass this information to the NetBeans development team then this bug may get assigned to some developer and we can get a better version of NetBeans next time with this bug resolved.
reporting bugs, issues, is very important part of the open source development concept. Users feedback always help in identification of bugs and also feedback from users gets considered in the future plan of the software. I decided to log this as an bug in the NetBeans IssueZilla.
NetBeans IssueZilla (based on Bugzilla) is an application and database for reporting and tracking bugs. When you enter a bug, Issuezilla assigns it to the appropriate developers and stores it in the database. You, or the developer assigned to the bug, can later modify bug parameters and update bug status.
To log a bug into the NetBeans IssueZilla you need to be registered with the netbeans.org site. This registration can be done from registration page.
First we need to choose a component name. For logging the issue about Spring support I will have to choose the "web" component. For NetBeans IDE 6.1 Beta the NetBeans team has decided to keep the spring support in the web component as it is the responsibility of the web team.
After choosing the component the issue page is shown where we need to select version which I chose 6.1 and subcomponent which chose spring
Then I typed all the description of the found bug into the description area of the bug page. I wrote all the steps involved to reproduce this bug so a developer can check the bug by reproducing the bug on workstation. Ideally I shall also attach the project files I used to identify this bug. The issue page says that the facility for attaching a file will be provided after the bug is logged.
Once my bug was logged I got the link to attach a file. I created a ZIP file for the project I used to check this bug and attached it to the bug.
There is a limit of 1MB for the attachment but we usually attach code samples which are small in size.
My bug number is 131070 and you can see the bug in the NetBeans IssueZilla at http://www.netbeans.org/issues/show_bug.cgi?id=131070
I got an email for the submitted bug and I was also added to the tracking list of this bug so whenever someone updates this bug I will get an email notifying me about the updates.
with regards
Tushar
Monday, March 24, 2008
Spring support in Netbeans IDE 6.1 Beta
(This post expects some knowledge of Spring Framework, writing beans configuration file and using Spring Framework. This post highlights the support for Spring Framework 2.5 in Netbeans IDE 6.1 Beta)
Netbeans IDE 6.1 Beta support Spring Framework 2.5 out of the box. The support is not much for a Java SE console application but we can still see what Netbeans offers for Spring Framework support.
I will start with a new Java SE console application through the new project wizard. I will name my project SpringDemo and will fill the appropriate fields of the Name and Location dialog box.
Netbeans IDE created a project for me with SpringDemo as my main class with a boiler plate main method.
The project yet do not contain any support for the Spring Framework 2.5. I will open the project properties dialog box by choosing the File menu "SpringDemo properties" option.
I will have to choose the Libraries node to add Spring libraries to the project.
After clicking the Add Library button Netbeans offers a list of libraries and we can see Spring Framework 2.5 Library is already available in this version of Netbeans IDE.
I chose the Spring Framework 2.5 Library and it is shown in the Compile Time Libraries of my project.
We can see the library references in the Projects panel now in the Libraries node.
Now I will add one spring beans configuration file. Spring work either with XML configuration file or Java annotations. I will use a beans configuration XML file for this project.
I right clicked on the Source Package node and chose New > Other option.
In the Choose File Type dialog box I chose the XML node and XML Document entry from the file type list.
I named the file as demo-beans. The Netbeans wizard automatically appended the XML extension and also showed me the path where this file will be stored. I have kept the file in the source folder directly so I can use this with a relative path and class path loader in Spring.
Netbeans IDE offers many options for the XML generation. I will choose the XML schema option which will need the URL of the Schema. I know the schema URL for Spring Framework 2.5 is http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
I provided the schema URL for the Spring Framework 2.5 from Spring Framework site. I selected the beans element as the root element and spring as prefix for the namespace.
I used default fields for the XML Model Generator Options.
Now I could see the demo-beans.xml file in the Project panel. There is a spring style leaf decoration to the icon for the file demo-beans.xml. This shows that the Netbeans IDE has identified this file as a Spring Configuration File.
I will create two classes to check the Spring support. First class will be a Developer class with just two private fields name and experienceYears. I will generate the setters and getters for these fields from the Netbeans IDE Source generate setter and getter option.
The second class I will write is SoftwareCompany. I will keep two Developer reference variables in this class. My intentions are to create Developer as well as SoftwareCompany objects through the demo-beans.xml spring configuration file.
I will create the BeanFactory by using the XmlBeanFactory and ClassPathResource classes and will try to fetch the software company object from the spring API. This will need a properly configured demo-beans.xml spring configuration file.
With all the classes written the Projects panel shows like this. Now the only task remaining is to write the demo-beans.xml spring configuration file. To provide classpath support in the spring bean configuration file I must tell Netbeans IDE about the existence of the demo-beans.xml file and ask it to use it as spring bean configuration file.
To configure the spring files I opened the project settings dialog box again.
Now I can see the Spring Framework node in the Categories tree. When this node is selected Netbeans presents configuration files section. I will use the Add File button to configure beans configuration file.
Now Netbeans IDE is ready to provide me support for the auto completion of class paths also in my demo-beans.xml file. As it is a XML file support for XML schema was already there. Now with the setting I just did there is support for completion of class names in the editor as well.
First I will have to remove the spring: prefix which I applied while creating the XML file. Netbeans IDE applies a prefix ns1 by default. I typed spring in place of ns1 so the XML file has spring: prefix applied. I will just remove that prefix as I have found the spring support is not getting applied with the prefixed version of XML file.
After the prefix is removed the file will look like:
To see to auto completion support I started typing the first bean element. The XML editor provided me support for completing the bean element as well as writing the id="developer" path. The real support can be seen when I started typing the class name for the class attribute. Now the IDE is providing me the completion for Java class found in my project.
I completed the beans configuration file with the following contents. There is one developer bean defined. There is a software company bean defined with one reference bean and one direct bean. The usual stuff we always do in the spring configuration files.
Now when I build the project and run the main program I could see the output of the program.
The output was as expected and the Netbeans has provided me support for writing the Spring Beans Configuration file. The support for visualization of these files is still not there. The dist folder now contains JAR for my project as well as a lib folder with the required JAR files which must be shipped with my JAR. The lib folder contains commons-logging and spring-2.5 JAR files.
There are some issues with the Spring support also. When I tried to add a configuration file from an Eclipse imported project Netbeans does not recognize the file as configuration file. There must be some problem with the recognition logic. I must report this as an issue in the Netbeans Issuezilla. I will post the procedure to post a issue in Netbeans issuezilla here next time.
with regards
Tushar Joshi, Nagpur
Saturday, March 22, 2008
Importing Eclipse project in Netbeans IDE 6.1 Beta
Today I will check the Eclipse Importer feature of the Netbeans IDE 6.1 Beta. I have a simple project written in Eclipse. I will now import that project in Netbeans and will run that project. As I have downloaded the very base Java SE pack of the Netbeans IDE 6.1 Beta I must ensure that the Eclipse Importer module is available with me.
The Tools menu has Plug-ins options in this version of Netbeans. So I chose to click on it.
I can see the plugins dialog box with many tabs. The Available Plugins tab shows all the available plugins on the Netbeans site. The installed tab shows all the installed plugins. There is a long list of plugins in the available plugins tab. Now how to locate the Eclipse importer module quickly. Here comes the Search filter feature handy.
I just typed the name Eclipse in the search filter text box on the right top of the dialog box and there was the Eclipse Project Importer plugin with its information available.
As soon as I selected the check box I could see that this plugin is 69kb in size and there was an Install button to install this plugin in my Netbeans.
I clicked the install button.
Netbeans started the plugin installation wizard. It confirmed from me whether this is what I really wanted :)
Netbeans showed me the license with which the plugin was available and obviously if I want this plugin I must accept the license agreement. I did that.
This was the Eclipse Project Importer plug-in was installed and I was notified of this fact with a dialog box.
I can now see the Eclipse Project Importer plug-in in my installed plug-ins tab in the Plug-ins dialog box. To quickly check this I again used the search filter text box situated at the right top corner of the plug-ins dialog box.
Now starts the real show. I have to import my project which I have written in Eclipse into Netbeans. The installation of the plug-in is just a one time activity and was needed just because I had downloaded the basic Java SE pack only. This plug-in may be bundled with the other bigger packs.
I can see there is a new menu available in the File menu drop down. Import Project option has a menu entry named Eclipse Project.
I clicked the Eclipse Project entry from the File > Import projects menu. It showed me a dialog box for the location of the eclipse project. There were options to select either the workspace or the project source folder only. Selecting the workspace is a simple idea so all the dependencies of the projects which are saved in the Eclipse workspace are also imported by Netbeans.
Here I pointed the workspace where I have created the simple Java project.
Netbeans showed me the projects available in the selected workspace. There was PersonExample my project. I checked that project and clicked the finish button.
Netbeans took some time to analyze the files and then opened a project for me in the left projects panel. I can now browse all the project files in Netbeans and also can compile them.
When I tried to run the project Netbeans asked me about the main class in the project. As this is an imported project Netbeans was not already knowing my main class and my project may have many classes with main method. Netbeans offered me a dialog box listing all the classes with main method and a choice for me to select the main class. I did that.
The output was as expected. This was just a Hello World program.
The most important fact was learned when I saw the folder where Netbeans created the importer project files for itself. What I can see is the configuration files only there was no actual code in this path. This highlights that Netbeans only creates a reference to the actual sources in Eclipse workspace. This means I can now work in Eclipse and Netbeans at the same time and keep the files at same place. This is great.
Just for curiosity I opened the project.properties file and saw the src entry pointing towards my Eclipse workspace. This made it clear that Netbeans Eclipse Project Importer module only creates reference to the actual eclipse projects and keeps the files where they are. This make working with Eclipse project and Netbeans on that project simultaneously possible.
with regards
Tushar