Presentation of NetBeans 4.0

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:

  • For standard application (for command line softwares, graphical interfaces,...)
  • For web sites. The 4.1 version will provide templates for J2EE, like EJB and web-services
  • A "sample" item menu, which contain code examples
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:

  • java files, with lexical and syntaxes colorization, auto-completion and mistake correction
  • xml, with syntax's colorization, an dtd and xsl generator, and a validator.
  • html and css, with syntax colorization.

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 :

  • build contains the class files.
  • dist contains final files of your project. There is a jar of your application, and the javadoc.
  • nbproject contains the ant configuration files, which determine how to compile, execute, deploy... a project.
  • src contains project's sources
  • test contains project's test files (we will see the Junit later)
  • other files : build.xml used to compile (this is a ant file) and manifest.mf to define the project
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:

  • You have got to put breakpoints in your code by doing a right click on your source code -> toggle Breakpoint
  • Select in the menu Run -> Debug , the project will compile automatically and will by launched.
  • Your program will pause on the first breakpoint encountered. The run menu offer you a lot of functionalities like: Run -> Step Over, Run -> Run to Cursor, ...

The windows in Window -> Debug will give you a lot of informations about variables, threads, ...

  • In the next screen-shoot, you'll can see three important things :
  • Breakpoints, which are colored in red
  • The green line, which show you were your software is stopped
  • Below, we can see the objects actually used
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:

  • Set the cursor on a class, in the "Project" tab.
  • Right click ---> Tools ---> Junit Tests ---> Create Test ... and validate the window which is shown with default options.
  • A class in the "Test Packages" will be created. This one extends a TestCase, this Junit framework's class allow you to create tests.

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:

  • System.out.println();
and set the cursor between the quotes. Go and select in the menu :
  • Tools ---> Internationalization ---> Insert Internationalized String ...
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:

  • System.out.println(java.util.ResourceBundle.getBundle("supinfo/labo/sun/i18n").getString("key_name"));
We will insert a new value
  • In the " Project " tab, select the bundle file, perform a right click ---> Add Locale ... then, select 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:

  • Versioning ---> Versioning Manager ...
  • Click on Add, to add a new working directory
  • Enter this informations:
    • Working Directory : the directory in your operating system where sources have to be sent.
    • CVS Server Type: pserver
    • CVS server name: cvs.netbeans.org
    • Port: 2401
    • Username: anoncvs
    • Repository: /cvs
CVS

  • "Perform Checkout" have to be checked
  • Click on "Next" at the bottom of the window, and, finally, finish.

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/

  • Select the "RunTime" tab, and the sub-menu "DataBase"
  • Perform a right-click on Drivers, Add drivers ... and select the MySQL driver (it is a jar file).
  • Select your driver in the Driver sub-directory, and create a connection by a right-click ---> Connect Using ... For this test, We did enter the following informations:
    • Database Url : jdbc:mysql://localhost:3306/mysql (where localhost is our local machine, where the mysql daemon is running).
    • Username et Password : ... it is yours ... !

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.

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo