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:

General Presentation

Summary:

4.0 Splash Screen

Introduction:

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.

History:

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.

General Presentation:


Project manager:
Let's go in File -> New Project

New Project

NetBeans propose ready-to-use project templates:

Templates projects make your work easier, because NetBeans will configure automatically the software in your environment, like web ones (Tomcat, which we will see later).

We will go and create a project in Standard -> java application, called "NetBeans".

New Project

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 ...

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

Java Class

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.

Supported Files:

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:

Auto-Completion:

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:

Auto-Completition

The java documentation is by this way, integrated in NetBeans, as we have just saw it.

Auto-Correction:

By writing the following line :
StringBuffer sb = new StringBuffer("test",5);

NetBeans underscore it. The reason is there is no constructor available this two arguments, as NetBeans show it :

Auto Correct

The automatic correction is available even before compiling the file.

Refactoring:

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 ...

Refactoring

Click on "Next", you will see a briefing of all the actions which will be executed by NetBeans:

Refactoring

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.

File Organization:

We can see different files in different directories :

File Organization

Generate Documentation Files:

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.

Automatic Compilation:

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.

"Debug-time"

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, ...

Debug

Test Classes (JUnit Framework)

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:

This class contains a constructor, a function called setUp (utilised as tests initialiser), tearDown (utilised at all tests closing time), and finally, an infinite number of methods called testXXX where XXX is a test's name.

Here is an example, for a Junit class:
Debug

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 :
maintTest
setUp <--- at testHello() execution
hello
tearDown
setUp <--- at testHello2() execution
hello2
tearDown

We let you consult a good tutorial about Junit, at its official website: http://junit.sourceforge.net/doc/testinfected/testing.htm

Internalization:

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:

and set the cursor between the quotes. Go and select in the menu : Create a " bundle ", with a key, and related value. Press " OK " , and a reference to the key will be created.

Internationalization

NetBeans will insert a value in your line:

We will insert a new value

New references will be added below the i18n.properties file.

Internationalization

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:

    System.out.println(java.util.ResourceBundle.getBundle("supinfo/labo/sun/i18n",Locale.JAPAN).getString("key_name"));

Using CVS

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:

CVS

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.

Connecting With A Database

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:
http://dev.mysql.com/downloads/connector/j/

You can select data, create tables, create views (but this functionality still doesn't exit in MySQL).

Auto-comment:

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.