This exercise describes how to install and use
NetBeans
on your desktop or laptop computer.
NetBeans is an
integrated development environment
(IDE) for editing, compiling, and running Java programs. It
supports many other programming languages, and we will also use
it to develop Javascript/HTML programs.
Note that NetBeans is not intended to run on smart phones,
tablet computers or Chromebooks.
We will use NetBeans version 8.2. There are more recent versions
of NetBeans, but they are not yet integrated well with JavaFX
(the Java graphical user interface framework) that we will use.
NetBeans is written in Java, so we must also install the Java
Development Kit (JDK). The only JDK that works well with
NetBeans 8.2 is JDK version 8 from Oracle Corporation.
Happily, Oracle provides both JDK 8 (more specifically, JDK
8u111) and NetBeans 8.2 in a download
"cobundle"
AVAILABLE HERE (opens in a new
window).
Download the cobundle for your system and follow the
INSTALLATION INSTRUCTIONS
(opens in a new window).
Upon completion, the NetBeans desktop launch icon will look like
this:
Upon launch, the IDE's start screen will look like this:
You will need to:
- Accept the license agreement for Java SE Development Kit 8u221
- Download the package appropriate for your platform
- Follow the provided
installation instructions (also rendered
below) that are given for different platforms
Go to this link (also rendered below):
https://netbeans.org/downloads/old/8.2/.
Then:
- Select your platform (Windows, Linux, or MacOS)
- Click Download under the column labeled "Java SE" under
"NetBeans IDE Download Bundles" and locate the download
bundle in the same folder in which you installed the JDK.
Upon download, follow the installation instructions given here (also
rendered below):
https://netbeans.org/community/releases/82/install.html.
Note:
- The installer will locate your JDK installation and display it
before installation. Be sure that JDK 8 is selected.
-
Upon completion, the NetBeans desktop launch icon will look like
this:
You can also launch NetBeans from the command line by running the
executable appropriate for your platform located in the bin
folder in your NetBeans installation folder.
Upon launch, the IDE's start screen will look like this:
NetBeans is developed and maintained by the
Apache Software Foundation.
To install it, go to the
Apache NetBeans
Project and click
Download.
Click the "
incubating-netbeans-10.0-bin.zip" link, which will
bring you to a page suggesting a mirror site for your download.
Click the mirror site to download
incubating-netbeans-10.0-bin.zip to your machine, then unzip
(extract) the folder (called
netbeans) to a location of your
choosing.
Within the
netbeans folder is a subfolder called
bin that
contains these files:
- netbeans: a shell script for running under Linux and
MacOS
- netbeans64.exe and netbeans.exe: executable
binaries for Windows
Run the binary appropriate for your system. After launch, the IDE should
look like this:
In this step you will create, build, and run a NetBeans project using
the provided files
Console.java and
ConsoleTest.java.
Don't worry if you don't understand the code at this time.
The files required for this exercise are available from the menu on the
left.
First, start NetBeans on your machine. Upon launch, the IDE will
look as shown below. Then follow the menu to the left.
Click the
File menu and select
New Project...
In the
New Project dialog, under
Categories:
select
Java with Maven and
under
Projects: scroll down to select
Simple JavaFXMavenArchetype (Gluon).
Note the message about activating JavaFX
functionality. Click
Next to get the next dialog:
Click
Download and Activate... to get the Plugin
Installer:
Click
Next to launch the installer. Upon completion
click
Finish to return to the project creation process.
In the
New Simple JavaFX Maven Archetype dialog, name the
project
Console and choose an appropriate project location
on your machine. Use
console for the package name
and click
Finish.
After NetBeans takes a few moments to build your project,
you should see the
Console project under the
Projects
tab in the upper left of the IDE.
Click on the handle next to the project name
Console
to open the project tree. Then click the handle next to
Source
Packages followed by the handle next to the
console
package to reveal the project tree structure shown below.
We will ignore the
<default package>. Note
the
App.java class in the
console package. It has
a
main method that will launch a sample JavaFX window
when the project is run.
Click the handle next to the
Console project node to reveal
the
Source Packages and
Libraries sub-nodes.
By default, there is a source package with no name. We will create a
new package called
console.
Right click the
Source Packages node and
choose the
New ▸ Java Package... option.
In the
New Java Package dialog, name the
package
console and click
Finish.
You should now see the
console package under the
Source
Packages node.
In this step you will
update the default
App class in the
console
package.
Before doing so, you can actually run this class by clicking the
Run Project tool
in
the IDE's tool bar. This will produce the window below.
In this step you will rename the
App class and change its
contents to do something more interesting.
Right click the
console node and
choose the
New ▸ Java
Class... option
In the
New Java Class dialog, name the
class
Console and click
Finish.
You should see the
Console.java class under
the
console node:
You could actually run this class by right-clicking it and
choosing
Run File. You will get a simple GUI (graphical user
interface) version of a "Hello World" application.
However, we are going to replace the contents of
Console.java
with our own code. Double click the class to open it in the
source editor.
Double-click the
App.java file in the project tree.
You should see its default contents
under the
App.java tab in
the right side of the IDE. This is a full program and text editor
with cut-and-paste capabilities.
Right-click
App.java and select
Refactor >
Rename to
get a class rename dialog. Replace the name
App
with
Console and click
Refactor. The IDE should
now look as shown below.
Replace the default contents of
Console.java with this
provided
Console.java
file using your desktop environment's cut-and-paste capabilities.
Note the small wrench icon next to
Console.java. This indicates
that the file has not been compiled.
While compilation usually takes
place automatically when you run a project or file, you can also
compile files manually.
Click the
Files tab next to the
Projects tab in
the upper left of the IDE and open the files view.
Note the absence of a
build folder (not the same as
the
build.xml file).
Return to the
Projects tab, right click
the
Console.java node, and select
Compile File.
Note that the wrench icon disappears and a
build folder
has been added to the
Files tab.
Navigate through the
build folder and sub-folders to find
the
Console.class object file produced by the compiler.
To test the class we will use the JUnit framework included with
NetBeans.
Under the
Projects tab, right click
Console.java
and choose
Tools ▸
Create/Update Tests
In the
Create/Update Tests dialog, shown below, keep the name and
location defaults but uncheck all the code generation
options. Click
OK.
Note that the
Test Packages node has been added to
the
Projects tab, with package name
console and
class name
ConsoleTest.java
Note that a
Test Packages
node has been created in the project tree with a package
named
console and a class named
ConsoleTest.
Below the default contents of
the
ConsoleTest.java file appear on
the right side of the IDE.
Replace the default contents of
ConsoleTest.java with this
provided
ConsoleTest.java file.
Right-click
ConsoleTest.java in the project tree and
select
Test File.
A window with the title
Testing Console should appear
(see below). It
simulates a terminal console that takes single-line commands and
processes them when
Enter is pressed on the keyboard.
Click in the
Input area, type some text, and press
Enter. The input will be echoed in the upper part of the window
and the console will wait for and display more input until the application is
ended by clicking the ⨯ in the upper right corner.
Right click the
ConsoleTest.java node and choose
Run
File.
A window with the title
Testing Console should appear. It
simulates a terminal console that takes single-line commands and
processes them when
Enter is pressed on the keyboard.
Click in the
Input area, type some text, and press
Enter. The input will be echoed in the upper part of the window
and the console will wait for and display more input until the application is
ended by clicking the ⨯ in the upper right corner.
NetBeans provides a useful means of debugging Java programs by
allowing the stopping of program execution to inspect the
program's state, for example, the values of an object's instance
fields.
A
breakpoint is a program location at which you would like
program execution to pause so you can inspect its state.
When a class file is open in the NetBeans source editor, line numbers are
displayed (although they are not part of the program itself).
For example, line number 56 in
Console.java immediately follows
the assignment of the variable
input. To observe the value of
this variable while the program runs, set a breakpoint by clicking on
line number 56. The result is shown below.
To run a test with breakpoints observed, right click
the
ConsoleTest.java node and choose
Debug Test File.
To run a test with breakpoints observed, right click
the
ConsoleTest.java node and choose
Debug Test File.
The console will appear and wait for input, for example,
"Hello". When
Enter is pressed the
process method is
called and execution pauses at line 56.
Notice that a
Debugging tab is displayed in the upper
left of the IDE. Also, you can hover the mouse over variable
references in the program to observe their values. Below, the mouse
is passing over the declaration of the instance field "
input".
The tooltip shows the value of the field to be "Hello":
When the debugger is being run, a
Variables window appears
beneath the source editor, showing the names and values of all exposed
variables.
In the
Variables window below, the
this variable has been
opened to show the
input variable and its current value, "Hello".
When a program is being debugged, the programmer has a choice between
high-level controls and stepping controls when deciding how to proceed.
High-level debugging controls involve exiting or proceeding to
breakpoints.
The following high-level controls
(
Finish, Pause and
Continue) appear on the tool bar:
Stepping controls allow the program to pause, not based on breakpoints,
but on the program's structure in terms of source lines and expressions.
The following stepping controls
(
Step Over, Step Over Expression, Step Into and
Step Out)
appear on the tool bar:
- Step Over : Executes one
source line, including any
contained method calls (steps "over" a source line)
- Step Over Expression
: Executes one method
call in an
expression (steps "over" a method call, among possibly others, in
an expression)
- Step Into : Executes one
method call in a source line
(steps "into" a source line and executes a method call, among
possibly others on that line)
- Step Out : Executes one
source line and any remaining
lines if the source line is part of a method body (steps "out" of
a method body)
Besides inspecting variable values while debugging, you can change
their values to further observe program behavior.
Below on the left the value of
input has been manually changed
in the debugger to "World!". After continuing through the next
breakpoint the console looks like that on the right. Note that the new
value of
input is displayed though that value was not entered by
the program user.
When your console project is working correctly:
- Make sure your identifying information is in the class comments
of Console.java and ConsoleTest.java
- Use File > Export Project > To Zip... to zip (compress)
your Console folder as
Console.zip.
- Submit Console.zip by going to the module called
Lab 1: Installing and Using NetBeans in
Your project will be inspected and run by the lab instructor. Grading criteria:
- Successful creation of the Echo Console: 10 points