Presentation of NetBeans 4.0
Contributed by Jean-Baptiste Renaux as part of the Win With NetBeans comptetition
This article is part of a three article series:
An Integrated Development Environment is a bundle of tools, helping programmers. NetBeans is one of them, and he is specialized in Java. You can, this way, free your mind and concentrate easily on your re code.
We will explore most of this software's functionalities, and the most important ones in the first time, then we will practice tutorials. At last, we will finish by a presentation of the plug-ins and the advantages and disadvantages of this IDE.
He is developed by Sun Microsystems, and free downloadable on his official web-site: www.netbeans.org.
Warning : This article's objective won't be to introduce all the functionalities, but having a over head vision of his possibilities. I suggest you to consult the official web-site and the documentation if you have any problem left.
1996: NetBeans project was been launched by a Czech company called Xelfi. They wanted to write a delphi-like IDE, for Java and written with Java. There was two commercial versions, "Developer" 2.0 et 2.1 .
May 1999: the 3.0 beta version is released.
October 1999: Sun Microsystems buy NetBeans. The IDE change is name to " Sun Forte For Java Community Edition ". This version is free, and the professional one has to be bought.
June 2000: Sun release NetBeans in open-source (which is renamed to his original name).
December 2004: The fourth version is released with new features like support for java 5, a better projet manager, an improved graphical interface, Ant is include in projects, ...
For the future:
Spring 2005. The 4.1 version will be released, with J2EE modules
In Sun policy, NetBeans is a root software for "Sun ONE Studio", the ONE's IDE (One Net Environment). ONE is a project supposed to provide a group of applications supposed to help network and development professionals. In this project, we can see "Sun ONE Application server", "Sun ONE Web Services platform", ...
NetBeans will work on Win32, Linux, MacOs X and Solaris. The architecture is written in 100% java.
Furthermore, all the tools we'll see are free. NetBeans is the programmer's swiss knife.
Let's go in File -> New Project
NetBeans propose ready-to-use project templates:
We will go and create a project in Standard -> java application, called "NetBeans".
There are two packages:
"Source Packages" contain your source code. We will put there our files, pictures, ...
"Test Packages" contain the source code of Junit files. Junit is a testing framework (we will see it later).
Warning: this packages are not the same than ones from the java language.
If we want to add an new element in our software, go and select the project in the project tab, and select in the menu File -> New File ...
We have got in this window a lot of file templates, from java packages to servlets, or Swing graphical interfaces.
We create here a java class:
Java Classes -> Java Class
I advise you to test a lot all this kind of templates to understand NetBeans functionalities.
By the way, I created two java packages : netbeans and netbeans.test, and two java classes : Main.java and classeTest.java
If you want to create a template file, do a right click on a project's file, and select Save As Template ...
We will see later how to compile, execute, and distribute a project.
An IDE have to support commonly used files to help programmer's work. NetBeans can recognize these files's structure, colorising some lexical words, and syntaxes:
The auto-completion, sometimes called "intellisense" in some others IDE, allow to suggest the end of your words. An example will be nice to understand it:
Here we start a new line, and we write "String", by pressing CTRL-Space, a pop-up menu open, with the name of usable classes and interfaces, and even a documentation is visible:
The java documentation is by this way, integrated in NetBeans, as we have just saw it.
By writing the following line :
NetBeans underscore it. The reason is there is no constructor available this two arguments, as NetBeans show it :
The automatic correction is available even before compiling the file.
The refactoring is a functionality allowing to rename packages, or files, without need to write/modify a line of code. If you want to rename a package, for example, select it in the Project tab, and choose in the menu Refactor -> Rename ...
Click on "Next", you will see a briefing of all the actions which will be executed by NetBeans:
By clicking on "Do Refactoring", the "netbeans" package will be renamed to "supinfo.labo.sun", and the main.java file will be moved to the new package.
We can see different files in different directories :
Creating the documentation allow the other programmers to understand the architecture of your code. We can use the javadoc tool, provided in the JDK, through the NetBeans graphical interface.
Javadoc use comments of your code to write the documentation files (with the symboles /** @autor name_of_the_autor */, for exemple).
By selecting in the menu Build -> Generate JavaDoc For Project, the documentation is done. You can consult it in the dist/javadoc file of your project.
Compilation is taken in charge by xml files, interpreted by Ant. Without special needs, this part is automatically generated.
Compilation is automatic at software executing, by doing Run ---> Run Main Project ... Compilation can be launched manually by selecting in the menu Build -> Build main project. The application's jar file will by located in the "dist" directory from the application's root directory (which you can see in the "Files" tab ).
Xml files supposed to be used by Ant are automatically generated in the "nbproject" files in the application's root directory. They will be used later at compilation time, documentation generating time, launch time.
If you don't know how ant is working, we suggest you to read the official documentation.
While you are writing your code, it's important to control each part of your software's execution. If you want to launch your application step-by-step, there is three stages:
The windows in Window -> Debug will give you a lot of informations about variables, threads, ...
Tests are growing importantly when your projects are larger and larger. It is unthinkable to write them in a main() function. We should better organize them in test classes, creating a test class for each class in your application. Hence, the Junit framework allow you to simulate the execution of you application.
How to create a test:
Here is an example, for a Junit class:
This Junit class can be launched at any time, in the NetBeans interface, by selecting Run ---> Run Other ---> Test File.
In this case, the Junit class output this strings :
We let you consult a good tutorial about Junit, at its official website: http://junit.sourceforge.net/doc/testinfected/testing.htm
NetBeans allow you to use internationalization (i18n) java functions.
Create a new standard project, with a new class and write this line in the main() method:
NetBeans will insert a value in your line:
To select key values, you can use final values in the java.util.Locale package, like Locale.FRANCE, Locale.CANADA_FRENCH, Locale.CHINESE, ... You will have to put the locale value in the second argument of the getBundle() method:
Team Working allow you synchronize your work with your fellows. NetBeans provide a built-in CVS client. We will connect to the NetBeans project cvs server.
Let's use the CVS client:
NetBeans will download all the source files. It will take a lot of time to ckeckout all the source files, but you can cancel, because it was only a test.
Most of web softwares are working with database, allowing you to save informations. NetBeans has a built-in tool to connect with a database.
We will test this part with MySql. First, you will have to download the drivers on this web-site:
You can select data, create tables, create views (but this functionality still doesn't exit in MySQL).
There is a graphical editor which will help you to write your comments on java classes. To use it, you have to perform a right click on a java class, in the "project" or "file" tab, and select Tools -> Auto-comment ...
An interface will show you all the commentables methods, classes, ... it's very easy and more attrative than writing them by hand.