NetBeans Installation and Basic Usage

This document is primarily intended for CSC142 Students who want to use an installation on their own computer such as a laptop or desktop at home.

JDK Installation

You need an installation of JDK (Java Development Kit) on your computer. JDK offers expanded development features compared to the JRE (Java Runtime Environment) which is probably already installed on your computer.

The JDK installation file can be obtained from the Oracle website with home and download pages:
http://www.oracle.com/technetwork/java/javase
http://www.oracle.com/technetwork/java/javase/downloads
Download a recent version. At the time of writing JDK is available readily for Java version 1.8. For definiteness, I'll assume this JDK version:
jdk-8u144
For Windows, download the file (assuming a 64-bit machine):
jdk-8u144-windows-x64.exe
Install by activating the .exe file and following instructions.

For MAC OSX, download the file
jdk-8u144-macosx-x64.dmg
Open the .dmg installation file and activate the .pkg file within to start the installation.

Netbeans Installation

NetBeans is Oracle's community-based Integrated Development Environment (IDE) for a variety of software development interests including Java, Php, C/C++, etc. It requires a JDK installation. The home and download pages are these:
http://netbeans.org
http://netbeans.org/downloads/
The download site offers a bewildering array of version choices which are differentiated by a "download-type" term embedded in the file name. I generally prefer the minimalistic version since you are easily able to augment the features through Netbean's plugin facility. The download I prefer is:
Windows: netbeans-8.2-javase-windows.exe
MAC OSX: netbeans-8.2-javase-macosx.dmg
Install by activating the appropriate file. A NetBeans shortcut is created on the Desktop. If there is more than one JDK installation on your system, the NetBeans installer will usually pick up the latest one.

Hello World Program

To create a simple "Hello World" program, start up NetBeans and follow the steps below.
  1. Select File ⇾ New Project
  2. In the New Project window, select the Java category, and choose Java Application, then Next.
  3. Next is the Name and Location dialog. Set the:
    Project Name:    Hello
    
    You can stop there if you want, just observe the two other important settings which indicate exactly where and what is the project folder:
    Project Location:
    Project Folder:
    
    NetBeans also pre-checks the box Create Main Class. You can uncheck it or leave it alone.

    Click Finish.
  4. If Create Main class was checked, otherwise skip.
    After creation you should be focused on the Projects window. If you kept the auto-created Main class, it will be displayed. For this course, you will only ever need this Projects window, and so you can close the others (you can always get them back from the Window menu).

    If you fully expand the Hello project (assuming you've kept the auto-created Main class), you'll see this structure:
    Hello
      Source Packages (or src)
        hello
          Hello.java
    

    For CSC142, we do not want to use the hello package, so right-click on hello, select Delete and complete with OK.
  5. You should now have the following display in Projects:
    Hello
      Source Packages (or src)
    

  6. Right-click on default package and select:
    New ( ⇾ Other ⇾ Java ) ⇾ Java Main Class
    After you select Java Main Class once, it appears directly from New. Set the class name:
    Class Name:    HelloWorld
    
    Click Finish.
  7. Go to the Files view and observe the structure which NetBeans creates. The src folder is meant to hold all the source packages. The HelloWorld.java file is in a package directory HelloWorld within the src folder.

  8. Within the public static void main function, remove the TODO line by:
    System.out.println("Hello World");
    The expedient is to type: sout[TAB] to have Netbeans expand the statement for you.
  9. Select File → Save (or Ctrl-S) to save. In Netbeans, saving is compiling.
  10. There are several ways to run this application. One way is to right-click on HelloWorld.java and select Run File from the popup menu. Look for the output in the Output window at the bottom.

NetBeans Projects on a flash drive

You can maintain one or more NetBeans projects on a flash drive, carry them around with you and work on them at different locations in which NetBeans is installed.

Let's assume we're doing this on a Windows system for definiteness. Assume you've created a sample NetBeans project in the "usual" place, which would be in the Documents folder, more precisely:
C:\Users\LOGIN\Documents\NetBeansProjects
Let's use project Hello created in the first section. It is represented by the folder:
C:\Users\LOGIN\Documents\NetBeansProjects\Hello
Insert your flash drive and open a folder which accesses the flash drive.

Drag the Hello into the flash drive folder.

Open the project on the flash drive

From NetBeans, select, right-click on the Projects Window and choose Open Project. Navigate to the flash drive and select Hello which was copied onto the flash drive folder.

You now have 2 Hello projects open! So it is best to close the first one. Right click on the first one and select Close from the Menu.

How do I know which one is which?

A very useful thing to know about is a Project's properties. To get this, again right-click on the project and select Properties from the menu (the last choice). Immediately you can tell which is which by the information in the Project Folder found at the top of the information dialog.


© Robert M. Kline