You are on page 1of 39

Object-Oriented Software Development

NetBeans IDE 8.1

NetBeans IDE 8.1 provides out-of-the-box code analyzers and editors for working with the latest Java 8 technologies--Java SE 8, Java SE
Embedded 8, and Java ME Embedded 8. The IDE also has a range of new tools for HTML5/JavaScript, in particular for Node.js,
KnockoutJS, and AngularJS; enhancements that further improve its support for Maven and Java EE with PrimeFaces; and improvements
to PHP and C/C++ support.
NetBeans IDE 8.1 is available in English, Brazilian Portuguese, Japanese, Russian, and Simplified Chinese.

Required Software
The Java SE Development Kit (JDK) 7 Update 10 (or later) or JDK 8 is required to install NetBeans IDE. You can download the latest
update of JDK 7 and JDK 8 at http://www.oracle.com/technetwork/java/javase/downloads.
The PHP and C/C++ NetBeans bundles only require the Java Runtime Environment (JRE) 7 or 8 to be installed and run. JDK 7 or 8 is
required if you are planning to use any of the Java features.
JDK 7 Update 6 (or newer) is required to use JavaFX 2.2 (or newer) features in NetBeans IDE 8.1.
JDK 8 is required to use JavaFX 8 features in NetBeans IDE 8.1.

Note:
JavaFX 2.2 is bundled with the latest JDK 7 for Windows, Mac and Linux.

JavaFX 8 is bundled with JDK 8 for Windows, Mac and Linux.

Unlike previous versions of NetBeans IDE, NetBeans IDE 8.1 does not require that you set up an "FX-enabled" Java platform in order
to utilize JavaFX support in the IDE. You can develop JavaFX projects in the IDE if you install any standard Java platform that is JDK 7
Update 6 (or newer) or JDK 8.

To use JavaFX features in the NetBeans IDE, we strongly recommend upgrading your JDK version to JDK 7 Update 10 or newer.

Installer Download Options


On the NetBeans IDE Download page, you can obtain one of several installers, each of which contains the base IDE and additional tools.
The following installers are available:

Java EE. Provides tools for developing Java SE and Java EE applications as well as support for NetBeans Platform development
and JavaFX 2.2 SDK (or newer) or JavaFX 8 SDK. This download option also includes GlassFish Server Open Source Edition
4.1.1, and Apache Tomcat 8.0.27 software. This will be the version we will be utilizing for this course and is recommended for you
to download and install.

Customizing Your Installation


If you download the All download option, you can choose exactly what tools and runtimes to install. Click Customize at the Welcome page
of the installer and select the features that you want to use.
If you want to add functionality to your NetBeans IDE configuration, use the NetBeans Plugin Manager. For example, assume that you
start out by downloading and installing the PHP pack. You then decide that you want to try out the C/C++ functionality. To do this, go to
the NetBeans Plugin Manager from the IDE (choose Tools > Plugins) and add the C/C++ pack to your existing installation.
There are several important notes about installation and configuration of some NetBeans IDE features:
GlassFish Server Open Source Edition 4.1.1 is included in the Java EE and All download options but it is not installed by default
from either of these options. To install GlassFish Server Open Source Edition 4.1.1, select the appropriate option below:

from the Java EE download, launch the installer and select the GlassFish Server Open Source Edition 4.1.1 checkbox at the
Welcome page;

from the All download, launch the installer and select GlassFish Server Open Source Edition 4.1.1 in the Customize Installation
dialog box.

You should change the default administrator password after you install the GlassFish server, refer to FaqSettingGlassFishPassword for
details.
Apache Tomcat 8.0.27 is included in the Java EE and All download options but it is not installed by default from either of these
options. To install Apache Tomcat, select the appropriate option below:

from the Java EE download, launch the installer and select the Apache Tomcat 8.0.27 checkbox at the Welcome page;

from the All download, launch the installer and select Apache Tomcat 8.0.27 in the Customize Installation dialog box.

For OS X, you can customize the NetBeans IDE installation from the All and Java EE downloads. The IDE installation from Java
SE, C/C++, and PHP downloads cannot be customized.

You can also download a platform-independent zip file and run the NetBeans IDE executable file. Note that the GlassFish Server
Open Source Edition and Apache Tomcat are only available with platform-specific installers.

To make sample project templates unreachable in the NetBeans IDE installation, see the Hide Sample Projects FAQ page.

Starting the Download


1. Go to https://netbeans.org/downloads/.
2. In the upper right area of the page, select the language and platform from the drop-down list. You can also choose to download
and use the platform-independent zip file.
3. Click the Download button for the download option that you want to install.
4. Save the installer file to your system.

1. Save the installer file to your system. Remember where you saved it and what you called it. (It will most likely be a zip file).
Note this is a fairly big file and may take a while to download.

Installing the Software


Follow the instructions in this section to install the IDE on your system. These installation instructions apply to all supported platforms. For
the list of supported platforms and system requirements, see the release notes.

Microsoft Windows, Solaris OS, and Linux


To install the software:
1. After the download completes, run the installer.

For Windows, the installer executable file has the .exe extension. Double-click the installer file to run it. In the Chrome
Browser window it appears at the very bottom of the browser page.

If you downloaded the All or Java EE bundle, you can customize your installation. Perform the following steps at the Welcome
page of the installation wizard:
o

Click Customize.

In the Customize Installation dialog box, make your selections.

Click OK.

4. At the Welcome page of the installation wizard, click Next.


5. Uncheck and Dont install the GlassFish Server Open Source Edition 4.0. Please DO check the Apache Tomcat when the
installation page opens. We will also practice installing this manually should you ever need to do it on a server, for example.

6. At the License agreement page, review the license agreement, click the acceptance check box, and click Next.

7. At the NetBeans IDE installation page, do the following:


o

Accept the default installation directory for the NetBeans IDE or specify another directory.

Note: The installation directory must be empty and the user profile you are using to run the installer must have read/write
permissions for this directory.
Accept the default JDK installation to use with the NetBeans IDE or select a different installation from the drop-down list. If
the installation wizard did not find a compatible JDK installation to use with the NetBeans IDE, your JDK is not installed in
the default location. In this case, specify the path to an installed JDK and click Next, or cancel the current installation. After
installing the required JDK version you can restart the installation.
Note: If the JDK version is older than the recommended JDK 7 Update 10, download and install the latest JDK update
from Java SE Downloads page and restart the NetBeans IDE installer. You can run the NetBeans IDE on JDK 6 as an
alternative.

8. At the Summary page, do the following:


o

Verify that the list of components to be installed is correct.

Select the Check for Updates check box if you want to check the Update Center for possible updates and have the JUnit
library installed during the installation (provided you accepted the license in step 5.)

Verify that you have adequate space on your system for the installation.

9. Click Install to begin the installation.

10. At the Setup Complete page, provide anonymous usage data if desired, and click Finish.

Note: If you encounter problems successfully completing the software installation, see Troubleshooting for descriptions and suggested
workarounds for unresolved issues that could affect the installation process.

OS X
To install the software:
1. After the download completes, run the installer. The installer file has the .dmg extension.
2. On the panel that opens double-click the package icon. The package has the .mpkg extension. The installation wizard starts.
3. Click Continue when the "This package will run a program to determine if the software can be installed." dialog box is displayed.
4. At the Introduction page of the installation wizard, click Continue.
Note: If the JDK version is older than the recommended JDK 7 Update 10, download and install the latest JDK update from Java
SE Downloads page and restart the NetBeans IDE installer. You can run the NetBeans IDE on JDK 6 as an alternative.
5. Review the license agreement and click Continue. Click Accept in the pop-up window to accept the license.
6. At the Select a Destination page, select the drive and click Continue.
7. If you downloaded the All or Java EE bundle, you can customize your installation. On the last installation wizard panel, press the
Customize button in the bottom left-hand side of the panel. The tree of products is displayed.
8. Select the products you want to install.
9. Enter the administrator's name and password for your system and click OK to begin the installation.

Platform-Independent Package
To run the software:
1. After the download of the platform-independent ZIP file completes, extract it to any folder on your system.
2. Run the executable file located in the netbeans/bin directory.
3. Accept the License Agreement.
4. At the JUnit License Agreement page, decide if you want to install JUnit and click the appropriate option, click Next. The NetBeans
IDE installation starts.
Note: If a compatible JDK installation cannot be found, you might need to manually add a path to the JDK installation directory by doing
the following:
1. Open the netbeans.conf file located in the netbeans/etc directory in a text editor.
1. Enter the location of a compatible JDK installation for the netbeans_jdkhome option. The default location in Windows is C:\Program
Files\Java\jdk1.7.0_10 or similar.
2. Save the netbeans.conf file and run the executable file in the netbeans/bin directory.

Troubleshooting
About the Installer Working Directory
The installer stores data about installation sessions in the installer working directory. Examples of this data are the list of components
installed on your system, installation log messages, and registry data.
The default location for the installer working directory is %USERPROFILE%\.nbi on Windows and ~/.nbi on other platforms. The log
subdirectory contains the installation log files.

Cleaning Up After Incomplete Installations


After incomplete or unsuccessful installations, you might need to clean up your system from previous installations.
For Microsoft Windows, Solaris OS, and Linux:
1. Delete the installer working directory.
2. Delete the installation directories of the IDE and the GlassFish application server.
3. On the Windows platform, delete all nbi* registry entries from the following registry
keys:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\UninstallHKEY_CURRENT_USER\SOFTWARE\
Microsoft\Windows\CurrentVersion\Uninstall

Creating/Using/Running a Project in Netbeans


Before starting Netbeans, create a directory (folder) in which you plan to store your Java files & other project-related files. It is a good
idea to do this for each project (i.e., program) you work on.

Example:
MyProjectDir folder on the C: drive:

C:/MyProjectDir

Alternatively, you can create a project folder anywhere you want on your system.

Creating/Using/Running a Project in NetBeans


To start NetBeans, either double-click the desktop icon (if one was created)
or select:
Start -> All Apps -> NetBeans -> NetBeans IDE 8.1.
from the Start menu as shown below in the screenshot.

You might have to answer a few questions on file associations and then close a few features dialog windows the first time you run
NetBeans.

Creating/Using/Running a Project in NetBeans


You should first select File -> Close Projects if any previous or default projects are open. More than likely nothing will be open and
you will select the My NetBeans Tab to verify no recent projects have been open yet.

You will then see the following:

Creating/Using/Running a Project in NetBeans


Now Select File -> New Project to create a new NewBeans project.

Creating/Using/Running a Project in NetBeans


The Project Wizard - Step 1 of 3 window will now open. In this window you set some environment path values for your project. The next
image shows an example of what the completed window should look like. Select Java and Java Application as shown below and then
click Next.

Creating/Using/Running a Project in NetBeans

In the next window you set some environment path values for your project. The next image shows an example of what the completed
window should look like.
In the Name section, enter a Name for the project file like: MyProject
In the Directory section, click the button and select the directory in which you want to store your project. This should be the
directory you created in step 1.
Do not check the Create Main Class option box. We will manually create our own main class file later.

Creating/Using/Running a Project in NetBeans


Your NetBeans will now look like the following:

Creating/Using/Running a Project in NetBeans


Before you create your first class, you must first create the package it belongs in.
Lets create a class called Person in a package named mycourse.domain. To do this, right-click on the Project Source entry diagram
in the Project frame (shown below), and select New and then Package.

Creating/Using/Running a Project in NetBeans


Enter the full package name mycourse.domain in the resulting pop-up window, and click Finish.

Creating/Using/Running a Project in NetBeans


Your NetBeans will now look like the following:

Creating/Using/Running a Project in NetBeans


Now you are ready to create your Person class.
Right-click on domain in the package-tree diagram in the Project frame and select New and then Class.

Creating/Using/Running a Project in NetBeans


Enter the class name Person in the resulting pop-up window, and click Finish.

Creating/Using/Running a Project in NetBeans


Your NetBeans should now look something like this:

Creating/Using/Running a Project in NetBeans


If the results of the compilation are successful, you should see the NetBeans window shown below:

Creating/Using/Running a Project in NetBeans


If there are errors in your java code, these errors are displayed right in the editor window, and will also be detailed in a newly displayed
lower compilation messages frame.

Creating/Using/Running a Project in NetBeans


Fix any errors you may find and recompile. This is the basic process you will go through when you create new classes for your course
project. All errors will need to be resolved before the compilation process occurs.

Miscellaneous Points
Class/Package and File/Directory Relationships
Note that your java files will be saved under the directory you specified when you first created your project (C:/MyProjectDir in this
example). Generally, our package names correspond to directory names under your initial directory location.
Example:
Your class Person in package mycourse.domain is located in a file called Person.java in directory:
C:/MyProjectDir/mycourse/domain/Person.java

Creating/Using/Running a Project in NetBeans


Once you are done (or think you are done) with your class, right-click on the class in the package-tree diagram in the Project frame and
select Build to compile this class.

Creating/Using/Running a Project in NetBeans


Now well add a driver class called ProjMain (in the mycourse package) to the project.
Right-click on mycourse in the package-tree diagram in the Project frame and select New and then Java Class.
Enter the class name ProjMain in the resulting pop-up window, and click Ok.

Creating/Using/Running a Project in NetBeans

Creating/Using/Running a Project in NetBeans


Once you have successfully compiled the classes in your project, you are ready to run it. Select the Run menu (from the top menu bar),
then Run Project (Or click the green arrow icon on the toolbar) to run the project.
If this is the first time you are running the project, the Runtime Configurations window will be displayed. You must create a Runtime
Configuration so NetBeans knows how to run your project.

Creating/Using/Running a Project in NetBeans


Click the button next to the Main class text entry box of the Edit Runtime Configuration window. This opens the Select Main
Class For Project window
In the Search tab, enter ProjMain (the name of our class that has our main driver in it Proj), and click Ok.
Next (still in the New Runtime Configuration window) enter -ea in the VM parameters text entry box.
Finally, click Ok on the Runtime Configurations window, then click Ok in the Project Properties window.

Creating/Using/Running a Project in NetBeans


Finally - NetBeans regularly saves your work. If the Save icons in the NetBeans tool bar are grayed out, then NetBeans has already
saved the project and your Java files and there is nothing left unsaved. If these are not grayed out, clicking them will force NetBeans to
immediately save your file.

You might also like