0% found this document useful (0 votes)
2 views

Java EE Web Application Primer: Building Bullhorn: A Messaging App with JSP, Servlets, JavaScript, Bootstrap and Oracle 1st Edition Dave Wolf instant download

The document is a primer on building a Java EE web application titled 'Bullhorn', which is a messaging app utilizing JSP, Servlets, JavaScript, Bootstrap, and Oracle. It includes detailed chapters on various aspects of web application development, such as database management, MVC architecture, and web page design. The authors, Dave Wolf and A.J. Henley, provide insights and practical guidance for Java developers looking to create enterprise applications.

Uploaded by

jobinkeltzg9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java EE Web Application Primer: Building Bullhorn: A Messaging App with JSP, Servlets, JavaScript, Bootstrap and Oracle 1st Edition Dave Wolf instant download

The document is a primer on building a Java EE web application titled 'Bullhorn', which is a messaging app utilizing JSP, Servlets, JavaScript, Bootstrap, and Oracle. It includes detailed chapters on various aspects of web application development, such as database management, MVC architecture, and web page design. The authors, Dave Wolf and A.J. Henley, provide insights and practical guidance for Java developers looking to create enterprise applications.

Uploaded by

jobinkeltzg9
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Java EE Web Application Primer: Building

Bullhorn: A Messaging App with JSP, Servlets,


JavaScript, Bootstrap and Oracle 1st Edition
Dave Wolf download
https://textbookfull.com/product/java-ee-web-application-primer-
building-bullhorn-a-messaging-app-with-jsp-servlets-javascript-
bootstrap-and-oracle-1st-edition-dave-wolf/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-
loucas/

Building RESTful Web Services with Java EE 8 Create


modern RESTful web services with the Java EE 8 API
Mario-Leander Reimer

https://textbookfull.com/product/building-restful-web-services-
with-java-ee-8-create-modern-restful-web-services-with-the-java-
ee-8-api-mario-leander-reimer/

Murach s Java Servlets and JSP 3rd Edition Murach


Training Reference Joel Murach Michael Urban

https://textbookfull.com/product/murach-s-java-servlets-and-
jsp-3rd-edition-murach-training-reference-joel-murach-michael-
urban/

Java EE 6 with GlassFish 3 Application Server 1st


Edition Heffelfinger David

https://textbookfull.com/product/java-ee-6-with-
glassfish-3-application-server-1st-edition-heffelfinger-david/
The Definitive Guide to JSF in Java EE 8: Building Web
Applications with JavaServer Faces Bauke Scholtz

https://textbookfull.com/product/the-definitive-guide-to-jsf-in-
java-ee-8-building-web-applications-with-javaserver-faces-bauke-
scholtz/

Building web and mobile ArcGIS Server applications with


JavaScript Lewin

https://textbookfull.com/product/building-web-and-mobile-arcgis-
server-applications-with-javascript-lewin/

Beginning EJB in Java EE 8: Building Applications with


Enterprise JavaBeans Jonathan Wetherbee

https://textbookfull.com/product/beginning-ejb-in-java-
ee-8-building-applications-with-enterprise-javabeans-jonathan-
wetherbee/

Responsive Web Design by Example Embrace responsive


design with HTML5 CSS3 JavaScript jQuery and Bootstrap
4 Hussain

https://textbookfull.com/product/responsive-web-design-by-
example-embrace-responsive-design-with-html5-css3-javascript-
jquery-and-bootstrap-4-hussain/

Beginning JSP JSF and Tomcat Java Web Development


Expert s Voice in Java 2 New Edition Zambon Giulio

https://textbookfull.com/product/beginning-jsp-jsf-and-tomcat-
java-web-development-expert-s-voice-in-java-2-new-edition-zambon-
giulio/
Java EE Web
Application
Primer
Building Bullhorn: A Messaging
App with JSP, Servlets, JavaScript,
Bootstrap and Oracle

Dave Wolf
A.J. Henley
Java EE Web
Application Primer
Building Bullhorn: A Messaging
App with JSP, Servlets,
JavaScript, Bootstrap and
Oracle

Dave Wolf
A.J. Henley
Java EE Web Application Primer: Building Bullhorn: A Messaging App
with JSP, Servlets, JavaScript, Bootstrap and Oracle

Dave Wolf A.J. Henley


New York, USA Washington, D.C., District of Columbia, USA

ISBN-13 (pbk): 978-1-4842-3194-4 ISBN-13 (electronic): 978-1-4842-3195-1


https://doi.org/10.1007/978-1-4842-3195-1
Library of Congress Control Number: 2017962002
Copyright © 2017 by Dave Wolf, A.J. Henley
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or
part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way,
and transmission or information storage and retrieval, electronic adaptation, computer software,
or by similar or dissimilar methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark
symbol with every occurrence of a trademarked name, logo, or image we use the names, logos,
and images only in an editorial fashion and to the benefit of the trademark owner, with no
intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if
they are not identified as such, is not to be taken as an expression of opinion as to whether or not
they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal
responsibility for any errors or omissions that may be made. The publisher makes no warranty,
express or implied, with respect to the material contained herein.
Cover image by Freepik (www.freepik.com)
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Manuel Jordan Elera
Coordinating Editor: Mark Powers
Copy Editor: April Rondeau
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505,
email [email protected], or visit www.springeronline.com. Apress Media, LLC is a
California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc
(SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please email [email protected], or visit http://www.apress.
com/rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub via the book’s product page, located at www.apress.com/9781484231944.
For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
To those who seek to teach themselves.
Table of Contents
About the Authors��������������������������������������������������������������������������������ix
About the Technical Reviewer�������������������������������������������������������������xi
Introduction���������������������������������������������������������������������������������������xiii

Chapter 1: Getting Started��������������������������������������������������������������������1


The Oracle Virtual Machine�����������������������������������������������������������������������������������2

Chapter 2: What Is a Database?�����������������������������������������������������������5


Referential Integrity����������������������������������������������������������������������������������������������6
Null Values������������������������������������������������������������������������������������������������������������6
Primary Keys, Foreign Keys, and Indexes�������������������������������������������������������������7
Joining Tables�������������������������������������������������������������������������������������������������������7
Normalization��������������������������������������������������������������������������������������������������������8
Structured Query Language (SQL)������������������������������������������������������������������������8
Working with the Oracle Database������������������������������������������������������������������������9
How to Open and Use SQL Developer�����������������������������������������������������������������10

Chapter 3: Installing and Running Eclipse������������������������������������������11

Chapter 4: Bullhorn Site Overview������������������������������������������������������15


The Components of Bullhorn�������������������������������������������������������������������������������15
What Does Each Page Look Like?�����������������������������������������������������������������������17
Editing a Profile ��������������������������������������������������������������������������������������������������21

v
Table of Contents

Chapter 5: What Is MVC?��������������������������������������������������������������������23


The Model, View, Controller, and Service in Bullhorn������������������������������������������24

Chapter 6: Creating a Web Application�����������������������������������������������27

Chapter 7: The DAO/Repository����������������������������������������������������������31


Implement Java Persistence (JPA)����������������������������������������������������������������������34
The Persistence.xml File�������������������������������������������������������������������������������������36
The JPA Entities��������������������������������������������������������������������������������������������������38

Chapter 8: The Service Layer��������������������������������������������������������������43


Create a DbUtilities Class������������������������������������������������������������������������������������43
Create the DbUser Class�������������������������������������������������������������������������������������44
Create the DbPost Class��������������������������������������������������������������������������������������51

Chapter 9: The Controller��������������������������������������������������������������������57


What Is a Servlet?�����������������������������������������������������������������������������������������������57
Getting the Form Data into the Servlet���������������������������������������������������������������59
Sending the Data to the Next Page���������������������������������������������������������������������59
How the Servlet Finds the Next Page������������������������������������������������������������������60
How to Set Values on Your Output Page��������������������������������������������������������������60
How the Log Out Button Works���������������������������������������������������������������������������61
The Login Servlet Code���������������������������������������������������������������������������������������61
The News Feed Servlet Code������������������������������������������������������������������������������64
The PostServ Servlet Code����������������������������������������������������������������������������������67
The Profile Servlet Code�������������������������������������������������������������������������������������69
The AddUser Servlet Code����������������������������������������������������������������������������������74

Chapter 10: The Presentation/View����������������������������������������������������77

Chapter 11: Designing Web Pages with HTML������������������������������������79

vi
Table of Contents

Chapter 12: HTML5 Tags���������������������������������������������������������������������81


Explanation of Common Tags������������������������������������������������������������������������������82
HTML Tables��������������������������������������������������������������������������������������������������������85
A Basic HTML5 and JSP Document���������������������������������������������������������������������86
JSP Standard Tag Library (JSTL)�������������������������������������������������������������������������87
What Can You Do with JSTL?������������������������������������������������������������������������������89
Prevent Cross-site Scripting Attacks�������������������������������������������������������������89
Loop Through a Collection�����������������������������������������������������������������������������89
Set a Value�����������������������������������������������������������������������������������������������������90
Test a Condition���������������������������������������������������������������������������������������������90
Repeat Content a Fixed Number of Times�����������������������������������������������������91
Test a Condition and Choose an Alternative��������������������������������������������������91
Determine If a String Is Null or Empty�����������������������������������������������������������92
Formatting Dates�������������������������������������������������������������������������������������������92
How to Display Form Data����������������������������������������������������������������������������������93
Create an HTML Login Form��������������������������������������������������������������������������93
Create a Page to Display the Output of Your Form����������������������������������������95
How to Allow the User to Navigate Between Web Pages�������������������������������96
Reusing JSP Code�����������������������������������������������������������������������������������������������96
Customizing Your Errors��������������������������������������������������������������������������������������97

Chapter 13: The Stateless Nature of the Web�����������������������������������101


The Process of Passing Data����������������������������������������������������������������������������102

Chapter 14: Users and Sessions�������������������������������������������������������105


Adding Objects to the Session��������������������������������������������������������������������������107
To Read a Value from the Session���������������������������������������������������������������108

vii
Table of Contents

Chapter 15: How to Create Database Tables for Bullhorn�����������������109

Chapter 16: Make Web Pages Do Something Using JavaScript��������111


Validate a Form Using JavaScript���������������������������������������������������������������������112
Display Number of Characters in Text Box��������������������������������������������������114

Chapter 17: Cascading Style Sheets (CSS)���������������������������������������115


Span and Div Tags���������������������������������������������������������������������������������������������116

Chapter 18: Making Pages Work on All Screen Sizes�����������������������119


Working with BootStrap������������������������������������������������������������������������������������120

Chapter 19: Use Gravatar to Display User’s Avatars with Posts�������123


Calculating an MD5 Hash with Java�����������������������������������������������������������������124

Chapter 20: The Presentation/View��������������������������������������������������127


The Code for the Login Page�����������������������������������������������������������������������������127
The Code for the Home Page����������������������������������������������������������������������������129
The Code for the News Feed Page��������������������������������������������������������������������130
The Code for the Profile Page���������������������������������������������������������������������������132
The Code for the Add User Page�����������������������������������������������������������������������134
The Code for the Support Page�������������������������������������������������������������������������135
The Code for the Error Page������������������������������������������������������������������������������136
The Navbar Include File������������������������������������������������������������������������������������136
The BootStrap Include File��������������������������������������������������������������������������������139
The Bootstrap Style Pages��������������������������������������������������������������������������140
The Footer Include File��������������������������������������������������������������������������������������140

Index�������������������������������������������������������������������������������������������������141

viii
About the Authors
Dave Wolf is a certified Project Management
Professional (PMP) with over 20 years of
experience as a software developer, analyst,
and trainer. His latest projects include
collaboratively developing training materials
and programming bootcamps for Java and
Python.

A.J. Henley is a technology educator with over


20 years of experience as a developer, designer,
and systems engineer. He is an instructor at
Howard University and Montgomery College.

ix
About the Technical Reviewer
Manuel Jordan Elera is an autodidactic
developer and researcher who enjoys learning
new technologies for his own experiments and
for creating new integrations.
Manuel won the 2010 Springy Award—
Community Champion and Spring Champion
2013. In his little free time, he reads the Bible
and composes music on his guitar. Manuel
is known online as dr_pompeii. He has
tech reviewed numerous books for Apress,
including Pro Spring Messaging (2017), Pro Spring, 4th Edition (2014),
Practical Spring LDAP (2013), Pro JPA 2, Second Edition (2013), and
Pro Spring Security (2013).
Read his 13 detailed tutorials about many Spring technologies or
contact him through his blog at http://www.manueljordanelera.
blogspot.com. You can also follow him on his Twitter account,
­@dr_pompeii.

xi
Introduction
Are you a Java developer wondering how to create an Enterprise
application? Do you find the different components overwhelming or
confusing, not knowing how they go together? We’re here to help. What if
you could just get an example application working and use that knowledge
to continue your Java journey?
This book and the accompanying code will show you one way to
create a website. It’s not the only way. It may not be the best way for
every application. But it’s a way that will introduce you to the different
components of Java Enterprise application development. And it’s a good
way to get started.
In Java EE Web Application Primer, you’ll learn the basics of Java EE
application development. You’ll see how the parts connect. You will have
the Java code for a complete, working application.

The Software
Our students take our courses to learn how to program for large
companies. We have found these are the skills most requested by the
companies hiring our students. We choose to use Java 8, Oracle 12c, and
Eclipse for developing the application. Similarly, we choose to use JPA
(Java Persistence API) instead of Hibernate. We choose JSTL (Java Standard
Tag Library) over other available options. Again, these technologies teach
core skills without hiding all the implementation details from the student.
Our application is designed to teach. We provide the complete source code.

xiii
Introduction

You will learn much simply by reviewing and modifying the source code.
This book answers the questions you may have after working with the
source code, and the source code helps explain how the concepts in this
book have been implemented.

How to Use This Book


We wrote this book based on our experience teaching Java bootcamps and
other programming courses. The objective of our courses is to help people
learn skills they can use at work. Businesses care more about results
than theory, and we apply that principle to our application. This book
answers the questions many of our students have about web application
development when starting out.

What Our Students Have Achieved


“I remember when the light bulbs started going off in my head,
when the gibberish on the screen started to make sense. It was
the most amazing feeling to start catching up with the rest of
my impressive classmates.”
—Vicky, now a project manager at a Fortune 100 company
“I went through four years of university schooling in computer
science, and I can honestly say that going through this course
gave me a wealth of experience that I only had a taste of dur-
ing my schooling. I certainly had project experience under my
belt graduating with a tech degree, but doing project after
project with Dave and Alton, the instructors, really cemented
the theory and practices I had learned previously in stone.
More than that, I got to patch up a lot of holes that I had left
unfilled from missed opportunities in college.”
—Francis, now an analyst at a Fortune 100 company

xiv
Introduction

If you’re ready to get started and develop your first Java Enterprise web
application, we thank you for choosing our book to begin your journey.
Know that you will face challenges and frustrations. You aren’t alone. We
have found that as our students worked through those, they learned more
about software development than we could ever teach in a book. You’re in
the right place. Wait no longer. It’s time to move on to Chapter 1!

xv
CHAPTER 1

Getting Started
VirtualBox allows you to create virtual computers within your physical
computer, enabling you to run multiple computers on one system. Setting
up VirtualBox requires very few steps. Once installed, you can then import
an existing virtual computer and begin work using that system.
Click and run the file to install VirtualBox just like with any other
software you’ve ever downloaded. If you are using Windows, double-click
the setup file and follow the prompts to install. If you are using a Mac, open
the DMG file that you downloaded and drag the VirtualBox file to your
Applications folder. During the installation, keep all of the options set to
their default.
Start the VirtualBox program. VirtualBox allows you to manage
your various virtual machines and easily create new ones. You can run
VirtualBox directly from the installation program, or you can start it from
the desktop icon.

Note Download VirtualBox from Oracle’s website:


http://www.oracle.com/technetwork/server-storage/
virtualbox/downloads/index.html

© Dave Wolf, A.J. Henley 2017 1


D. Wolf and A.J. Henley, Java EE Web Application Primer,
https://doi.org/10.1007/978-1-4842-3195-1_1
Chapter 1 Getting Started

The Oracle Virtual Machine


Being lazy—I mean, efficient—we used a pre-built Oracle virtual
machine (VM) image to develop the site. Oracle makes this VM available
for download at no cost (registration required). The VM requires the
open source VirtualBox software be installed on your computer as just
described. The VM hosts the latest version of the Oracle database (version
12c). It also contains SQL Developer and even Java 1.8. You will only need
to install Eclipse, which we’ll cover in a later section.

Tip Download the Oracle Database Application Developer virtual


machine from the Oracle website at http://www.oracle.
com/technetwork/database/enterprise-edition/
databaseappdev-vm-161299.html. You must accept the terms of
the software prior to downloading.

Once you have the Oracle virtual machine file ready, select File ➤
Import Appliance in the menu bar. Click the Open Appliance button to
select the Oracle virtual machine file. Navigate to the file with the .ova
file extension. Selecting this file will open a dialog box in VirtualBox that
displays the settings. You can select the Import button from here. The next
window will show you the configuration of the current virtual appliance.
Once you click on Import, VirtualBox will copy the disk images and
create a virtual machine with the settings described in the dialog. You will
see the Oracle virtual machine in the VirtualBox Manager’s list of virtual
machines. The VirtualBox Manager is the first screen that opens when you
open VirtualBox. Select your machine, click Start, and give it time to load,
then you can work with that machine as if it were a separate computer.

2
Chapter 1 Getting Started

Note If you’re not using the Oracle virtual machine, you can
complete everything in this book using Windows.
You can download and install Oracle database version 12c for
Windows at http://www.oracle.com/technetwork/database/
enterprise-edition/downloads/database12c-win64-­
download-2297732.html.
You will also need to install SQL Developer, which you can find at
http://www.oracle.com/technetwork/developer-tools/
sql-developer/downloads/index.html.
Finally, you will need to install Eclipse Oxygen from http://www.
eclipse.org/downloads.

3
CHAPTER 2

What Is a Database?
A database is a place to permanently store data for retrieval in a safe,
efficient way. A database allows us to create data and save it permanently.
It allows us to retrieve previously created data, update existing data, or
delete existing data.
A transaction groups SQL statements so that they are all applied to
the database. If one statement fails for some reason, all the statements
are undone from the database. Transactions ensure data integrity.
Transactions distinguish a database management system such as Oracle
from a file system.
The properties of a database transaction that ensure data validity are
atomicity, consistency, isolation, and durability.

• Atomicity refers to the fact that in each database


transaction either all the information is saved or none
of the information is saved.

• Consistency ensures that a transaction either works


correctly or the dataset is returned to the state it was in
before the transaction was executed.

• Isolation refers to the ability of a database to keep a


transaction that is not yet committed distinctly separate
from the working database.

© Dave Wolf, A.J. Henley 2017 5


D. Wolf and A.J. Henley, Java EE Web Application Primer,
https://doi.org/10.1007/978-1-4842-3195-1_2
Chapter 2 What Is a Database?

• Durability refers to the way committed data is saved by


the system such that, even in the event of a failure and
system restart, the data is available in its correct state.

The database stores data in sets, which are most commonly viewed as
tables. One row of a database table represents a record containing related
attributes, called fields. Fields are represented by the columns in a table.

Referential Integrity
Your database management system (DBMS) supports referential integrity.
The goal of referential integrity is to avoid having “orphaned” data.
Orphaned data can happen when you are deleting or updating the data
in your tables; for example, if you have a post in your database that does
not have a matching user. This shouldn’t happen and is often the result
of importing poorly formatted data or inadvertently deleting a user. A
database management system such as Oracle can enforce referential
integrity to prevent this by denying changes that will result in orphaned
data.

Null Values
Sometimes there is no value in a column of a row. In this case, the column
stores a NULL value. You can think of this as a flag to indicate the absence
of data. NULL is different from the numeric value zero or a string with a
length of zero characters. It is neither. It is nothing, because no value has
been stored in the column for this record. NULL, it turns out, is very useful.
You can search for a field in records that contain NULL and know that they
are the ones with no value in the field.

6
Chapter 2 What Is a Database?

Primary Keys, Foreign Keys, and Indexes


Databases are very powerful tools that allow us to search and sort data at
incredible speeds. An essential ingredient of the mechanics of a database
is that each record should be unique. To make each record unique, either
use an existing field that is unique to each record or add a field to each
record that contains a unique number.
Your DBMS can generate a unique number for each record. The
unique number of each record becomes its primary key. This field
distinguishes that record from any other in the table.
When a second table contains data related to that of the first table, the
second table can refer to the original using the primary key field.
A primary key used as a reference in another table is called a foreign
key. Foreign keys define a reference from one table (the child) to another
table (the parent).
To make access to a column of data more efficient, the database will
create an object called an index. An index contains an entry for each value
in the indexed column(s), resulting in fast access to rows. Like an index
in a print book, the database can look up the requested value in the index
and quickly locate its corresponding row in the table.

Joining Tables
Relationships are a means to join data to different tables. This helps you
avoid redundancy in the tables. You can divide your data into different
tables—entering it only once—and then reference it from other tables by
establishing relationships.

7
Chapter 2 What Is a Database?

There are three types of relationships, as follows:

• A One-to-One relationship is where each record in the


first table has only one matching record in the second
table. This usually happens when information in one table
is divided across multiple tables. This is not common.

• A One-to-Many relationship is where each record in the


first table matches with multiple records in the second
table. For example, a user can have multiple posts.

• A Many-to-Many relationship is where each record


in the first table can have many corresponding
records in the second table, and also each record
in the second table can have many corresponding
records in the first table.

Normalization
In a normalized data structure, each table contains information about a
single entity and each piece of information is stored in exactly one place.
Normalization is the process of efficiently organizing data in a
database. This is done by organizing the columns (fields or attributes) and
tables of a relational database to minimize data redundancy.
The goals of the normalization process are to eliminate redundant data
and ensure data dependencies make sense.

Structured Query Language (SQL)


A database has its own programming language, SQL (Structured Query
Language). SQL is a nonprocedural language that provides database
access. All database operations are performed using SQL. Java can talk
to the database management system using SQL. This is done using the

8
Chapter 2 What Is a Database?

JDBC API, which allows your application to specify which records to


retrieve based on various criteria. For example, you can select records
created between certain dates or update only records that meet given
criteria. SQL can also be used to create database objects, such as user
tables and saved queries, which are known as views. A view contains
no data itself but is simply the stored query the use of which simplifies
accessing the data.
SQL (pronounced as the letters S-Q-L or sequel) is a specialized
database language that consists of statements that are very close to
English. SQL has one purpose: to communicate with a database. We
communicate with the database to add, update, or delete data. We also
communicate with the database to create and modify tables and other
database objects.
Almost every major DBMS supports SQL. Learning SQL will enable
you to interact with almost every database you might encounter. SQL is
easy to learn. The statements consist of descriptive English words. SQL
is powerful. Cleverly using the language elements allows you to perform
complex database operations. SQL is a standard governed by ANSI
(American National Standards Institute). In addition to the standard
implementation of SQL, most vendors implement their own proprietary
extensions. The version of SQL) you use for Oracle may differ from the
version you use to access other databases.

Working with the Oracle Database


Just as you use an IDE (integrated development environment) to work with
Java programs, you can also use an IDE to work with Oracle databases.
This IDE is called SQL Developer. The virtual machine has a copy of SQL
Developer already installed.

9
Chapter 2 What Is a Database?

How to Open and Use SQL Developer


To open SQL Developer in the virtual machine, simply click its icon on the
desktop.

Tip Oracle provides step-by-step instructions for using SQL


Developer on their technetwork website. If you use the virtual
machine, then everything is installed for you. Browse to http://
www.oracle.com/webfolder/technetwork/tutorials/obe/
db/sqldev/r40/sqldev4.0_GS/sqldev4.0_GS.html.

10
CHAPTER 3

Installing and
Running Eclipse
Your virtual machine contains all the software you need to create
Bullhorn—the Oracle Database 12c, SQL Developer, and Java 1.8—but it
doesn’t contain the Eclipse IDE. You will need to download and install that
yourself. Fortunately, the installation process is very easy.

INSTALL ECLIPSE ON THE VIRTUAL MACHINE

To install Eclipse on the virtual machine, you will need to open Firefox and
download the Eclipse archive. Then, you will need to extract the files from the
archive. Next, you will need to run the setup program that is included in the
archive files. Finally, open Eclipse.

1. From the virtual machine, open the Firefox web browser. You
can get to Firefox by clicking on the Applications menu and
selecting the icon for Firefox Web Browser.

2. Next, browse to http://www.eclipse.org/downloads.


3. Click on the orange button to download Eclipse. You’ll be
installing the latest version, which is called Oxygen.
4. You’ll be directed to another page with an orange Download
button. Click this one as well.

© Dave Wolf, A.J. Henley 2017 11


D. Wolf and A.J. Henley, Java EE Web Application Primer,
https://doi.org/10.1007/978-1-4842-3195-1_3
Chapter 3 Installing and Running Eclipse

5. Select the option to open with the Archive Manager when this
window is displayed. The Archive Manager is the program that
will extract your files.

6. You’ll be prompted to select a folder into which you want to


place the extracted files. Browse to the Home folder and select
Extract.

7. Check the option to open the folder to view the files.


Once you see the extracted files, look for the file called
eclipse-­install.

8. Select the option to install Eclipse for Java EE.

9. Your folder should be /home/oracle/eclipse/


jee-­oxygen.

10. Click Launch.

11. Accept the default workspace. This is where your project files
will be kept.

You have just installed Eclipse Oxygen.

HOW TO CHANGE THE PORT IN TOMCAT

By default, Tomcat is configured to listen on the following port numbers: 8005,


8080, and 8009. The port we’re most interested in is 8080 since it’s used for
HTTP access. When you run a web application in Eclipse using Tomcat, the
URL becomes http://localhost:8080/ApplicationName. However,
sometimes these ports are used by other software running on the computer.
Fortunately, Eclipse makes it easy to change the port numbers.

12
Chapter 3 Installing and Running Eclipse

1. From your web project, in the Servers view, double-click on the


server name.

2. That will open a configuration page for Tomcat as follows:

3. Notice that the port numbers are shown in the table on the
right. Click to edit; for example:

4. Once you change the port number for HTTP from 8080 to 9000,
you should press Ctrl + S to save the change and restart the
server.

Your application should now run without conflict. If you do get a conflict, then
you’ve chosen another used port. Repeat the process with a different port
number. It’s best to select a port within the range of 1025 to 65535. You can
research “Well-known port numbers” to find many articles explaining the
reasoning here.

13
CHAPTER 4

Bullhorn Site Overview


The diagram in Figure 4-1 illustrates how the site fits together. Only the
core components are shown. You may wish to add additional pages and
classes as needed.

JPA (data
access)
Classes
Bullhorn Overview Diagram
Session - visible to all servlets and JSPs
Session times out 20 minutes after last accessed
Database
User object in session is available to all servlets and JSPs Posts Table
Users Table
Newsfeed
Login Servlet Home Servlet
Servlet

Request Request Request Request


Request Request
Login Page Home Page Newsfeed Profile

Posts user email


user email Post item
password
Post item
...................
post text Post item motto
Login Post item
Submit Update

Session holds objects (but only if Servlet adds them)


JSP (Java Server Page) = HTML + Java Code (and maybe JavaScript)
Servlet = Java code which create objects such as the User
Class = Java code used as a blueprint for an objects Note: Not all classes
For simplicity, all passwords are the word ‘password’ are shown in this diagram

Figure 4-1. The components that make up Bullhorn

The Components of Bullhorn


• Servlets Java classes that extend the web server to
provide an interface to the browser and database or
other servlets.

© Dave Wolf, A.J. Henley 2017 15


D. Wolf and A.J. Henley, Java EE Web Application Primer,
https://doi.org/10.1007/978-1-4842-3195-1_4
Chapter 4 Bullhorn Site Overview

• JPA classes Java Persistence API classes that are used


to communicate between the servlets and the database.

• Request objects represent information sent between


the browser and the servlets. This information might
include email addresses and passwords that are being
used by the servlet to allow access to the site.

• Sessions are the web server’s method or approach of


retaining data while the user is accessing the site.

• User objects The user information is stored in a class


that will be stored in the session and is available to all
pages for the current user.

• JSP (Java Server Pages) Web pages that contain HTML


and tags from the JSP Standard Tag Library to add
functionality. Because they contain code they can
dynamically render for each user’s request. The JSP
Standard Tag Library permits each person to view their
own version of the page.

• HTML (Hypertext Markup Language) pages. HTML is a


system for tagging text files to control fonts, colors, and
images on your web pages.

Tip To keep your HTML from getting too complicated, use CSS
(Cascading Style Sheets) and JavaScript to control the presentation of
your content and let HTML control the layout.

The Bullhorn application contains web pages for login, home, news
feed, and user profile. The user starts at the login page. Once the user
clicks the Login button, the request (data from the login form) will be sent
to the login servlet.

16
Chapter 4 Bullhorn Site Overview

The login servlet will validate the user against the database. A
valid user will be stored in the session, which is the website’s way of
remembering data between page views. Invalid users will not get past the
login page until they enter a correct username and password combination.
We will create other objects (classes) to validate data or support the
classes and pages shown in the diagram.

What Does Each Page Look Like?


The login page will contain text boxes in which the user will enter their
email and password. This information will be verified in the login servlet. If
they match what is in the database then the user will be redirected to their
home page. If they do not match then the user will be prompted to log in
again. Users who reach the login page but aren’t registered on the site can
register for a login by clicking on the “Join” link. See Figure 4-2.

Figure 4-2. The login page contains text boxes for email and
password and a button to sign in to the application

17
Chapter 4 Bullhorn Site Overview

The home page will allow each user to create a new post. Each post is
limited to 141 characters, so the home page enforces this restriction (see
Figure 4-3). Once the user is logged in, all pages contain a navigation bar at
the top that allows the user to navigate to different pages, view or edit their
profile, and search for posts containing a specific word.

Figure 4-3. The home page contains a form to submit a post to the
database. The form contains a text box and buttons to either submit
the post or clear the form.

Each page contains the same navigation bar, which allows the user
to move around the application. The navigation bar contains the logo,
links for the home page and the news feed page, and a search box. It also
displays the name of the logged-in user. The user can also select from
various user options, which is implemented as a drop-down list. These
include logging out, viewing or editing profile, and submitting feedback.
See Figure 4-4.

18
Exploring the Variety of Random
Documents with Different Content
Camera led the conversation in our corner of the room to the subject of optical
illusions, when some one of course suggested the hat experiment. There is probably
nothing the proportions of which are so deceptive as a hat. Reader, if you have never
tried the experiment, take a stick and point out on the wall how high you think a hat
would reach from the floor if placed on its crown, as represented in our sketch.

Aunty Delluvian, the first to try, took the stick and boldly measured off a distance of
between two and three feet, and utterly laughed to scorn the moderate persons who
satisfied themselves with ten inches. After each of the measurements was marked with a
pencil, and the hat itself put beside them, showing every one to be wrong, Aunty's
amazement knew no bounds. Indeed, she would not be satisfied till we brought our own
hat to convince her that some deception had not been practised.
This was Aunty Delluvian's first visit to the Adams', having only recently been
introduced through the agency of Nix. I was, therefore, not unprepared for some criticism
on our friends; but when the good lady, towards the close of the evening, took us to one
side and said confidentially and emphatically, nodding her head at the same time
knowingly, "No flippery, flummery. I like her!" we were a little surprised, the statement
was so emphatic and yet so vague. That was all she said, walking away briskly when she
had so delivered herself, as though she had rendered a final verdict. To which of the
family did she refer? To Mrs. Adams, we presume, and yet she might have said
something about the other members of the family. She is a queer creature is Aunty
Delluvian.
We are disposed to think that the ART of entertaining is rarely if ever regarded as an
ART, and certainly never treated as such. We, however, on this occasion, laid our plans
and arranged our forces with as much care and skill as a general exercises in laying out a
campaign. We have as profound a respect for a good commissary as ever did Napoleon
Bonaparte. We had our reserve, too, and our signal corps, so that should the battle
waver at any moment, it might be immediately set going again. Amongst other
resources, we had a number of surprise pictures concealed in a certain place, which were
to be produced when occasion might require. One of these will be found on opposite
page, and comprises fifteen faces in one. Pictures of this kind always amuse, and are fine
provocatives of conversation.
FIFTEEN FACES IN ONE.—See page 229.
Reader, when you give a party, do not bring your entire force into action at first; always
have a reserve to fall back upon.
We saw a whole group which was showing alarming symptoms of demoralization rallied
with a pocket-handkerchief. Nix saw the emergency, drew his handkerchief, tied one end
round the tip of his finger, on which, with a few dots of the pen, he had indicated a comic
face, and threw himself into the dispirited crew, exclaiming:
"This is Rantepolefungus, the mysterious magician of Morocco." Then, in a feigned
voice:
"How do, pretty ladee and gentlemen? Me tell fortune, work spell, makee incantation.
Me tell you fortune, pretty missee; you be, by-a-by, sixt wife great street contractor;
favorite wife, he givee dust-cart full of greeny-back; much lovee you; cut off head of all
other wife, makee you much happy; he givee you large gold ring big's flour-barrel to
wear in your nosee, and six whiskey cocktails every morning. Pretty ladee, give great
magician buckshees," and a whole string of other nonsense, the little Moor moving his
head and hands all the time, suiting the action to the words.
The sketches opposite will show how the Moor is made.
As we walked home with Nix, smoking our cigars, we agreed that the party had been
managed with consummate generalship. As we parted, he asked us if we should like to
have a small statue of Vishnu? Wonder what he meant.
[A] The spark emitted is sufficiently powerful to light a jet of gas.
CHAPTER XX.
Those red and green lights which lend such a glory to the final tableaux of fairy pieces
on the public stage, can easily be introduced into private parlor performances. There is
no danger in using them; they are quite inexpensive, and very easily managed. Warning,
however, should be given to all asthmatic persons to vacate the ranch before firing off, as
their fumes are apt to produce unpleasant results. When we first performed the play of
Bullywingle the Beloved, the red light was calculated on as a startling feature of the
performance. At the proper moment the match was applied, the combustibles behaved
handsomely, everybody was entranced, all save one unfortunate gentleman, subject to
asthma, who created quite a sensation by rushing out of the house in a choking
condition, and remaining speechless in the snow for over twenty minutes.
The mode of working these lights is to place one of the powders, for which we shall
presently give you prescriptions, in an iron shovel, and apply a lighted match. The
powder will begin to burn slowly, emitting a bright red or green light, accompanied by
volumes of smoke. Before exhibiting these lights, all others in the room, gas or lamps,
should be turned down as low as possible.
If the operator stands behind the scenes, so as to be out of sight during the
performance, the effect is what Artemus Ward would call Trooly Grand.
In order to procure the lights, go to some druggist and give him the following
prescriptions. He will procure the necessary materials and mix them for you.

RED FIRE.

Forty parts of dry nitrate of strontian, thirteen parts of finely powdered sulphur, five
parts of chlorate of potash, and four parts of sulphuret of antimony. The chlorate of
potash and sulphuret of antimony should be powdered separately in a mortar, and then
mixed together on paper; after which they may be added to the other ingredients,
previously powdered and mixed.

GREEN FIRE.

Green fire, when burned in a reflector, sheds a beautiful light on all surrounding
objects. Take of flour of sulphur thirteen parts, of nitrate of baryta seventy-seven, of
oxymuriate of potassa five, of metallic arsenic two, of charcoal three. The nitrate of
baryta should be well dried and powdered; it should then be mixed with the other
ingredients, all finely pulverized, and the whole triturated until perfectly blended together.
A little calamine may be occasionally added, in order to make the compound slower of
combustion; and it is above all things requisite that the rubbing together of the materials
should be continued until they are completely mixed.
It may so happen that in some of your parlor theatricals you may wish to introduce a
storm, so we will tell you how to manage it.
There are several elements in a storm which can be counterfeited.
Thunder.
Snow.
The sound of rain or hail.
Lightning.
Wind.
The noise of thunder is produced by shaking a sheet of iron behind the scenes. The
sheet should be about three feet square, and can be procured at any stove store.
Snow can be represented by throwing handfuls of small scraps of paper from above.
It is best to mount on a chair or step-ladder behind the scenes, and strew them down
in the proper direction. The scraps of paper should be of course white and torn, not cut,
of the requisite size.
The sound of rain or hail is produced thus: Get the carpenter to make for you a box,
from eight to twelve feet in length, and of about four inches inside diameter; put in a
couple of handfuls of dried peas, and then fasten up the box; when you wish to make
rain, tilt up one end of the box and let the peas run down to the other end, then reverse
the box and let them run back again. As long as you continue to do this you will have an
excellent imitation of rain, at least as far as the sound is concerned.
Lightning is imitated by having a lamp in a box; whenever you want to produce a flash,
open the lid suddenly and close it again. Of course all the other lights in the room must
have been previously lowered.
Wind. Sufficient wind to blow about the flakes of snow can be produced with a very
large fan, a wooden frame with calico stretched over it being as good as anything. But to
simulate the effects of a gale, some other means must be adopted.
We will assume that the curtain rises on a storm scene; thunder and hail are heard,
and fitful flashes of lightning illumine the landscape. Enter a wandering female, a little
girl, we will presume, in search of shelter; as she walks on to the stage leaning forward
as though struggling against the blast, her shawl and dress are violently agitated by the
wind. To produce this effect attach two or three strong threads to the garments named,
and at the proper time jerk and pull them with a tremulous motion, to impart the natural
action. The preceding diagram will illustrate our meaning.
These instructions may be found useful to amateur players, and will certainly heighten
the effect of the performance when they can be introduced.
There is another point in connection with make-up to which we may as well call the
reader's attention before closing this chapter. All persons, no matter how ruddy their
complexions may be, look pale or sallow under the influence of the bright light necessary
to illuminate a stage; to counteract this effect it is absolutely necessary to rouge, or in
other words, paint the cheeks pink; a little carmine from your paint-box will serve for this
purpose, if you have not the regular rouge powder on hand.
CHAPTER XXI.
It is marvellous how much amusement, in a quiet way, can be got out of a pair of
scissors and a piece of card-board. Moreover, if the fingers be plump and white, we know
of no position in which they look more tantalizingly bewitching, than when harnessed like
a couple of white mice in the iron yoke of a pair of liliputian shears. We have passed
many a pleasant evening in contemplating and cutting. On one occasion which we
remember well, as it led to sudden and unexpected matrimony of a valued friend, we sat
till twelve o'clock at night and used up a whole pack of cards, except the jack of
diamonds, in making boomerangs and other mechanical notions. The boomerang we
have already introduced to our readers, and some of the other contraptions we shall now
proceed to explain. So scare up all the cards you can, and bring out your army of
scissors.
One card puzzle we have often tried, and with which most persons are familiar, is that
of the cross. You cut out of card or stiff paper, five pieces similar in shape and size to the
following, viz. one piece of fig. 1, one piece of fig. 2, and three pieces of fig. 3.
These five pieces you put together so as to make a cross like Figure 4.

If you cannot solve the problem, look at the following cut, and you will cease to be
puzzled.

Now we will try another card puzzle. Cut a piece of card or paper in the shape of a
horse-shoe, and mark on it the places for the nails as represented in the subjoined
sketch.
The puzzle is with two cuts to divide it into six parts, each part containing one nail.
Of course you cannot do it; we could not do it ourselves, and had to get the white
mice to show us the way.
Somehow or another we never can find out anything with half a dozen taper fingers
fluttering before our eyes. They bewilder us terribly, getting between the feet of our
ideas, so to speak, and tripping us up; as young lambs might serve an awkward
shepherd.
Well, the mystery is solved thus: you cut off the upper circular part, containing two of
the nails; then by changing the position of the piece, another cut will divide the horse-
shoe into six portions, each containing one nail.

The next trick is of a slightly different style. Cut two pieces of card like those
represented in the diagram and place them in the position represented; the problem is,
with a small stick or lead-pencil, to raise them from the table, without of course touching
them with your fingers. You may try this as often as you like. If you succeed, well and
good; if you do not, you can come back here and refer to the solution.
Here is a picture (No. 2) representing the way in which it is done; need we add
anything in the way of explanation? We think not—so we won't do it.
CHAPTER XXII.
Nix has a sister married to a wealthy leather merchant, whose place of business is in
that odoriferous part of New York city called The Swamp. She is very beautiful, so we call
her the Swamp Angel, and her husband's counting-house, Araby the Blest. Her children
we have christened Findings, the youngest being always spoken of as the last. We have
numerous jokes, of course, about the cobbler sticking to his last, the best quality of calf,
and so on. She is very good-natured, and enjoys our badinage heartily, having a healthy
vein of fun of her own, which transmutes all the little events of domestic life into the
most refined humor. We like humor in a woman, or we should rather say in a
gentlewoman; her culture and the natural tact peculiar to her sex, seem to eliminate any
of those grosser particles which the coarse sensibilities of a man would not detect.
Humor is as fascinating in a woman as sarcasm is abominable; it requires the very
highest breeding to make the latter quality moderately safe in the hands of young
women. For our own part, we would rather see a woman chew tobacco than hear her say
sharp things. However, this is a digression. Mrs. Crofton, as we said, is very fond of fun,
and in her house there is that perfect ease and abandon which can only be enjoyed by
well-bred people; whoever visits there is at home; and a favored few, of whom the writer
has the honor of being one, are treated quite as enfants de famille.
If, on calling, we find the heads of the house from home, we know where the claret
and cigars are kept. Cicero, the negro waiter, obeying standing orders, promptly serves
up some repast, and presses the hospitality of the house upon us with all the aplomb and
grace for which his race are remarkable.
We drop into breakfast whenever we feel so disposed, and invite ourselves to dinner or
tea as freely as though our friends kept a hotel; indeed we jocularly call their mansion by
various public names: "The Crofton House," "Fifth Avenue Hotel," "The Shoe and Leather
House," etc., etc. We have perpetrated more sheer, downright nonsense in their saloons
than any forty strait-laced country school-children ever condescended to commit in their
rural play-ground.
One day during the holidays, when some fourteen or fifteen friends had dropped in
quite promiscuous, and were playing all kinds of tricks, a certain gentleman, imported
from England, an officer in the Guards, genus Swell, "pwoposed" that we should play the
Muffin man. As none of us had ever heard of this gentleman or the muffin business,
there was a general cry for light.
"Oh, its vewy jolly, I asshua yaw. We all sit wound in a wing, yaw know, and one of us,
yaw know, sings:

"'Do yaw know the muffin man,


Do yaw know his name,
Do yaw know the muffin man,
That lives in Cwumpet Lane.'
Then the next person answers:

"'Oh, yes, I know the muffin man,


Oh, yes, I know the muffin man,
Oh, yes, I know the muffin man,
Who lives in Cwumpet[A] Lane.'

Then he turns to the next person, and when each person has sung his verse, yaw know,
he then joins in the cawus,[B] until it has gone all wound;[C] then, yaw know, we all sing
together:

"'We all know the muffin man,


We all know his name;
We all know the muffin man,
Who lives in Cwumpet Lane.'

The game is, yaw know, to keep a gwave[D] face all the time. If yaw laugh yaw pay a
forfeit."
"The muffin man, the muffin man," echoed half a dozen voices; "let us play the muffin
man."
The proposition being carried nem. con., we all sat "wound in a wing," or round in a
ring, a circle of individuals of every age from three up to seventy. The Englishman, as
head instigator, started the game, but before he got half through his verse we were all in
convulsions of laughter; the next person took it up, but it was utterly useless to think of
collecting the forfeits; we were all, in spite of every effort, like a party of maniacs reeling
in our seats with merriment. There was something so utterly idiotic and absurd in a large
party of respectable, rational beings, congratulating themselves in song that they "knew
the muffin man of Crumpet Lane."
The English swell was immediately made an honorary member of our order, which is,
as yet, without a name.
As we had all laughed our throats dry, Mr. Crofton invited us into the next room to see
a man, as the Immortal Artemus delicately expresses it, so we all went in and saw the
man. Some of us saw him in ice claret, some in hot punch, and some in cool champagne.
One of Crofton's children, a maiden aged three years, whom they called Toney, as the
diminutive of her Christian name, Antonia, came toddling in with the rest and said:
"Me, Nooni, want see man." Whereupon her father gave her a goblet of lemonade. She
just tasted it, and handed it back with supreme contempt, saying:
"Me, Nooni, want banny wasser;" which being translated into English means:
"Me, Toney, wants brandy and water."
The little voluptuary was satisfied with a glass of weak claret punch.
During this conversation, Bub, a patriarch of five years, who had been looking on with
a very patronizing air, now came forward, and laying his hand on his sister's shoulder,
lisped out:
"Oh, you tunnen witty sing, zats nice banny water." Then turning to us in a confidential
way, he continued: "She's a witty durl (little girl); she finks (thinks) zats banny water;
banny water make witty durls fick (sick); me, big boy, banny water not make me fick."
We gave him a nondescript drink, flavored with every liquor on the table, which made
him feel immensely proud.
"Let us play at earth, air, fire, and water," said Mrs. Crofton.
"Very well, Toney," answered her husband. "You can play at earth, and I will play with
the fire-water." So saying, he filled himself a glass of punch, and stretched his limbs in an
easy-chair.
"I think my husband is the laziest fellow living," laughed Mrs. Crofton. "I do believe if I
were being carried off by wild Indians, he would make a note of it in his memorandum
book, to have his porter attend to the matter next day."
Nix here interposed: "Dear, dear, these family quarrels are very painful. Come, Toney,
and help to amuse the young people. Earth, air, fire, and water, whatever that may be, is
the order of the day. How do you play it, Toney?"
"You all sit round the room, and then one of the party throws something at one of the
others, at the same time naming one of the elements, earth, or air, or fire, or water; then
he begins to count one, two, three, four, five, six, seven, eight, nine, and before he says
ten, the person struck must name some animal living in the element chosen."
"Well, but what do you throw at the person?" inquired Nix; "a bureau, or decanter, for
instance?"
"No, no; something small and soft, like a pair of gloves, or—or—oh, I know, wait a
minute and I will run up-stairs and get the baby's worsted ball; that will be just the
thing."
While Mrs. Crofton was absent, and she was detained rather longer than her mission
seemed to warrant, Nix, in poking about in his sister's work-basket in pursuit of mischief,
discovered a piece of white beeswax.
"Eureka!" he exclaimed, "I have it; we will play Toney a trick before she comes back;
we will make her think some one has broken her new mirror."
Saying this, he advanced to a large pier-glass between the windows, and marked on it
a huge star with the white wax something like the accompanying diagram, and then
instructed one or two of us to make lamentations over it when his sister should return.
We had not to wait long: in a few minutes Mrs. C. entered the room, whereupon we
conspirators set to work gesticulating, and talking over the supposed catastrophe.
"Dear! dear!" said one, "how unfortunate!"
"How did it happen?" queried a second.
"I really don't know," answered a third. "I merely heard a crash, and——"
Here the lady came on the scene, looking quite flushed.
"I knew you children would be in some mischief," she said, "while I was away. I
suppose this is some of my clumsy brother's work. He never comes into the house
without destroying something."
"I'm very sorry," whined Nix, contritely; "it was quite an accident, I assure you; but I
wonder whether it could not be mended?"
"Mended! you goose," exclaimed his sister. "Who ever heard of mending a broken
mirror! It will take a pretty big cheque on your banker to mend that, sir."
"I am not so sure of that," replied Nix. "If it is not very bad I might——any way I will
try." Suiting the action to the words, he advanced towards the mirror in such a position
that his sister could not see what he did, and very deliberately wiped out the wax marks
with his pocket-handkerchief. The astonishment of Mrs. C. at this miracle knew no
bounds, nor could the gift of any amount of new pier-glasses have given her more
pleasure.
"Now, then, all take your seats; we are going to play earth, air, fire, and water."
The circle is formed; our hostess holds the woollen ball poised in her hand for an
instant, and then sends it flying into the bosom of a grey-haired old gentleman, at the
same time uttering the word "air," and commencing to count rapidly, "one, two, three,
four, five, six, seven, eight, nine, ten." The old gentleman seemed utterly paralysed until
she had finished counting, when he stammered out, "Wh—h—h—h—h—Pig!" amidst the
roars of laughter of every one present. Of course he had to pay a forfeit, and took his
turn at throwing the ball.
No one who has not seen this game played can conceive how ludicrous it is, or how
much good wholesome laughter may be got out of it. When a sufficient number of
forfeits had accumulated, they were cried in the usual manner. A good deal of ingenuity
was displayed in awarding the tasks as well as in executing them. One was that the
owner of this "pretty thing" should make an impromptu containing the names of every
one in the room, and was managed in the following style:

"Three Howards—Corsey, Toney, Archibald, and Nix,


Bub, Brown, Campbell, Jim and Jane have got me in a fix."

Another task imposed was, that the owner of a cigar-case should give us a riddle no one
could solve. Going into the next room, this person procured a glass of wine, and holding
it up said: "Gentlemen, I give you 'the ladies.'" No one attempted to solve this riddle.
Another gentleman was ordered to point out the greatest goose in the room. This
delicate task he set about performing in the following manner: he went to one young
lady and asked her to hold up her face to the light, which she did, whereupon he
imprinted a chaste salute on her lips; he then went to the next, but she persisted in
holding down her head. He then turned round to his tasker and said: "Really it is
impossible for me to determine which are the geese if they will not allow me to examine
their bills." He was let off.
When all the forfeits were restored, even to little Toney's pocket-handkerchief, which
she recovered by throwing herself into her papa's arms and hugging him round the neck,
as the prettiest, and wittiest, and one she loved best, we all adjourned to broiled oysters
and chicken salad.
[A] This word means Crumpet.
[B] This word means Chorus.
[C] Round.
[D] Grave.
CHAPTER XXIII.
A few days ago when the blistering sun had converted the whole of New York city into
one vast bake-oven, Nix called at our office, and proposed a flying trip to a certain
watering-place. We will not mention its name for fear of incurring the suspicion of writing
puffs. It was, however, sufficiently unfashionable to be tolerably comfortable. In order to
reach our destination we took an early steamboat, leaving New York at six o'clock in the
morning. With what intense satisfaction we became conscious of possessing lungs as we
inhaled the cool air which had been washing itself all night in the great waves of the
Atlantic ocean, or sleeping among the pine-woods of Delaware and New Jersey. There is
nothing surely which makes one feel more grateful for the gift of life than to breathe the
early morning air, laden with the perfume of salt-water. On this occasion the bracing
atmosphere gave a relish to everything. The crisp broiled ham, the clam-fritters, and
even the miserable coffee we had for breakfast on board, all tasted like food worthy of
the gods. And as for our cigars (genuine Havanas) which followed the meal, their incense
fairly sent us up to the seventh heaven of delight. But our business is to write on the Art
of Amusing, and although an early steamboat trip may be one of the most enjoyable of
things, it scarcely comes within the sphere of our work.
When we arrived at the hotel, we found the lady guests were in process of organizing
a fair for the benefit of the sufferers by the great Portland fire.
Nix rushed into the enterprise with his usual enthusiasm; and by that evening, when
the fair commenced, had fully qualified himself to start in business as a Three-sticks-a-
penny-man. This plebeian pastime he had picked up at some English race or fair he had
once visited, and now attempted with considerable success to acclimatize in America. His
first step was to go to the village store and purchase a number of penknives, jack-knives,
pincushions, tobacco-boxes, and similar contraptions. His second care was to cut half-a-
dozen hickory-sticks or wands, of about four feet six inches in length, and of the
thickness of your middle finger—that is, if you are blest with as spacious a paw as
ourself; if not, we feel at a loss how to convey to your mind an approximate idea of the
measurement. But suppose you take any healthy Irish day-laborer, and make his third
finger the standard, not the part where the knobs are, but the spaces between them.
Well, Nix cut six sticks of about the thickness of a healthy Irish day-laborer's third finger,
in the spaces between the joints or knobs. He then cut a dozen other sticks of about the
thickness of anybody's wrist, and about two feet long. Good! When he wished to
commence operations on the fair-ground he selected a piece of level turf, and on one
side of it dug six holes about the size of the late Daniel Webster's hat; these holes he half
filled with sand, and in the centre of every hole he then stuck one of the sticks of about
the thickness of a healthy Irish, etc., etc. Then on the top of each stick he balanced a
jack-knife, pin-cushion, or some other object of more or less value. Now all his
preparations were completed. He was prepared to receive customers. Standing in a
commanding attitude, at a distance of about thirty feet from the arrangement we have
described, he cried out in truly English style:
"Now, ladies and gents, ere yer are—three sticks a penny. Any lady or gent wishin to
make a immediate fortin, and marry the being of his art on the result, have only to invest
a few dollars in my establishment, and he will retire wealthy in arf a nour. Here, ladies
and gents, look at these ere sticks" (holding up one of the clubs about the thickness of
anybody's wrist), "hall you ave to do is to throw one of these ere at them there" (pointing
to the pincushions, etc.); "hany article you knock orf is yourn, provided it don't fall inter
the ole. Now, all I charge you for the priviledge orf throwin' three of these sticks, is the
radicerlously small sum of ten cents. You are sure to win five dollars each time. Now,
walk up; walk up, and take yer chance, and make yer everlastin fortin; marry the hobject
of yer haffections, and build yer pallatial willa on the Udson."
Here a courageous youth stepped up, examined the whole arrangement minutely, and
concluded to invest ten cents. Fortunately for Nix and the cause this youth knocked off a
dollar jack-knife at the first throw. The consequence was an immense rush of patronage;
indeed, the sport became so exciting that two similar establishments could have been
kept in active operation. As it was, Nix cleared fifty-four dollars over and above all
expenses for the good of the fair, and the benefit of the poor folks of Portland.
One of Nix's most profitable customers was a good-natured flashy young man of the
wholesale dry-goods pattern, who appeared each day in some new shade of mustard-
colored clothing, from the delicate yellow of freshly mixed pure Durham to the rich tones
of stale German. He told us in confidence that he had intended to go to Saratoga, but the
old gentleman and old lady (his father and mother) had insisted on his coming down with
them to "this d——d hole;" then, suddenly recollecting that we had all probably come
from chance, he added:
"Oh, this is a very nice place; first-rate; I don't say anything about that, only I had a
party of friends going up to Saratoga, and they'll expect me; they know there's always
fun going on where I am. It don't make any difference to me whether I spend fifty dollars
or five hundred. I'm bound to have a good time. I appreciate anything; tha's—anything,
you know—tha's got any wit into it, you know. Well, you know, there are some people
who ain't got any idea; don't seem to appreciate, you know. Now, when I saw you
throwin' sticks, well, I piled right in; I didn't care about it, of course, only I saw what you
were doing it for, and I didn't care. Some people would think it awful vulgar, you know,
but I don't care; that's the sort of man I am. Perhaps I shouldn't have liked some of my
aristocratic lady friends to have seen me; but then down here, you know. Oh, I'd just as
lief have given the money to the fair; I'd spent thirty dollars before in slippers and things,
and then gave 'em back. I didn't want 'em, you know, only I like to see things lively;
there's bound to be fun when I'm round."
However, we will not follow our good-natured friend through his long monologue of
refined egotism; we merely introduced him because he showed us a variety of tricks, two
of which we think worth recording in our book on amusements. On the morning after the
fair, Nix and ourself, in company with the mustard-colored aristocrat, took a bath in the
ocean. The aristocrat appeared in the water attired in a sumptuous bathing dress,
smoking a cigar which he told us cost $800 per thousand; which, he frankly confessed,
he thought too high a price for a man to pay for cigars in these times. He further stated
that he relished smoking in the water very much. To our inquiry whether there was no
danger of the waves putting it out, he replied by informing us that he could dive under
water with a lighted cigar in his mouth without extinguishing it.
"D'you see that boat there?" he said, pointing to a small scow about a hundred and
fifty yards distant. "Well, I will dive under that; you watch me, and you will see me come
up." We thought there must be some hoax in the matter, and so kept a strict eye upon
his movements. He swam out to the craft, gave a plunge and a kick, after the manner of
ducks in a pond, disappeared, and came up on the other side, calmly puffing his weed.
Never having seen or heard of the feat before, Nix and ourself were what the ancient
Greeks used to call flabbergasterd. When he had enjoyed his triumph and our
bewilderment for a few minutes, he showed us how it was done; simply by putting the
lighted end of the cigar in his mouth just before going under water, that was all. He
added: "I will show you something better if you will come up to the shooting-gallery after
we get through bathing. Did you ever see a man ring the bell with his back to the
target?"
Arrived at the shooting-gallery, our young friend procured a mirror which he hung on
the wall opposite the target, then placing himself in front of the former, with his back to
the latter, he held the pistol over his shoulder and took aim, looking at the image of the
pistol in the glass as if it were the pistol itself; that is, in such a manner that the
reflection of the object was covered by the reflection of the pistol; he then fired, and
came within an inch of the bull's-eye.
When we got back to the hotel he amused us by setting fire to a glass of alcohol with a
burning glass. He placed a silver dollar (a red cent would have answered as well) in the
spirit, and then directed the rays of the sun through the burning-glass on the metal; in an
instant the liquid was all ablaze.
In the afternoon this same youth called us all to enjoy a trick he had played upon the
old gentleman.
The old gentleman, it appeared, was engaged in reading Macaulay's History of
England, and like a methodical old gentleman, whenever he laid down the book, marked
the place where he left off. On the day in question his son had abstracted his book from
its accustomed place, and painted on the page following the one he was, reading a very
excellent imitation of a fly. At his usual hour the old gentleman was seen to put on his
spectacles, and take up the book; all those in the secret were of course on hand;
presently he came to the passage on which appeared the counterfeit fly; the old
gentleman shook the book, but the fly stirred not; then he blew at it; then he laid down
the volume, and deliberately taking out his handkerchief, made a pass at the offending
insect with that weapon, replaced his handkerchief, settled his glasses, took up the book
again, but to his utter surprise the fly still remained. A light seemed now to dawn on him
—the fly had got crushed between the leaves—so he essayed to remove it with his
finger-nail; here his hopeful offspring could stand it no longer, and burst into a roar of
laughter, in which several others joined. When the joke was explained to the worthy
victim, he said: "Now, that's very good, isn't it; very good. I made sure it was a real fly,
as true as you live. Look here, wife; look at this, some of Master Tom's doing; good, ain't
it; as true as you live, that's a fact. Ah! Ha!"[A]
Later in the evening Young Hopeful horrified a circle of ladies by discovering at their
feet a huge spider; in the midst of their shrieks and exclamations a courageous
gentleman with large whiskers stepped forward to crush the intruder, raised his foot, and
brought it down firmly, but staggered back astounded—the creature had exploded with a
loud report, conveying an idea of vindictiveness and power truly appalling. The young
gentleman took us aside and explained the mystery, at the same time producing from his
pocket a small box containing some half-dozen similar spiders.
"I have them made on purpose for me," he said. "A German porter in our store first put
me up to it, and I told him to set to work and make me as many as he liked, and charge
me any price he chose. I tell ye, that Dutchman thinks I'm a great boy. I pay him about
five dollars a week for spiders; well, you know, that's a good deal for a man like him;
only gets twelve dollars a week in the store."
We examined the specimen carefully, and found it was constructed very much on the
plan of the torpedoes used by children on the Fourth of July; only the paper was brown
and a little thicker, and there were legs of fine wire attached, which gave it a very lifelike
and spidery appearance. The Dutchman had evidently gone into the matter con amore,
for he had taken the pains to wash some of his specimens with gum, and then sprinkle
them with wool-dust to produce the appearance of what are called hairy spiders. About
one-third of a grain of fulminating silver produces the explosion in each. They are very
easily made.
As we steamed back to the great city of New York next day, Nix said he thought we
had made a very good investment of three red-hot days of mid-summer time. We
thought so, too.
[A] We have since seen a somewhat similar trick played by painting a fly on the
face of a watch or inside the glass.
CHAPTER XXIV.
We are not a great advocate for arithmetical puzzles as a pastime for festive occasions,
that is to say not as a general rule; but there are certain tricks of figures which are quite
amusing, and some few problems which from their very simplicity become almost
ludicrous. We have seen many a tolerably wise head puzzled over the question:
"If a barrel of flour cost thirty-nine dollars thirteen and three quarter cents, what will a
penny loaf come to?"
And consume considerable time and paper without discovering the obvious fact, that a
penny loaf will of course come to a penny and nothing else.
We remember, too, an amiable Divine, who tortured his dear old head for three-
quarters of an hour to solve the question:
"If a shovel, poker, and tongs, cost thirteen dollars forty-three and a quarter cents,
what will a ton of coals come to?"
And when informed that they would come to ashes, he seemed to feel quite hurt; and
indeed, to labor for some time under a sense of having been trifled with. When told that
it was merely a joke, a little fun, he replied that he was a great admirer of Don Quixote,
could appreciate Gil Bias, and relished exceedingly the wit of Swift and Sterne; but failed
to perceive the particular humor of our joke about the ton of coals.
With all due respect for the estimable prelate, we must venture to differ from him,
fortified as we are in our opinion by a young lady, who, if not a divine herself, has a pair
of eyes that are, in whose company we have solved some of the most intricate
arithmetical jocularities and trivialities, till we were up to the eyes in ink and love. One we
well remember, partly because it gave us so much trouble, and partly because there was
a wild picturesqueness about the subject which appeals to our imagination. It ran thus:
A man has a wolf, a goat, and a cabbage, to carry over a river, but he can only convey
them one at a time, his boat being very small. How is he to manage this, so that the wolf
may not be left alone with the goat, nor the goat with the cabbage? It is obvious if the
wolf be left with the goat, he will eat it up; whilst if the goat be left with the cabbage,
short work will be made of that classic vegetable.
Oh, how often we crossed and recrossed that river; how often we took the goat out,
and put the wolf in; and how frequently we took out the wolf, and put in the goat. How
we trembled for the poor man, fearing there could be no alternative for him but to
sacrifice either the goat or the cabbage, or else kill the wolf. How varied and wild were
our expedients, such as throwing the wolf across, sending the cabbage round by express,
digging a tunnel under the bed of the river, forcing the proprietor to eat the cabbage
himself, towing the goat behind the boat, and other devices too numerous to mention, all
of which we were assured, by those holding the key to the mystery, were altogether
inadmissible; and then when, with humbled pride, we reluctantly gave it up, how mad we
were at the simplicity of the solution, which was this:
He first takes over the goat, and then returns for the wolf; he then takes back the
goat, which he leaves, and takes over the cabbage, he then returns and takes over the
goat All as simple as A, B, C, when you know how to do it; that knowing how to do it is
the great difficulty in ninety-nine out of every hundred things in this world.
Puzzles which involve long and laborious calculation are not in our line; they are too
suggestive of the school and the country room. Something like the following is good for
skirmishing:
PROBLEM.
Put down four nines, so that they will make one hundred.
After a short struggle you surrender at discretion, and in an instant get the
SOLUTION.
999/9
There is no delay, no tedious figuring up; you get your answer and are ready for
something fresh. Some such abstruse calculation as the following, for instance:
PROBLEM.
If a herring and a half cost three cents, how many will you get for a dollar?
To ladies, who as a general rule have not the organ of calculation very largely
developed, this will usually prove a poser. As the problem is to be solved by patience and
study, we will leave them to do it, or give it up, and proceed to the next
PROBLEM.
A gentleman sent his servant with a present of nine ducks in a box, upon which was
the following direction:—

"To Alderman Gobble with IX. ducks."

The servant, who had more ingenuity than honesty, purloined three of the ducks, and
contrived it so that the number contained in the box corresponded with that upon the
direction. As he neither erased any word or letter, nor substituted a new direction, how
did he so alter it as to correspond with the contents of the box?
The dishonest but ingenious servant simply placed the letter S before the two Roman
numerals, IX. The direction then read thus:

"To Alderman Gobble, with SIX ducks."

It will be seen that this problem is very easy of solution to every one, save Artemus
Ward, who would spell it Sicks dux in a bocks.
Here is one, however, which would suit the taste, if not the ability, of the great
showman to a nicety:
PROBLEM.
To distribute among three persons twenty-one casks of wine, seven of them full, seven
of them empty, and seven of them half full; so that each of them shall have the same
quantity of wine, and the same number of casks.
This problem admits of two solutions, which may be clearly comprehended by means
of the two following tables:
FIRST SOLUTION.
Persons. Full casks. Empty. Half full.
1 2 2 3
2 2 2 3
3 3 3 1

SECOND SOLUTION.
Persons. Full casks. Empty. Half full.
1 3 3 1
2 3 3 1
3 1 1 5
One more problem, and we shall have had enough mathematics for one chapter.

A figure similar to the preceding can be formed without removing the pencil from the
paper, without crossing any line or retracing any part. Now set to work and do it.
If you do not succeed, you may refer to the annexed diagram and solution.
Draw a line from 1 to 2, 2 to 3, 3 to 4, 4 to 5, 5 to 6, 6 to 1, 1 to 7, 7 to 8, 8 to 9, 9 to
3, 3 to 10, and 10 to 1.
CHAPTER XXV.
We have observed that Tableaux and Charades run in some families, and that these
families are always ready to spend any amount of time and money to carry out their
favorite ideas; we cannot help feeling considerable admiration for any one having some
honest enthusiasm for any amusement in this toiling age of ours. But our mission is not
to deal much with the costly or complicated. Those who wish to produce tableaux from
Waverley or the Bride of Abydos, who desire to attire themselves as Mary Queen of
Scots, Di Vernon, or Dolly Varden, we leave to their own devices, giving only our best
wishes. There are, however, charades to be got up on the spur of the moment, which are
not less entertaining than the more elaborate performances to which we allude. We will
mention one or two which have come under our observation during a chequered
existence; they may serve to give the key-note, if nothing more.
On the occasion of a certain impromptu party, the lady of the house begged some of
her guests to get up something which would entertain the rest, some charades, or what
not. Two gentlemen consulted for a moment, and then took up their positions in the back
of the parlor, which represented the stage. One sat down to read, whilst the other crept
up slyly behind him, and much to his dismay turned off the gas. They then both rose and
declared the charade completed, leaving it to the audience to divine the answer. Whether
any one guessed it or not we do not know—but the answer was Gastric—Gas-trick.
Another gentleman then stepped into the stage, with a large hat at the back of his
head, and began calling—"Mooley, mooley, mooley; com, com, mooley. Where kin that
keow a poked herself now? she's allers a concealing of herself somewheres or another—
mooley," etc.,
His riddle was now concluded, and he desired the audience to give him the answer.
The answer was Cow-hiding.
A famous physician and wit was the next to come forward, accompanied by a friend.
They took positions in opposite corners of the room, advanced towards each other, and
as they passed, the friend said to the doctor, "How do, Doctor?" To the surprise of all,
they declared the charade completed. No one could guess it, of course; the answer was
metaphysician, met-a-physician.
Again they took their positions precisely as before, announcing that they were about to
give another charade. Again they walked across the room, and as they passed, one said
to the other, "How do, again?" This was the conclusion of the second charade; quite as
puzzling as the first, only more so. The answer was metaphor—met-afore. This absurdity
was received with roars of laughter and thunders of applause.
Charades of this kind, we are inclined to think, give more real pleasure after all, than
the studied, costly elaborations. They are perhaps not so pretty; but, ye gods! where
there are pretty women, what else could mortal man desire in the way of beauty!
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like