Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Java EE 7 Development with NetBeans 8
Java EE 7 Development with NetBeans 8

Java EE 7 Development with NetBeans 8: Develop professional enterprise Java EE applications quickly and easily with this popular IDE , Third Edition

eBook
$29.69 $32.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Java EE 7 Development with NetBeans 8

Chapter 1. Getting Started with NetBeans

In this chapter, we will learn how to get started with NetBeans. The following topics are covered in this chapter:

  • Introduction
  • Obtaining NetBeans
  • Installing NetBeans
  • Starting NetBeans for the first time
  • Configuring NetBeans for Java EE development
  • Deploying our first application
  • NetBeans tips for effective development

Introduction

NetBeans is an Integrated Development Environment (IDE) and platform. Although initially, the NetBeans IDE could only be used to develop Java applications, as of version 6, NetBeans supports several programming languages, either through built-in support, or by installing additional plugins. Programming languages natively supported by NetBeans include Java, C, C++, PHP, HTML, and JavaScript. Groovy, Scala, and others are supported via additional plugins.

In addition to being an IDE, NetBeans is also a platform. Developers can use NetBeans' APIs to create both NetBeans plugins and standalone applications.

Note

For a brief history of NetBeans, see http://netbeans.org/about/history.html.

Although the NetBeans IDE supports several programming languages, because of its roots as a Java only IDE it is more widely used and known within the Java community. As a Java IDE, NetBeans has built-in support for Java SE (Standard Edition) applications, which typically run on a user's desktop or notebook computer; Java ME (Micro Edition) applications, which typically run on small devices such as cell phones or PDAs; and for Java EE (Enterprise Edition) applications, which typically run on "big iron" servers and can support thousands of concurrent users.

In this book, we will be focusing on the Java EE development capabilities of NetBeans, and how to take advantage of NetBeans' features to help us develop Java EE applications more efficiently.

Some of the features we will cover include how NetBeans can help us speed up web application development using JavaServer Faces (JSF), the standard Java EE component based web framework by providing a starting point for these kinds of artifacts. We will also see how NetBeans can help us generate Java Persistence API (JPA) entities from an existing database schema (JPA is the standard object-relational mapping tool included with Java EE).

In addition to web development, we will see how NetBeans allows us to easily develop Enterprise JavaBeans (EJBs); and how to easily develop web services. We will also cover how to easily write both EJB and web service clients by taking advantage of some very nice NetBeans features.

Before taking advantage of all of the aforementioned NetBeans features, we of course need to have NetBeans installed, as covered in the next section.

Obtaining NetBeans

NetBeans can be obtained by downloading it from http://www.netbeans.org.

Obtaining NetBeans

To download NetBeans, we need to click on the Download button. Clicking on this button will take us to a page displaying all NetBeans' download bundles.

Obtaining NetBeans

NetBeans' downloads include different NetBeans bundles that provide different levels of functionality. The following table summarizes the different NetBeans bundles available and describes the functionalities they provide.

NetBeans Bundle

Description

Java SE

Allows development of Java desktop applications.

Java EE

Allows development of Java Standard Edition (typically desktop) applications, and Java Enterprise Edition applications (enterprise applications running on "big iron" servers).

C/C++

Allows development of applications written in the C or C++ languages.

HTML5 and PHP

Allows development of web applications using HTML5 and/or the popular open source PHP programming language.

All

Includes functionalities of all NetBeans bundles.

To follow the examples in this book, either the Java EE or the All bundle is needed.

Note

The screenshots in this book were taken with the Java EE bundle. NetBeans may look slightly different if the All bundle is used, particularly, some additional menu items might be seen.

The following platforms are officially supported by NetBeans:

  • Windows
  • Linux (x86/x64)
  • Mac OS X

Additionally, NetBeans can be executed on any platform containing Java 7 or newer version. To download a version of NetBeans to be executed in one of these platforms, an OS independent of NetBeans is available.

Note

Although the OS independent version of NetBeans can be executed in all the supported platforms, it is recommended to obtain the platform specific version of NetBeans for your platform.

The NetBeans download page should detect the operating system being used to access it, and the appropriate platform should be selected by default. If this is not the case, or if you are downloading NetBeans with the intention of installing it in another workstation on another platform, the correct platform can be selected from the drop down labeled appropriately enough as Platform.

Once the correct platform has been selected, we need to click on the appropriate Download button for the NetBeans bundle we wish to install; for Java EE development, we need either the Java EE, or the All bundle. NetBeans will then be downloaded to a directory of our choice.

Note

Java EE applications need to be deployed on an application server. Several application servers exist in the market; both the Java EE and the All NetBeans bundles come with GlassFish and Tomcat bundled. Tomcat is a popular open source servlet container, which can be used to deploy applications using JSF. However, it does not support other Java EE technologies such as EJBs or JPA. GlassFish is a 100 percent Java EE compliant application server. We will be using the bundled GlassFish application server to deploy and execute our examples.

Installing NetBeans

NetBeans requires a Java Development Kit (JDK) Version 1.7 or newer to be available before it can be installed.

Note

Since this book is aimed at experienced Java developers, we will not spend much time explaining how to install and configure the JDK. We can safely assume that the target market for the book is more than likely to have a JDK installed. Installation instructions for the Java Development Kit can be found at http://docs.oracle.com/javase/7/docs/webnotes/install/index.html.

NetBeans installation varies slightly between the supported platforms. In the following few sections we explain how to install NetBeans on each supported platform.

Microsoft Windows

For Microsoft Windows platforms, NetBeans is downloaded as an executable file named something like netbeans-8.0-javaee-windows.exe (exact name depends on the version of NetBeans and the NetBeans bundle that was selected for download). To install NetBeans on Windows platforms, simply navigate to the folder where NetBeans was downloaded and double-click on the executable file.

Mac OS X

For Mac OS X, the downloaded file is called something like netbeans-8.0-javaee-macosx.dmg (exact name depends on the NetBeans version and the NetBeans bundle that was selected for download). In order to install NetBeans, navigate to the location where the file was downloaded and double-click on it.

Linux

For Linux, NetBeans is downloaded in the form of a shell script. The name of the file will be similar to netbeans-8.0-javaee-linux.sh (exact name will depend on the version of NetBeans and the selected NetBeans bundle).

Before NetBeans can be installed on Linux, the downloaded file needs to be made executable, which can be done using a command line—by navigating to the directory where the NetBeans installer was downloaded and executing the following command:

chmod +x filename.sh

Substitute filename.sh in the preceding command with the appropriate filename for the platform and NetBeans bundle. Once the file is executable it can be installed from the command line as follows:

./filename.sh

Other platforms

For other platforms, NetBeans can be downloaded as a platform independent ZIP file. The name of the ZIP file will be something like netbeans-8.0-201403101706-javaee.zip (exact filename may vary, depending on the exact version of NetBeans downloaded and the NetBeans bundle that was selected).

To install NetBeans on one of these platforms, simply extract the ZIP file to any suitable directory.

Installation procedure

Even though the way to execute the installer varies slightly between platforms, the installer behaves in a similar way between most of them.

Note

One exception is the platform independent ZIP file, in which there is essentially no installer. Installing this version of NetBeans consists of extracting the ZIP file to any suitable directory.

After executing the NetBeans installation file for our platform, we should see a window similar to the one illustrated in the following screenshot.

Installation procedure

The pack shown may vary depending on the NetBeans bundle that was downloaded. The preceding screenshot is for the Java EE bundle.

At this point, we should click on the button labeled Next> to continue the installation.

Installation procedure

NetBeans is dual licensed, licenses for NetBeans include the GNU Public License (GPL) Version 2 with the classpath exception, and the Common Development and Distribution License (CDDL). Both of these licenses are approved by the Open Source Initiative (OSI).

To continue installing NetBeans, click on the checkbox labeled I accept the terms in the license agreement and click on the button labeled Next>.

Installation procedure

NetBeans comes bundled with JUnit, a popular Java unit testing framework. JUnit's license differs from the NetBeans license, so it needs to be accepted separately. Clicking the Next> button takes us to the next step in the installation wizard:

Installation procedure

At this point the installer will prompt us for a NetBeans installation directory, and for a JDK to use with NetBeans. We can either select new values for these or retain the provided defaults.

Once we have selected the appropriate installation directory and JDK, we need to click on the button labeled Next> to continue the installation.

Note

NetBeans uses the JAVA_HOME environment variable to populate the JDK's directory location.

Installation procedure

The installer will now prompt us for an installation directory for the GlassFish application server, as well as for the JDK to use for GlassFish; we can either enter a custom directory or accept the default values and then click on Next>.

Installation procedure

If we chose to install Tomcat, the installer will prompt us for a Tomcat installation directory. Again, we can either enter a custom directory or accept the default values and then click on Next>.

Installation procedure

At this point, the installer will display a summary of our choices. After reviewing the summary, we need to click on the button labeled Install to begin the installation.

Installation procedure

As the installation begins, the installer starts displaying a progress bar indicating the progress of installation.

Installation procedure

After NetBeans and all related components have been installed, the installer indicates a successful installation, giving us the option to contribute anonymous usage data as shown in the preceding screenshot. After making our selection we can simply click on the Finish button to exit the installer.

On most platforms, the installer places a NetBeans icon on the desktop; the icon should look like the following:

Installation procedure

We can start NetBeans by double-clicking on the icon.

Starting NetBeans for the first time

We can start NetBeans by double-clicking on its icon. We should see the NetBeans splash screen while it is starting up.

Starting NetBeans for the first time

Once NetBeans starts, we should see a page with links to demos, tutorials, and sample projects, among others.

Starting NetBeans for the first time

Every time NetBeans is launched, it shows the default start page as illustrated in the preceding screenshot. If we don't want this page to be displayed automatically every time NetBeans is started, we can disable this behavior by un-checking the checkbox labeled as Show on Startup at the top of the page. We can always get the start page back by going to Help | Start Page.

Configuring NetBeans for Java EE development

NetBeans comes preconfigured with the GlassFish application server, and with the JavaDB RDBMS. If we wish to use the included GlassFish application server and JavaDB RDBMS, then there is nothing we need to do to configure NetBeans. We can, however, integrate NetBeans with other Java EE application servers such as JBoss/WildFly, WebLogic, or WebSphere and with other relational database systems such as MySQL, PostgreSQL, Oracle, or any RDBMS supported by JDBC, which pretty much means any RDBMS.

Integrating NetBeans with a third-party application server

Integrating NetBeans with an application server is very simple. To do so, we need to perform the following steps:

Note

In this section, we will illustrate how to integrate NetBeans with JBoss, the procedure is very similar for other application servers or servlet containers.

  1. First, we need to click on Window | Services.
    Integrating NetBeans with a third-party application server
  2. Next, we need to right-click on the node labeled Servers in the tree inside the Services window, and then select Add Server... from the resulting pop-up menu.
    Integrating NetBeans with a third-party application server
  3. Then we need to select the server to install from the list in the resulting window, and click on the button labeled Next>.
    Integrating NetBeans with a third-party application server
  4. We then need to enter a location in the filesystem where the application server is installed and click Next>.
    Integrating NetBeans with a third-party application server
  5. Finally, we need to select a domain, host, and port for our application server, then click on the Finish button.
    Integrating NetBeans with a third-party application server

The Services window should now display our newly added application server:

Integrating NetBeans with a third-party application server

That's it! We have successfully integrated NetBeans with a third-party application server.

Integrating NetBeans with a third-party RDBMS

NetBeans comes with built-in integration with the JavaDB RDBMS system. Additionally, it comes with JDBC drivers for other RDBMS systems such as Oracle, MySQL, and PostgreSQL.

To integrate NetBeans with a third-party RDBMS, we need to tell NetBeans the location of its JDBC driver.

Note

In this section, we will create a connection to HSQLDB, an open source RDBMS written in Java, to illustrate how to integrate NetBeans with a third-party RDBMS; the procedure is very similar for other RDBMS systems such as Oracle, Sybase, SQL Server, among others.

Adding a JDBC driver to NetBeans

Before we can connect to a third-party RDBMS, we need to add its JDBC driver to NetBeans. To add the JDBC driver, we need to right-click on the Drivers node under the Databases node in the Services tab.

Adding a JDBC driver to NetBeans

We then need to select a JAR file containing the JDBC driver for our RDBMS, NetBeans guesses the name of the driver class containing the JDBC driver. If more than one driver class is found in the JAR file, the correct one can be selected from the drop-down menu labeled Driver Class. We need to click on the OK button to add the driver to NetBeans as shown in the following screenshot:

Adding a JDBC driver to NetBeans

Once we have followed the preceding procedure, our new JDBC driver is displayed in the list of registered drivers.

Adding a JDBC driver to NetBeans

Connecting to a third-party RDBMS

Once we have added the JDBC driver for our RDBMS into NetBeans, we are ready to connect to the third-party RDBMS.

To connect to our third-party RDBMS, we need to right-click on its driver under the Services tab, then click on Connect Using... on the resulting pop-up menu as shown in the following screenshot:

Connecting to a third-party RDBMS

Then we need to enter the JDBC URL, username, and password for our database.

Connecting to a third-party RDBMS

After clicking on the Next> button, NetBeans will ask us to select a database schema. In this case, we select PUBLIC from the drop-down menu.

Connecting to a third-party RDBMS

In the next step in the wizard, we are allowed to enter a user-friendly name for our database connection, or we can simply accept the default value.

Connecting to a third-party RDBMS

After clicking on the Finish button, our database is shown in the list of databases in the Services window. We can connect to it by right-clicking on it, selecting Connect from the resulting pop-up menu, then entering our username and password for the database (if we chose not to allow NetBeans to remember the password when we added the database).

Connecting to a third-party RDBMS

We have now successfully connected NetBeans to a third party RDBMS.

Deploying our first application

NetBeans comes pre-configured with a number of sample applications. To make sure everything is configured correctly, we will now deploy one of the sample applications to the integrated GlassFish application server that comes bundled with NetBeans.

To open the sample project, we need to go to File | New Project, then select Samples | Java EE from the Categories list in the resulting pop-up window. Once we have selected Java EE from the categories list, a list of projects is displayed in the Projects list; for this example we need to select the JavaServer Faces CDI project. This sample is a simple project involving both JSF and Contexts and Dependency Injection (CDI).

Deploying our first application

After clicking on the Next> button, we are prompted to enter a project location in the next pop-up window. In this case, the default value is sensible.

Deploying our first application

Once we click on the Finish button, our new project is displayed in the Projects window:

Deploying our first application

We can compile, package, and deploy our project at one go by right-clicking on it and selecting Run from the resulting pop-up menu.

Deploying our first application

At this point, we should see the output of the build script. Also, both the integrated GlassFish application server and the integrated JavaDB RDBMS system should automatically start.

Deploying our first application

As soon as our application is deployed, a new browser window or tab automatically starts, displaying the default page for our sample application.

Deploying our first application

If our browser is displaying a page similar to the preceding one shown, then we can be certain that NetBeans and GlassFish are working properly and we are ready to start developing our own Java EE applications.

NetBeans tips for effective development

NetBeans offers a wide array of features that make Java and Java EE development easier and faster. In the following few sections, we cover some of the most useful features.

Code completion

The NetBeans code editor includes a very good code completion feature, for example, if we wish to create a private variable, we don't need to type the whole private word, we can simply write the first three letters (pri), then hit Ctrl + Space and NetBeans will complete the word private for us.

Code completion also works for variable types and method return values, for example, if we want to declare a variable of type java.util.List, we simply need to type the first few characters of the type, then hit Ctrl + Space NetBeans will try to complete with variable types in any of the packages we have imported in our class. In order to make NetBeans attempt to complete with any type in the classpath, we need to hit Ctrl + Space again.

Code completion

As we can see in the preceding screenshot, NetBeans displays JavaDoc for the class we selected from the code completion options. Another time-saving feature is that the class we selected from the options is automatically imported into our code.

Once we have the type of our variable, we can hit Ctrl + Space right after the variable and NetBeans will suggest variable names.

Code completion

When we want to initialize our variable to a new value, we can simply hit Ctrl + Space again and a list of valid types is shown as options for code completions as demonstrated in the following screenshot:

Code completion

In our example, our type (java.util.List) is an interface, therefore, all classes implementing this interface are shown as possible candidates for code completion. Had our type been a class, both our class and all of its subclasses would have been shown as code completion candidates.

When we are ready to use our variable, we can simply type the first few characters of the variable name, then hit Ctrl + Space.

Code completion

When we wish to invoke a method in our object, we simply type a period at the end of the variable name, and all available methods are displayed as code completion options.

Code completion

Notice how the JavaDoc for the selected method is automatically displayed.

Code templates

Code templates are abbreviations for frequently used code snippets. To use a code template, we simply type it into the editor and hit the Tab key to expand the abbreviations into the full code snippet it represents.

For example, typing sout and pressing the Tab key will expand into System.out.println("");, with the caret placed between the two double quotes.

Some of the most useful code templates are listed in the following table, please note that code templates are case sensitive.

Abbreviation

Example expanded text

Description

Psf

public static final

Useful when declaring public, static, and final variables.

fore

for (Object object : list) {

}

Use the enhanced for loop to iterate through a collection.

ifelse

if (boolVar) {

} else {
}

Generate an if-else conditional statement.

psvm

public static void main(String[] args) {

}

Generate a main method for our class.

soutv

System.out.println("boolVar = " +
        boolVar);

Generate a System.out.println() statement displaying the value of a variable.

trycatch

try {

} catch (Exception exception) {
}

Generate a try-catch block.

whileit

while (iterator.hasNext()) {
       Object object = iterator.next();

 }

Generate a while loop to iterate through an iterator.

To see the complete list of code templates, click on Tools | Options, click on the Editor icon, then on the Code Templates tab.

Code templates

We can add our own templates by clicking on the New button. We will be prompted for the template's abbreviation. Once we enter it, our new template will be added to the template list and will automatically be selected. We can then enter the expanded text for our template in the Expanded Text tab.

Code templates can be used not only for Java but for HTML, CSS, and all other editors in NetBeans. To view/edit templates for other languages, simply select the desired language from the Language drop-down menu under the Code Templates tab as indicated in the following screenshot:

Code templates

Keyboard shortcuts

NetBeans offers several keyboard shortcuts that allow very fast navigation between source files. Memorizing these keyboard shortcuts allows us to develop code a lot more effectively than relying on the mouse.

Note

Some of the most useful NetBeans' keyboard shortcuts are listed in this section, but this list is by no means exhaustive. The complete list of NetBeans' keyboard shortcuts can be obtained by clicking on Help | Keyboard Shortcuts Card.

One useful keyboard shortcut that allows us to quickly navigate within a large Java file is Ctrl + F12. This keyboard shortcut switches focus to the Navigator window, which displays an outline of the current Java file and shows all its methods and member variables.

Keyboard shortcuts

When the Navigator window has focus, we can simply start typing to narrow down the list of member variables and methods shown. This keyboard shortcut makes it very fast to navigate through large files.

Hitting Alt + F12 will open the Hierarchy window, which outlines the class hierarchy of the current Java class.

Keyboard shortcuts

We can use the previous shortcut to quickly navigate to a superclass or a subclass of the current class.

Another useful keyboard shortcut is Alt + Insert. This keyboard shortcut can be used to generate frequently used code such as that for constructors, getter and setter methods, among others.

Keyboard shortcuts

The code will be generated at the current location of the caret.

Additionally, when the caret is right next to an opening or closing brace, hitting Ctrl + [ results in the caret being placed in the matching brace. This shortcut works for curly braces, parenthesis, and square brackets. Hitting Ctrl + Shift + [ has a similar effect, but this key combination not only places the caret in the matching brace, it also selects the code between the two carets:

Keyboard shortcuts

Sometimes, we would like to know all the places in our project where a specific method is invoked. Hitting Alt + F7 while the method is highlighted allows us to easily find out this information.

Keyboard shortcuts

The keyboard shortcuts works with variables as well.

NetBeans will indicate compilation errors in our code by underlining the erroneous line with a squiggly red line as shown in the following screenshot. Placing the caret over the offending code and hitting Alt + Enter will allow us to select from a series of suggestions to fix our code:

Keyboard shortcuts

Sometimes navigating through all the files in a project can be a bit cumbersome, especially if we know the name of the file we want to open but we are not sure of its location. Luckily, NetBeans provides the Shift + Alt + O keyboard shortcut that allows us to quickly open any file in our project:

Keyboard shortcuts

Additional useful keyboard shortcuts include Shift + Alt + F to quickly format our code, Ctrl + E (Cmd + E on Mac OS) to erase the current line, much faster than highlighting the line and hitting backspace. Sometimes we import a class into our code and later decide not to use it. Frequently, the lines where the class is used are deleted but we forget to delete the import line at the top of the source file. NetBeans will generate a warning about the unused import; hitting Ctrl + Shift + I will delete all unused imports in one fell swoop, plus it will attempt to add any missing imports.

One last thing worth mentioning, even though it is not strictly a keyboard shortcut, a very useful feature of the NetBeans editor is that left-clicking on a method or variable while pressing Ctrl will turn the method or variable into a hyperlink. Clicking on this hyperlink will result in NetBeans taking us to the method or variable declaration.

Understanding NetBeans visual cues

In addition to offering keyboard shortcuts, code templates, and code completion, NetBeans offers a number of visual cues that allow us to better understand our code at a glance. Some of the most useful cues are illustrated in the following screenshot:

Understanding NetBeans visual cues

When there is a warning in our code, NetBeans will alert us in two ways, it will underline the offending line with a squiggly yellow line, and it will place the following icon in the left margin of the offending line:

Understanding NetBeans visual cues

The light bulb in the icon indicates that NetBeans has a suggestion on how to fix the problem. Moving the caret to the offending line and hitting Alt + Enter, as discussed in the previous section, will result in NetBeans offering one or more ways of fixing the problem.

Similarly, when there is a compilation error, NetBeans will underline the offending line with a red squiggly line, and place the following icon on the left margin of said line.

Understanding NetBeans visual cues

Again, the light bulb indicates that NetBeans has suggestions on how to fix the problem. Hitting Alt + Enter in the offending line will allow us to see the suggestions that NetBeans has.

NetBeans not only provides visual cues for errors in our code, it also provides other cues, for example, placing the caret next to an opening or closing brace will highlight both the opening and closing brace, as shown in the populateList() method. This is demonstrated in the previous screenshot.

If one of our methods overrides a method from a parent class, the following icon will be placed in the left margin next to the method declaration:

Understanding NetBeans visual cues

The icon is an upper case "O" inside a circle, the O stands for "override".

Similarly, when one of our methods is an implementation of a method declared on an interface, the following icon will be placed in the left margin of the method declaration.

Understanding NetBeans visual cues

The icon is an uppercase "I" inside a green circle, which stands for "implements".

NetBeans also provides visual cues in the form of fonts and font colors, for example, static methods and variables are shown in italics, member variables are shown in green, and Java reserved keywords are shown in blue.

Another nice feature of the NetBeans editor is that highlighting a method or variable highlights it everywhere it is used in the currently open file.

Accelerated HTML5 development support

NetBeans has the capability to update deployed web pages in real time as we edit the markup for the page. This feature works both for HTML files and for JSF facelets pages (discussed in the next chapter).

In order for this feature to work, we need to use either the embedded WebKit browser included with NetBeans, or Google's Chrome browser with the NetBeans Connector plugin. To select the browser to run our web application, we need to click on the browser icon on the NetBeans toolbar, then select one of the options under With NetBeans Connector, as shown in the following screenshot:

Accelerated HTML5 development support

The accelerated HTML5 development support feature works "out of the box" with the embedded WebKit browser. To test it, select the embedded WebKit browser, then run the application we deployed earlier in this chapter in the Deploying our first application section. It will run inside NetBeans when using the embedded WebKit browser.

Accelerated HTML5 development support

To test the accelerated HTML5 development functionality, let's make a simple change to one of the pages on the application. Open the file called home.xhtml and look for a line containing the text Number.

<h:panelGrid border="1" columns="5" style="font-size: 18px;">
  Number: 
    <h:inputText id="inputGuess" value="#{game.guess}"
      required="true" size="3" 
      disabled="#{game.number eq game.guess}" 
      validator="#{game.validateNumberRange}">
    </h:inputText>
    <h:commandButton id="GuessButton" value="Guess"
      action="#{game.check}" 
      disabled="#{game.number eq game.guess}"/>
    <h:commandButton id="RestartButton" value="Reset"
      action="#{game.reset}" immediate="true" />
      <h:outputText id="Higher" value="Higher!"
        rendered="#{game.number gt game.guess and
          game.guess ne 0}" 
        style="color: red"/>
      <h:outputText id="Lower" value="Lower!" 
        rendered="#{game.number lt game.guess and game.guess ne 0}" 
        style="color: red"/>
      </h:panelGrid>

Replace the string Number with the string Your Guess, so that the markup now looks like this:

<h:panelGrid border="1" columns="5" style="font-size: 18px;">
  Your Guess: 
    <h:inputText id="inputGuess" value="#{game.guess}"
      required="true" size="3" 
      disabled="#{game.number eq game.guess}" 
      validator="#{game.validateNumberRange}">
    </h:inputText>
    <h:commandButton id="GuessButton" value="Guess"
       action="#{game.check}" 
       disabled="#{game.number eq game.guess}"/>
    <h:commandButton id="RestartButton" value="Reset"
      action="#{game.reset}" immediate="true" />
    <h:outputText id="Higher" value="Higher!"
      rendered="#{game.number gt game.guess and
        game.guess ne 0}" style="color: red"/>
    <h:outputText id="Lower" value="Lower!"
      rendered="#{game.number lt game.guess and 
        game.guess ne 0}" style="color: red"/>
    </h:panelGrid>

Save the file, and without redeploying the application or reloading the page, go back to the embedded browser window. Our change will be reflected on the rendered page.

Accelerated HTML5 development support

In order for the accelerated HTML5 development feature to work in Chrome, we need to install the NetBeans Connector plugin from the Chrome Web Store. If we select Chrome as our web browser (under the With NetBeans Connector section on the menu) and attempt to run our application, NetBeans will prompt us to install the plugin.

Accelerated HTML5 development support

Clicking on the button labeled Go to Chrome Web Store takes us directly to the download page for the NetBeans Connector plugin:

Accelerated HTML5 development support

Clicking on the button labeled Free at the upper-right corner results in a pop-up window displaying the permissions for the NetBeans connector plugin:

Accelerated HTML5 development support

Clicking on the Add button automatically installs the plugin. We can then run our project on the Chrome browser and any changes we make to the markup will be instantly reflected on the browser.

Accelerated HTML5 development support

As we can see in this screenshot, when running our application through the NetBeans connector, Chrome displays a message alerting us of the fact.

Summary

In this chapter, we learned how to download and install NetBeans.

We also learned how to set up NetBeans with third-party Java EE application servers and with third-party relational database systems, including how to register a JDBC driver for the RDBMS in question.

We built and deployed our first Java EE application by using one of the sample projects included by NetBeans.

Finally, we covered some of the NetBeans' features such as code completion, code templates, keyboard shortcuts, and visual cues that allow us to do our job more effectively as software developers.

Left arrow icon Right arrow icon
Download code icon Download Code

Description

The book is aimed at Java developers who wish to develop Java EE applications while taking advantage of NetBeans functionality to automate repetitive tasks. Familiarity with NetBeans or Java EE is not assumed.

Who is this book for?

The book is aimed at Java developers who wish to develop Java EE applications while taking advantage of NetBeans functionality to automate repetitive tasks. Familiarity with NetBeans or Java EE is not assumed.
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jan 31, 2015
Length: 364 pages
Edition : 3rd
Language : English
ISBN-13 : 9781783983520
Category :
Languages :
Tools :

What do you get with Print?

Product feature icon Instant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to United States

Economy delivery 10 - 13 business days

Free $6.95

Premium delivery 6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date : Jan 31, 2015
Length: 364 pages
Edition : 3rd
Language : English
ISBN-13 : 9781783983520
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 109.98
Java EE 7 Development with NetBeans 8
$54.99
Java EE 7 Development with WildFly
$54.99
Total $ 109.98 Stars icon

Table of Contents

12 Chapters
1. Getting Started with NetBeans Chevron down icon Chevron up icon
2. Developing Web Applications Using JavaServer Faces 2.2 Chevron down icon Chevron up icon
3. JSF Component Libraries Chevron down icon Chevron up icon
4. Interacting with Databases through the Java Persistence API Chevron down icon Chevron up icon
5. Implementing the Business Tier with Session Beans Chevron down icon Chevron up icon
6. Contexts and Dependency Injection Chevron down icon Chevron up icon
7. Messaging with JMS and Message-driven Beans Chevron down icon Chevron up icon
8. Java API for JSON Processing Chevron down icon Chevron up icon
9. Java API for WebSocket Chevron down icon Chevron up icon
10. RESTful Web Services with JAX-RS Chevron down icon Chevron up icon
11. SOAP Web Services with JAX-WS Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.8
(5 Ratings)
5 star 80%
4 star 20%
3 star 0%
2 star 0%
1 star 0%
Yusuf Sep 20, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Java EE7 meet the criteria I was looking for
Amazon Verified review Amazon
Nwokoma O Sampson Sep 13, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is one of the best well written technical books I ever purchased, and I am glad I did! It is helping me to learn new technologies while mastering Netbeans. I highly recommend it!
Amazon Verified review Amazon
Jesus S. Dec 11, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Me gusto mucho como esta distribuido, como maneja los conceptos pero sobre todo como te lleva de la mano para comenzar a programar en estos lenguajes.
Amazon Verified review Amazon
RAJ Feb 21, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good Product
Amazon Verified review Amazon
Cliente Amazon Mar 22, 2017
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Bom dia !O conteúdo é bom demais. Acontece que estou com dificuldades para instalar o software no tablete. No notebook está correto.Grato.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order? Chevron down icon Chevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
Modal Close icon
Modal Close icon