NetBeans IDE Tutorial
1. About Netbeans IDE
Netbeans IDE, started as a student project known as Xelfi in the past, is a popular IDE developed with the goal to create a Delphi like IDE for Java. First developed in 1996, it has grown into a full fledged IDE for Enterprise scaled software development. With its excellent integrated abilities like the connection manager, integrated Glassfish server and resource managers, Netbeans IDE makes development quite easy for novice developers. This article has been created with the goal to guide every developer on how to take the most out of Netbeans IDE and its features.
Table Of Contents
- 1. About Netbeans IDE
- 2. Installing Netbeans IDE
- 3. Understanding Netbeans IDE interface
- 4. Working with Netbeans IDE
- 4.1. Creating first project in Netbeans IDE
- 4.2 Build the first project
- 4.3 Execute and Debug the first project
- 4.4 Versioning in Netbeans IDE
- 4.5 Refactoring class names & variable names
- 4.6 Formatting code and organising imports
- 4.7 Enhancing Netbeans IDE with the power of plugins
- 4.8 Useful shortcuts
- 4.9 Netbeans IDE preferences
- 4.10 Managing Working sets
- 4.11 Configuring Database connections
- 4.12 Exceptional features
- 4.1. Creating first project in Netbeans IDE
- 5. Conclusion
2. Installing Netbeans IDE
2.1 Prerequisites
For the tutorial, we would be downloading Netbeans IDE for Java EE. This would require Java 8 pre-installed to prevent any roadblocks during the tutorial. The Java installation version could be verified by using the command java --version in the command prompt or terminal depending on your OS.
2.2 Download and Install Netbeans IDE
Netbeans IDE is available in various flavours shown below. For the purpose of this tutorial, we would proceed with the download of Java EE version of Netbeans IDE 8.2. The download list could be found here. It is available for all the popular operating systems and unlike other IDEs, there is also an OS independent version of Netbeans available for download. For now, we will proceed with the download of OS specific version.
Once downloaded, the installation process is quite straightforward. Simply run the setup and follow the installation process. Once installed, start the IDE. It might take a while to load all the modules. Once loaded, you should be welcomed by this screen if everything went perfect with the installation.
Let us now get started with learning about using the Netbeans IDE.
3. Understanding Netbeans IDE interface
Netbeans IDE has an extremely minimalistic design when compared to the likes of it. The toolbar initially contains limited number of buttons. Their use has been described below.
- File operations buttons: The first group of buttons marked in Red indicate the buttons for file operations. The first button is used to create new files. The second button is dedicated to creation of new project. The third button is used to open up a file or a project as the need be. The fourth button is used to save all the changes files as and when required.
- Actions Undo-Redo buttons: The buttons are utilised to undo or redo the changes while developing the code.
- Build, Run and Debug controls: These controls are used when a project requires to be built or executed. The first button in the group marked blue is used for building the project. A build process involves complete process of compilation, linking and bytecode or executable file creation. The second button is a Clean & Build button. It clears the files generated from previous build and recreates all the compiled versions of files. The next button is used to execute a project with the default configuration while the button beside it allows you to debug when necessary. The last button is a profiling execution button. It allows to execute the project in a profiling mode.
In addition to toolbar, you could see three tabs in the left panel – Projects, Files & Services. Of these, currently only Services tab contains a few objects depending on your version and flavour of IDE. Netbeans provides with numerous really useful features like these services.
The services tab holds a list of Databases, sample RESTful services, Servers, Repositories, Test drivers and others. These services allow you to get an interface to test these components and interact with them right away. We will be looking at these as we proceed.
4. Working with Netbeans IDE
4.1 Creating first project in Netbeans IDE
Let us start with the creation of first project. To start with the first project, either navigate to File -> New Project or simply press the New Project button as described above. It should open up a small window as shown below.
For the tutorial purpose, we will proceed with Java Application. Select Java application in the right side panel and click Next. The next step asks for the selection of project name, location and folder. Select the necessary details and click next. The below image shows these details filled in.
On click of Finish, you should be able to see that your main class is automatically created. The project shows up in the Projects window and the MainClass shows up in the editor. A snapshot of how it appears is shown below.
Edit the MainClass as shown below to start understanding the basic control to run our first program.
MainClass.java
package com.javacodegeeks;
/**
*
* @author abhishekkothari
*/
public class MainClass {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.out.println("Hello there! Welcome to Java Code Geeks")
}
}
Now click the save button or Navigate to File -> Save to save the file. We have intentionally missed out a semicolon in the above code. When you paste the code in your editor, you would see a red line below the System.out.println("Hello there! Welcome to Java Code Geeks") statement. The red line indicates an error in the statement. Netbeans automatically builds the code in the backend to identify any potential compilation issues in advance. To know more about the error, simply hover over the red mark on the left side of the editor. It will show a tooltip like the one shown below to help you understand the error.
With the tooltip, Netbeans also provides hints. Simply press Alt+Enter. It will take you to the end of the line and suggest what needs to be done. In this manner, Netbeans plays the role of an IDE by dynamically helping you solve the problems. Place a semicolon at the end of the line with error.
4.2 Build the first project
Once the code is ready, the next step is to build and execute the project. In the top bar, you would be able to see two buttons to build the project. The buttons are Build and Clean & Build respectively. To explain the purpose of both the buttons, one needs to have a basic understanding of what happens when a project is built.
In case of Java, on building the project, it compiles the Java files into Class files. These files are placed inside a folder named bin in the corresponding project folder. The Clean & Build button clears these class files and recompiles the complete project code again while the Build button, simply compile the files that are necessary. The project can also be built using the shortcuts for these buttons.
Build: F11
Clean & Build: Shift+F11
These tasks can also be executed by navigating to the Run->Build Project & Run->Clean Build Project menu items respectively. Another possible way is to right click the project and select the relevant option.
4.3 Execute and Debug the first project
Once the project is built successfully, the code would be ready to execute. To execute the project, there are numerous ways. The simplest way is the shortcut key F6. It runs the code with its default configurations. Another possible way out is to use the green play button to execute the code. On executing the code, it should display the output as shown below.
This is how you could run any simple Java project in Netbeans IDE. Let us further modify the code to include a little more lines.
MainClass.java
package com.javacodegeeks;
import java.util.Scanner;
/**
*
* @author abhishekkothari
*/
public class MainClass {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String name = in.next();
sayHello(name);
}
private static void sayHello(String name){
System.out.println("Hello "+name);
}
}
Now, we will understand the process of debugging. Debugging is to execute the code step by step to analyse possible causes of error. In order to debug the code from a specific line, we need to add a breakpoint. To add a breakpoint, simple click on the line number on the left side of the editor as shown below.











It would have been beneficial to show how to build a Maven project in NetBeans. The process is slightly different when selecting the type of project to create, and at least initially a user has to enter a groupId and artifactId.