28075

Download as pdf or txt
Download as pdf or txt
You are on page 1of 55

Download the Full Version of textbook for Fast Typing at textbookfull.

com

Java EE Web Application Primer: Building Bullhorn:


A Messaging App with JSP, Servlets, JavaScript,
Bootstrap and Oracle 1st Edition Dave Wolf

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/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Biota Grow 2C gather 2C cook Loucas

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

textboxfull.com

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/
textboxfull.com

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/

textboxfull.com

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/

textboxfull.com
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/

textboxfull.com

Building web and mobile ArcGIS Server applications with


JavaScript Lewin

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

textboxfull.com

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/

textboxfull.com

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/
textboxfull.com

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/

textboxfull.com
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
Berlepsch, after weary hours of watching—but that she can thus
control at the instant this process of adding or withholding the sperm-
cells, certainly seems not so strange as that the spermatheca, hardly
bigger than a pin-head, could supply these cells for months, yes, and
for years. Who that has seen the bot-fly dart against the horse's legs,
and as surely leave the tiny yellow egg, can doubt but that insects
possess very sensitive oviducts, and can extrude the minute eggs
just at pleasure. That a queen may force single eggs, at will, past the
mouth of the spermatheca, and at the same time add or withhold the
sperm-cells, is, I think, without question, true. What gives added
force to this view, is the fact that other bees, wasps and ants
exercise the same volition, and can have no aid from cell-pressure,
as all the eggs are laid in receptacles of the same size. But the
Baron of Berlepsch, worthy to be a friend of Dzierzon, has fully
decided the matter. He has shown that old drone cells are as small
as new worker-cells, and yet each harbors its own brood. Very small
queens, too, make no mistakes. With no drone-cells, the queen will
sometimes lay drone-eggs in worker-cells, in which drones will then
be reared. And will, if she must, though with great reluctance, lay
worker-eggs in drone-cells.
Before laying an egg, the queen takes a look into the cell,
probably to see if all is right. If the cell contains any honey, pollen, or
an egg, she usually passes it by, though when crowded, a queen will
sometimes, especially if young, insert two or three eggs in a cell, and
sometimes, in such cases, she drops them, when the bees show
their dislike of waste, and appreciation of good living, by making a
breakfast of them. If the queen finds the cell to her liking, she turns
about, inserts her abdomen, and in an instant the tiny egg is glued,
in position (Fig, 26, b) to the bottom of the cell.
The queen, when considered in relation to the other bees of the
colony, possesses a surprising longevity. It is not surprising for her to
attain the age of three years in the full possession of her powers,
while they have been known to do good work for five years. Queens,
often at the expiration of one, two, three or four years, depending on
their vigor and excellence, either cease to be fertile, or else become
impotent to lay impregnated eggs—the spermatheca having become
emptied of its sperm-cells. In such cases the workers usually
supersede the queen; that is they destroy the old queen, ere all the
worker-eggs are gone, and take of the few remaining ones to start
queen-cells, and thus rear young, fertile and vigorous queens.
It sometimes happens, though rarely, that a fine-looking queen,
with full-formed ovaries, and large spermatheca, well-filled with male
fluid, will deposit freely, but none of the eggs will hatch. Readers of
the bee-publications know that I have frequently received such for
dissection. The first I ever got was a remarkably fine-looking Italian,
received from the late Dr. Hamlin, of Tennessee. All such queens
that I have examined seem perfect, even though scrutinized with a
high-power objective. We can only say that the egg is at fault, as
frequently transpires with higher animals, even to the highest. These
females are barren; through some fault with the ovaries, the eggs
grown therein are sterile. To detect just what is the trouble with the
egg is a very difficult problem, if it is capable of solution at all. I have
tried to determine the ultimate cause, but without success.
The function of the queen is simply to lay eggs, and thus keep
the colony populous; and this she does with an energy that is fairly
startling. A good queen in her best estate will lay two or three
thousand eggs a day. I have seen a queen in my observing hive, lay
for some time at the rate of four eggs per minute, and have proved
by actual computation of brood cells, that a queen may lay over
three thousand eggs in a day. Langstroth and Berlepsch both saw
queens lay at the rate of six eggs a minute.
The latter had a queen that laid three thousand and twenty-one
eggs in 24 hours, by actual count, and in 20 days she laid fifty-seven
thousand. This queen continued prolific for five years, and must have
laid, says the Baron, at a low estimate, more than 1,300,000 eggs.
Dzierzon says queens may lay 1,000,000 eggs, and I think these
authors have not exaggerated. Yet, with even these figures as an
advertisement, the queen bee cannot boast of superlative fecundity,
as the queen white-ant—an insect closely related to the bees in
habits, though not in structure, as the white-ants are lace-wings and
belong to the sub-order Neuroptera, which includes our day-flies,
dragon-flies, etc.—is known to lay over 80,000 eggs daily. Yet this
poor helpless thing, whose abdomen is the size of a man's thumb,
and composed almost wholly of eggs, while the rest of her body is
not larger than the same in our common ants, has no other
amusement; she cannot walk; she cannot even feed herself or care
for her eggs. What wonder then that she should attempt big things in
the way of egg-laying? She has nothing else to do, or to feel proud
of.
Different queens vary as much in fecundity as do different breeds
of fowls. Some queens are so prolific that they fairly demand hives of
India rubber to accommodate them, keeping their hives gushing with
bees and profitable activity while others are so inferior, that the
colonies make a poor, sickly effort to survive at all, and usually
succumb early, before those adverse circumstances which are ever
waiting to confront all life on the globe. The activity of the queen, too,
is governed largely by the activity of the workers. The queen will
either lay sparingly, or stop altogether, in the interims of storing
honey, while, on the other hand, she is stimulated to lay to her
utmost capacity, when all is life and activity in the hive.
It would seem that the queen either reasons from conditions, is
taught by instinct, or else that without her volition the general activity
of the worker-bees stimulates the ovaries, how, we know not, to grow
more eggs. We know that such a stimulus is born of desire, in case
of the high-holder, already referred to. That the queen may have
control of the activity of her ovaries, either directly or indirectly,
through reflex nervous action induced by the general excitement of
the bees, which always follows active storing, is not only possible,
but quite likely.
The old poetical notion that the queen is the revered and admired
sovereign of the colony, whose pathway is ever lined by obsequious
courtiers, whose person is ever the recipient of loving caresses, and
whose will is law in this bee-hive kingdom, controlling all the
activities inside the hive, and leading the colony whithersoever they
may go, is unquestionably mere fiction. In the hive, as in the world,
individuals are valued for what they are worth. The queen, as the
most important individual, is regarded with solicitude, and her
removal or loss noted with consternation, as the welfare of the
colony is threatened; yet, let the queen become useless, and she is
despatched with the same absence of emotion that characterizes the
destruction of the drones when they have become supernumeraries.
It is very doubtful if emotion or sentimentality are ever moving forces
among the lower animals. There are probably certain natural
principles that govern in the economy of the hive, and aught that
conspires against, or tends to intercept the action of these principles,
becomes an enemy to the bees. All are interested, and doubtless
more united than is generally believed, in a desire to promote the
free action of these principles. No doubt the principle of antagonism
among the various bees has been overrated. Even, the drones,
when they are being killed off in the autumn, make a sickly show of
defense, as much as to say, the welfare of the colony demands that
such worthless vagrants should be exterminated; "so mote it be;" go
ahead. The statement, too, that there is often serious antagonism
between the queen and workers, as to the destruction or
preservation of inchoate queens, yet in the cell, is a matter which
may well be investigated. It is most probable that what tends most
for the prosperity of the colony is well understood by all, and without
doubt there is harmonious action among all the denizens of the hive,
to foster that which will advance the general welfare, or to make war
on whatever may tend to interfere with it. If the course of any of the
bees seems wavering and inconsistent, we may rest assured that
circumstances have changed, and that could we perceive the
bearing of all the surrounding conditions, all would appear consistent
and harmonious.
Fig. 17.

Drone Bee, magnified.

THE DRONES.

These are the male bees, and are generally found in the hive
only from May to November: though they may remain all winter, and
are not infrequently absent during the summer. Their presence or
absence depends on the present and prospective condition of the
colony. If they are needed, or likely to be needed, then they are
present. There are in nature several hundred in each colony. The
number may and should be greatly reduced by the apiarist. These
(Fig, 17) are shorter than the queen, being less than three-fourths of
an inch in length, are more robust and bulky than either the queen or
workers, and are easily recognized when flying by their loud, startling
hum. As in other societies, the least useful make the most noise.
This loud hum is caused by the less rapid vibration of their large,
heavy wings. Their flight is more heavy and lumbering than that of
the workers. Their ligula, labial palpi, and maxillæ—like the same in
the queen bee—are short, while their jaws (Fig, 21, a) possess the
rudimentary tooth, and are much the same in form as those of the
queen, but are heavier, though not so strong as those of the workers.
Their eyes (Fig, 4) are very prominent, meet above, and thus the
simple eyes are thrown forward. Their posterior legs are convex on
the outside (Fig, 18), so, like the queens, they have no pollen
baskets. The drones are without the defensive organ, having no
sting, while their special sex-organs (Fig, 10) are not unlike those of
other insects, and have already been sufficiently described.

Fig. 18.

Part of Leg of Drone, magnified.


t—Tibia.
p—Broadened tibia and basal tarsus.
t s—Joints of Tarsus,
c—Claws.
It was discovered by Dzierzon, in 1845, that the drones hatch
from unimpregnated eggs. This strange phenomenon, seemingly so
incredible, is as has been shown in speaking of the queen, easily
proved and beyond question. These eggs may come from an
unimpregnated queen, a fertile worker—which will soon be further
described—or from an impregnated queen, which may voluntarily
prevent impregnation. Such eggs may be placed in the larger
horizontal cells (Fig, 28, a), in manner already described. As stated
by Bevan, the drone feeds six and a half days as a larva, before the
cell is capped. The capping of the drone-cells is very convex, and
projects beyond the plane of the same in worker-cells, so that the
drone brood is easily distinguished from worker, and from the darker
color—the wax being thicker and less pure—the capping of both
drone and worker brood-cells enable us easily to distinguish them
from honey-cells. In twenty-four days from the laying of the egg, the
drones come forth from the cells. Of course variation of temperature,
and other conditions, as variable amount of diet, may slightly retard
or advance the development of any brood, in the different stages.
The drones—in fact all bees—when they first emerge from the cells,
are gray, soft, and appear generally unsophisticated.
Just what the longevity of the male bee is, I am unable to state. It
is probable, judging from analogy, that they live till accident, the
worker bees, or the performance of their natural function causes
their death. The worker-bees are liable to kill off the drones, which
they do by constantly biting and worrying them. They may also
destroy the drone-brood. It is not very rare to see workers carrying
out immature drones even in mid-summer. At the same time, too,
they may destroy inchoate queens. Such action is prompted by a
sudden check in the yield of honey, and with the drones is most
common at the close of the season. The bees seem very cautious
and far-sighted. If the signs of the times presage a famine, they stay
all proceedings looking to the increase of colonies. On the other
hand, unlimited honey, rapid increase of brood, crowded quarters—
whatever the age of the queen—is sure to bring many of the male
bees. While any circumstances that indicate a future need of drones
will prevent their destruction even in late autumn.
The function of the drones is solely to impregnate the queen,
though when present they may add animal heat. That their nutrition
is active, is suggested by the fact, that upon dissection, we always
find their capacious stomachs filled with honey.
Impregnation of the queen always takes place, as before stated,
while on the wing, outside the hive, usually during the heat of warm
sunshiny days. After mating, the drone organs adhere to the queen,
and may be seen hanging to her for some hours. The copulatory act
is fatal to the drones. By holding a drone in the hand, the ejection of
the sex-organs is often produced, and always followed by immediate
death. As the queen only meets a single drone, and that only once, it
might be asked why nature was so improvident as to decree
hundreds of drones to an apiary or colony, whereas a score would
suffice as well. Nature takes cognizance of the importance of the
queen, and as she goes forth amidst the myriad dangers of the outer
world, it is safest and best that her stay abroad be not protracted;
that the experience be not repeated, and especially, that her meeting
a drone be not delayed. Hence the superabundance of drones—
especially under natural conditions, isolated in forest homes, where
ravenous birds are ever on the alert for insect game—is most wise
and provident. Nature is never "penny wise and pound foolish." In
our apiaries the need is wanting, and the condition, as it exists in
nature, is not enforced.
The fact that parthenogenesis prevails in the production of the
drones, has led to the theory that from a pure queen, however
mated, must ever come a pure drone. My own experience and
observation, which I believe are those of all apiarists, has confirmed
this theory. Yet, if the impure mating of our cows, horses, and fowls,
renders the females of mixed blood ever afterward, as is believed
and taught by many who would seem most competent to judge—
though I must say I am somewhat skeptical in the matter—then we
must look closely as to our bees, for certainly, if a mammal, and
especially a fowl, is tainted by impure mating, then we may expect
the same of insects. In fowls such influence, if it exists, must come
simply from the presence in the female generative organs of the
germ-cells, or spermatozoa, and in mammals, too, there is little more
than this, for though they are viviparous, so that the union and
contact of the offspring and mother seems very intimate, during fœtal
development, yet there is no intermingling of the blood, for a
membrane ever separates that of the mother from that of the fœtus,
and only the nutritious and waste elements pass from one to the
other. To claim that the mother is tainted through the circulation, is
like claiming that the same result would follow her inhaling the breath
of her progeny after birth. I can only say, that I believe this whole
matter is still involved in doubt, and still needs more careful, scientific
and prolonged observation.
THE NEUTERS, OR WORKER-BEES.

These, called "the bees," by Aristotle, and even by Wildman and


Bevan, are by far the most numerous individuals of the hive—there
being from 15,000 to 40,000 in every good colony. It is possible for a
colony to be even much more populous than this. These are also the
smallest bees of the colony, as they measure but little more than
one-half of an inch in length (Fig, 19).

Fig. 19.

Worker-Bee,
magnified.
The workers—as taught by Schirach, and proved by Mlle. Jurine,
of Geneva, Switzerland, who, at the request of Huber, sought for and
found, by aid of her microscope, the abortive ovaries—are
undeveloped females. Rarely, and probably very rarely, except that a
colony is long or often queenless, as is frequently true of our nuclei,
these bees are so far developed as to produce eggs, which, of
course, would always be drone eggs. Such workers—known as
fertile—were first noticed by Riem, while Huber actually saw one in
the act of egg-laying. Except in the power to produce eggs, they
seem not unlike the other workers. Huber supposed that these were
reared in cells contiguous to royal cells, and thus received royal food
by accident. The fact, as stated by Mr. Quinby, that these occur in
colonies where queen-larvæ were never reared, is fatal to the above
theory. Langstroth and Berlepsch thought that these bees, while
larvæ, were fed, though too sparingly, with the royal aliment, by bees
in need of a queen, and hence the accelerated development. Such
may be the true explanation. Yet if, as some apiarists aver, these
appear where no brood has been fed, and so must be common
workers, changed after leaving the cell, as the result of a felt need,
then we must conclude that development and growth—as with the
high-holder—spring from desire. The generative organs are very
sensitive, and exceedingly susceptible to impressions, and we may
yet have much to learn as to the delicate forces which will move
them to growth and activity. Though these fertile workers are a poor
substitute for a queen, as they are incapable of producing any but
drones, and are surely the harbingers of death and extinction to the
colony, yet they seem to satisfy the workers, for they will not brook
the presence of a queen when a fertile worker is in the hive, nor will
they suffer the existence in the hive of a queen-cell, even though
capped. They seem to be satisfied, though they have very slight
reason to be so. These fertile workers lay indifferently in large or
small cells—often place several eggs in a single cell, and show their
incapacity in various ways.
Fig. 20.

Tongue of a Worker-Bee, much magnified.


a—Ligula. c, c—Maxillæ.
b, b—Labial palpi. d—Paraglossæ.
[The average length of a black worker's tongue, as
compared
with this from an Italian, would be from base to a.]
The workers, as might be surmised by the importance and variety
of their functions, are structurally very peculiar Their tongues (Fig,
20, a), labial palpi (Fig. 20, b, b), and maxillæ (Fig. 20, c, c), are very
much elongated, while the former is very hairy, and doubles under
the throat when not in use. The length of the ligula enables them to
reach into flowers with long tubes, and by aid of the hairs they lap up
the nectar. When the tongue is big with its adhering load of sweet, it
is doubled back, enclosed by the labial palpi and maxillæ, and then
extended, thus losing its load of nectar, which at the same time is
sucked into the large honey-stomach. The bees, at will, can force the
honey back from the honey-stomach, when it is stored in the honey-
cells or given to the other bees.

Fig. 21.

a—Jaw of drone.b—Jaw of queen. c—Jaw of worker.

The jaws (Fig, 21, c) are very strong, without the rudimentary
tooth, while the cutting edge is semi-conical, so that when the jaws
are closed they form an imperfect cone. Thus these are well formed
to cut comb, knead wax, and perform their various functions. Their
eyes (Fig, 5) are like those of the queen, while their wings, like those
of the drones, attain the end of the body. These organs (Fig, 3), as in
all insects with rapid flight, are slim and strong, and, by their more or
less rapid vibrations, give the variety of tone which characterizes
their hum. Thus we have the rapid movements and high pitch of
anger, and the slow motion and mellow note of content and joy.
Fig. 22.

Part of Posterior Leg of Worker, outside,


much magnified.
t—Tibia. t s—Joint of tarsi,
b—Rim of hairs. c—Claws.
p—Pollen basket.
On the outside of the posterior tibia and basal tarsus is a cavity,
made more deep by its rim of hairs, known as the pollen basket (Fig,
22, p). In these pollen baskets is compacted the pollen, which is
gathered by the mouth organs, and carried back by the four anterior
legs. Opposite the pollen baskets are regular rows of golden hairs
(Fig. 23, e), which probably aid in storing and compacting the pollen
balls.
On the anterior legs of the workers, between the femur and tibia,
is a curious notch (Fig. 24, C), covered by a spur (Fig. 24, B). For
several years this has caused speculation among my students, and
has attracted the attention of observing apiarists. Some have
supposed that it aided bees in reaching deeper down into tubular
flowers, others that it was used in scraping off pollen, and still others
that it enabled bees to hold on when clustering. The first two
functions may belong to this, though other honey and pollen-
gathering bees do not possess it. The latter function is performed by
the claws at the end of the tarsi.

Fig. 23.

Part of Worker's Posterior Leg, inside,


much magnified.
e—Rows of hairs.
t—Tibia.
c—Claws.

Fig. 24.

Anterior Leg of Worker,


magnified.
Fig. 25.

Worker's Sting, magnified.


a—Tube.
b b—Barbed spears drawn out of tube and turned back,
c—Poison sack.
d—Muscles.
The workers, too, possess an organ of defense (Fig, 25), which
they are quick to use if occasion requires. This is not curved as in
the queen, but straight. The gland which secretes the poison is
double, and the sack (Fig, 25, c), in which it is stored, is as large as
a flax-seed. The sting proper, is a triple organ, consisting of three
sharp spears, very smooth and of exquisite polish. The most highly-
wrought steel instruments, under a high magnifier, look rough and
unfinished, while the parts of the sting show no such inequalities.
One of these spears (Fig, 25, a) is canaliculate—that is, it forms an
imperfect tube—and in this canal work the other two (Fig. 25, b, b),
which fill the vacant space, and thus the three make a complete
tube, and through this tube, which connects with the poison sack,
passes the poison. The slender spears which work in the tube are
marvelously sharp, and project beyond it when used, and are worked
alternately by small but powerful muscles (Fig. 25, d), so they may
pass through buckskin, or even the thick scarf-skin of the hand.
These are also barbed at the end with teeth, seven of which are
prominent, which extend out and back like the barb of a fish-hook.
Hence the sting cannot be withdrawn, if it penetrates any firm
substance, and so when used, it is drawn from the bee, and carries
with it a portion of the alimentary canal, thus costing the poor bee its
life. Darwin suggests that bees and wasps were developed from the
saw-flies, and that the barbs on the sting are the old-time saws,
transformed into the spear-like barbs. He does not explain why these
are so much shorter and more obscure in the queen, and in other
bees and wasps. The honey-stomach or crop in the workers (Fig, 9,
o) is well developed, though no larger than those in the drones.
Whether it is more complex in structure, I do not know.
The workers hatch from an impregnated egg, which can only
come from a queen that has met a drone, and is always laid in the
small, horizontal cell. These eggs are in no wise different, so far as
we can see, from those which are laid in the drone or queen-cells. All
are cylindrical and slightly curved (Fig, 26, b, c) and are fastened by
one end to the bottom of the cell, and a little to one side of the
centre. As already shown, these are voluntarily fertilized by the
queen as she extrudes them, preparatory to fastening them in the
cells. These eggs, though so small—one-sixteenth of an inch long—
may be easily seen by holding the comb so that the light will shine
into the cells. With experience, they are detected almost at once, but
I have often found it quite difficult to make the novice see them,
though very plainly visible to my experienced eye.
Fig. 26.

Egg and Brood.


b and c—Eggs.
d, e, f and g—Various sizes of
larvæ.
h—Pupa.
i—Pupa of queen, in queen-
cell.
k, k—Caps.

The egg hatches in three days. The larva (Fig, 26, d, e, f, g),
incorrectly called grub, maggot—and even caterpillar, by Hunter—is
white, footless, and lies coiled up in the cell till near maturity. It is fed
a whitish fluid, though this seems to be given grudgingly, as it never
seems to have more than it wishes to eat, so it is fed quite frequently
by the mature workers. It would seem that the workers fear an
excessive development, which, as we have seen, is most
mischievous and ruinous, and work to prevent the same, by a mean
and meager diet. The food is composed of pollen and honey.
Certainly of pollen, for, as I have repeatedly proved, without pollen,
no brood will be reared. Probably some honey is incorporated, as
sugar is an essential in the nutrition of all animals, and we could
hardly account for the excessive amount of honey consumed, while
breeding, by the extra amount consumed by the bees, consequent
upon the added exercise required in caring for the brood. M. Quinby,
Doolittle, and others, say water is also an element of this food. But
bees often breed very rapidly when they do not leave the hive at all,
and so water, other than that contained in the honey, etc., cannot be
added. This makes it a question if water is ever added. The time
when bees seem to need water, and so repair to the rill and the
pond, is during the heat of summer, when they are most busy. May
this not be quaffed to slake their own thirst?
In six days the cell is capped over by the worker-bees. This cap
is composed of pollen and wax, so it is darker, more porous, and
more easily broken than the caps of the honey-cells; it is also more
convex (Fig, 26, k). The larva, now full grown, having lapped up all
the food placed before it, surrounds itself with a silken cocoon, so
excessively thin that it requires a great number to appreciably reduce
the size of the cells. These always remain in the cell, after the bees,
escape, and give to old comb its dark color and great strength. Yet
they are so thin, that cells used even for a dozen years, seem to
serve as well for brood as when first used. In three days the insect
assumes the pupa state (Fig, 26, h). In all insects the spinning of the
cocoon seems an exhaustive process, for so far as I have observed,
and that is quite at length, this act is succeeded by a variable period
of repose. The pupa is also called a nymph. By cutting open cells it
is easy to determine just the date of forming the cocoon, and of
changing to the pupa state. The pupa looks like the mature bee with
all its appendages bound close about it, though the color is still
whitish:
In twenty-one days the bee emerges from the cell. The old writers
were quite mistaken in thinking that the advent of these was an
occasion of joy and excitement among the bees. All apiarists have
noticed how utterly unmoved the bees are, as they push over and
crowd by these new-comers in the most heedless and discourteous
manner imaginable. Wildman tells of seeing the workers gathering
pollen and honey the same day that they came forth from the cells.
This idea is quickly disproved if we Italianize black-bees. We know
that for some days these young bees do not leave the hive at all,
except in case of swarming, when bees even too young to fly will
essay to go with the crowd. These young bees, like the young
drones and queens, are much lighter for the first few days.
The worker-bees never attain a great age. Those reared in
autumn may live for eight or nine months, and if in queenless stocks,
where little labor is performed, even longer; while those reared in
spring will wear out in three, and when most busy, will often die in
from thirty to forty-five days. None of these bees survive the year
through, so there is a limit to the number which may exist in a colony.
As a good queen will lay, when in her best estate, three thousand
eggs daily, and as the workers live from one to three months, it might
seem that forty thousand was too small a figure for the number of
workers. Without doubt a greater number is possible. That it is rare is
not surprising, when we remember the numerous accidents and
vicissitudes that must ever attend the individuals of these populous
communities.
The function of the worker-bees is to do all the manual labor of
the hives. They secrete the wax, which forms in small pellets (Fig,
27, a, a) under the over-lapping rings under the abdomen. I have
found these wax-scales on both old and young. According to Fritz
Müller, the admirable German observer, so long a traveler in South
America, the bees of the genus melipona secrete the wax on the
back.
The young bees build the comb, ventilate the hive, feed the larvæ
and cap the cells. The older bees—for, as readily seen in Italianizing,
the young bees do not go forth for the first one or two weeks—gather
the honey, collect the pollen, or bee-bread, as it is generally called,
bring in the propolis or bee glue, which is used to close openings,
and as a cement, supply the hive with water(?), defend the hive from
all improper intrusion, destroy drones when their day of grace is
past, kill and arrange for replacing worthless queens, destroy
inchoate queens, drones, or even workers, if circumstances demand
it, and lead forth a portion of the bees when the conditions impel
them to swarm.
When there are no young bees, the old bees will act as house-
keepers and nurses, which they otherwise refuse to do. The young
bees, on the other hand, will not go forth to glean, even though there
be no old bees to do this necessary part of bee-duties. An indirect
function of all the bees is to supply animal heat, as the very life of the
bees require that the temperature inside the hive be maintained at a
rate considerably above freezing. In the chemical processes
attendant upon nutrition, much heat is generated, which, as first
shown by Newport, may be considerably augmented at the pleasure
of the bees, by forced respiration. The bees, too, by a rapid vibration
of their wings, have the power to ventilate their hives, and thus
reduce the temperature, when the weather is hot. Thus they
moderate the heat of summer, and temper the cold of winter.

Under Surface of Bee, showing


Wax between Segments.
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