100% found this document useful (3 votes)
11 views

Java 8 Recipes 2nd Edition Josh Juneau download

The document provides information about the book 'Java 8 Recipes 2nd Edition' by Josh Juneau, including its content structure, intended audience, and key topics covered such as Java 8 features, JavaFX, and application development. It serves as a guide for both novice and experienced Java developers looking to enhance their skills and understanding of the Java programming language. Additionally, it includes links to other related Java resources and books authored by Juneau.

Uploaded by

koveralysagl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (3 votes)
11 views

Java 8 Recipes 2nd Edition Josh Juneau download

The document provides information about the book 'Java 8 Recipes 2nd Edition' by Josh Juneau, including its content structure, intended audience, and key topics covered such as Java 8 features, JavaFX, and application development. It serves as a guide for both novice and experienced Java developers looking to enhance their skills and understanding of the Java programming language. Additionally, it includes links to other related Java resources and books authored by Juneau.

Uploaded by

koveralysagl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 62

Java 8 Recipes 2nd Edition Josh Juneau download

https://textbookfull.com/product/java-8-recipes-2nd-edition-josh-
juneau/

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!

Java 9 Recipes: A Problem-Solution Approach 3rd Edition


Josh Juneau

https://textbookfull.com/product/java-9-recipes-a-problem-
solution-approach-3rd-edition-josh-juneau/

Java EE 7 Recipes A Problem Solution Approach 1st


Edition Juneau Josh

https://textbookfull.com/product/java-ee-7-recipes-a-problem-
solution-approach-1st-edition-juneau-josh/

Java 7 Recipes A Problem Solution Approach Juneau Josh


Beaty Mark Dea Carl Guime Freddy Oconner John

https://textbookfull.com/product/java-7-recipes-a-problem-
solution-approach-juneau-josh-beaty-mark-dea-carl-guime-freddy-
oconner-john/

Introducing Java EE 7 A Look at What s New Juneau Josh

https://textbookfull.com/product/introducing-java-ee-7-a-look-at-
what-s-new-juneau-josh/
JavaServer Faces Introduction by Example Juneau Josh

https://textbookfull.com/product/javaserver-faces-introduction-
by-example-juneau-josh/

All About Java 8 Lambdas Introducing Java 8 Lambdas 1st


Edition Konda

https://textbookfull.com/product/all-about-java-8-lambdas-
introducing-java-8-lambdas-1st-edition-konda/

Java Performance In Depth Advice for Tuning and


Programming Java 8 11 and Beyond 2nd Edition Scott Oaks

https://textbookfull.com/product/java-performance-in-depth-
advice-for-tuning-and-programming-java-8-11-and-beyond-2nd-
edition-scott-oaks/

Practical JSF in Java EE 8 Michael Müller

https://textbookfull.com/product/practical-jsf-in-java-
ee-8-michael-muller/

Java 8 Pocket Guide Instant Help for Java Programmers


1st Edition Liguori Robert Liguori Patricia

https://textbookfull.com/product/java-8-pocket-guide-instant-
help-for-java-programmers-1st-edition-liguori-robert-liguori-
patricia/
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
Contents at a Glance

About the Author ................................................................................................................xli


About the Technical Reviewers ........................................................................................xliii
Acknowledgments ............................................................................................................. xlv
Introduction ..................................................................................................................... xlvii

N Chapter 1: Getting Started with Java 8 .............................................................................1


N Chapter 2: New Features of Java 8..................................................................................29
N Chapter 3: Strings............................................................................................................49
N Chapter 4: Numbers and Dates ........................................................................................65
N Chapter 5: Object-Oriented Java .....................................................................................97
N Chapter 6: Lambda Expressions ....................................................................................133
N Chapter 7: Data Structures and Collections ..................................................................153
N Chapter 8: Input and Output ..........................................................................................187
N Chapter 9: Exceptions and Logging ...............................................................................207
N Chapter 10: Concurrency ...............................................................................................223
N Chapter 11: Debugging and Unit Testing .......................................................................249
N Chapter 12: Unicode, Internationalization, and Currency Codes ...................................263
N Chapter 13: Working with Databases ............................................................................283
N Chapter 14: JavaFX Fundamentals ................................................................................331
N Chapter 15: Graphics with JavaFX ................................................................................405
N Chapter 16: Media with JavaFX .....................................................................................445

v
N CONTENTS AT A GLANCE

N Chapter 17: JavaFX on the Web .....................................................................................473


N Chapter 18: Nashorn and Scripting ...............................................................................505
N Chapter 19: E-mail.........................................................................................................527
N Chapter 20: XML Processing .........................................................................................537
N Chapter 21: Networking ...............................................................................................553
N Chapter 22: Security ......................................................................................................571

Index .................................................................................................................................579

vi
Introduction

The Java programming language was introduced in 1995 by Sun Microsystems. Derived from languages such as
C and C++, Java was designed to be more intuitive and easier to use than older languages, specifically due to its
simplistic object model and automated facilities such as memory management. At the time, Java drew the interest
of developers because of its object oriented, concurrent architecture; its excellent security and scalability; and
because applications developed in the Java language could run on any operating system that contained a Java Virtual
Machine (JVM). Since its inception, Java has been described as a language that allows developers to “write once, run
everywhere” as code is compiled into class files that contain bytecode, and the resulting class files can run on any
compliant JVM. This concept made Java an immediate success for desktop development, which later branched off into
different technological solutions over the years, including development of web-based applications and rich Internet
applications (RIAs). Today, Java is deployed on a broad range of devices, including mobile phones, printers, medical
devices, Blu-ray players, and so on.
The Java platform consists of a hierarchy of components, starting with the Java Development Kit (JDK), which
is composed of the Java Runtime Environment (JRE), the Java programming language, and platform tools that are
necessary to develop and run Java applications. The JRE contains the Java Virtual Machine (JVM), plus the Java
application programming interfaces (APIs) and libraries that assist in the development of Java applications. The JVM
is the base upon which compiled Java class files run and is responsible for interpreting compiled Java classes and
executing the code. Every operating system that is capable of running Java code has its own version of the JVM. To that
end, the JRE must be installed on any system that will be running local Java desktop or stand-alone Java applications.
Oracle provides JRE implementations for most of the major operating systems. Each operating system can have its
own flavor of the JRE. For instance, mobile devices can run a scaled down version of the full JRE that is optimized
to run Java Mobile Edition (ME) and Java SE embedded applications. The Java platform APIs and libraries are a
collection of predefined classes that are used by all Java applications. Any application that runs on the JVM makes
uses the Java platform APIs and libraries. This allows applications to use the functionality that has been predefined
and loaded into the JVM and leaves developers with more time to worry about the details of their specific application.
The classes that comprise the Java platform APIs and libraries allow Java applications to use one set of classes in order
to communicate with the underlying operating system. As such, the Java platform takes care of interpreting the set
of instructions provided by a Java application into operating system commands that are required for the machine on
which the application is being executed. This creates a facade for Java developers to write code against so that they can
develop applications that can be written once and ran on every machine that contains a relevant JVM.
The JVM and the Java platform APIs and libraries play key roles in the lifecycle of every Java application. Entire
books have been written that explore the platform and JVM. This book focuses on the Java language itself, which is
used to develop Java applications, although the JVM and Java platform APIs and libraries are referenced as needed.
The Java language is a robust, secure, and modern object oriented language that can be used to develop applications
to run on the JVM. The Java programming language has been refined over several iterations and it becomes more
powerful, secure, and modern with each new release. This book covers many features of the Java programming
language from those that were introduced in Java 1.0 through those that made their way to the language in Java 8.
In 2014, Oracle Corporation released Java 8, which was another milestone release for the Java ecosystem. Not only was
Java already the most modern, statically typed, object oriented language available for development, but Java 8 adds
important new enhancements to the language, such as lambda expressions, streams processing, and default methods.
JavaFX 8 was also released at the same time, advancing desktop Java applications more than ever. JavaFX 8 can be
used for developing rich desktop and Internet applications using the Java language, or any other language that runs

xlvii
N INTRODUCTION

on the JVM. It provides a rich set of graphical and media user interfaces to develop extraordinary visual applications.
This release is another nice update to the JavaFX platform, adding in features such as the Swing node and the
Print API.
This book covers the fundamentals of Java development, such as installing the JDK, writing classes, and running
applications. It delves into essential topics such as the development of object oriented constructs, exception handling,
unit testing, and localization. The book also provides solutions for desktop application development using the JavaFX,
and some web-based and database solutions. It covers JavaFX 8 in depth and is an essential guide for developers
beginning to use JavaFX 8. This book can be used as a guide for solving problems that ordinary Java developers may
encounter at some point. A broad range of topics is discussed, and the solutions to the problems that are covered
in this book are concise and to the point. If you are a novice Java developer, we hope that this book will help you get
started on your journey to working with one of the most advanced and widely used programming languages available
today. For those of you who have used the Java language for some time, we hope that this book will provide you with
updated material that is new to Java 8 and JavaFX 2.0 so that you can further refine your Java development skills.
We ensure that advanced Java application developers will also learn a thing or two regarding the new features of the
language and perhaps even stumble upon some techniques that were not used in the past. Whatever your skill level,
this book is good to have close at hand as a reference for solutions to those problems that you encounter in your daily
programming.

Who This Book Is For


This book is intended for all those who are interested in learning the Java programming language and/or already know
the language but would like some information regarding the new features included in Java SE 8 and JavaFX 8. Those
who have not yet programmed in the Java language can read this book, and it will allow them to start from scratch
to get up and running quickly. Intermediate and advanced Java developers who are looking to update their arsenal
with the latest features that Java SE 8 and JavaFX 8 make available to them can also read the book to quickly update
and refresh their skill set. Java desktop programmers will find this book useful for its content on developing desktop
applications using the JavaFX API. There are, of course, a myriad of other essential topics that will be useful to Java
developers of any type.

How This Book Is Structured


This book is structured so that it does not have to be read from cover to cover. In fact, it is structured so that developers
can chose which topics they want to read about and jump right to them. Each recipe contains a problem to solve,
one or more solutions to solve that problem, and a detailed explanation of how the solution works. Although some
recipes may build upon concepts that have been discussed in other recipes, they contain the appropriate references
so that the developer can find other related recipes that are beneficial to the solution. The book is designed to allow
developers to get up and running quickly with a solution so that they can be home in time for dinner.

xlviii
CHAPTER 1

Getting Started with Java 8

In this chapter we present a handful of recipes to help programmers who are new to the Java language, as well as
those having experience in other languages, become accustomed to Java 8. You will learn to install Java 8, and also
install an Interactive Development Environment (IDE) from which you’ll develop applications and experiment with
the solutions provided in this book. You will learn basics of Java such as how to create a class and how to accept
keyboard input. Documentation is often overlooked, but in this chapter you will quickly learn how to create great
documentation for your Java code.

N Note Java 8 Recipes is not intended as a complete tutorial. Rather, it covers key concepts of the Java language.
If you are truly new to Java, we recommend buying and reading one of the many Beginning Java books that are also
published by Apress.

1-1. Creating a Development Environment


Problem
You want to install Java and experiment with the language. You’d also like a reasonable IDE to use with it.

Solution
Install Java Development Kit 8 (JDK). That gives you the language and a compiler. Then install the NetBeans IDE to
provide a more productive working environment.
Java Standard Edition (Java SE) is sufficient for most recipes in this book. To download the release, visit the
following page on the Oracle Technology Network (OTN):

http://www.oracle.com/technetwork/java/javase/overview/index.html

Figure 1-1 shows the Downloads tab, and you can see the Java Platform download link and image prominently
on the page. Next to that link is an image for the NetBeans IDE, which provides the option of downloading the JDK
and NetBeans together. Choose the option that you prefer, download the release for your platform, and run the setup
wizard to install.

1
CHAPTER 1 N GETTING STARTED WITH JAVA 8

Figure 1-1. Java SE Downloads page on the Oracle Technology Network

N Note If you chose to only install the Java Platform (JDK) and not NetBeans, you can download NetBeans at a later
time by visiting netbeans.org.

How It Works
The name Java™ is a trademark owned by Oracle Corporation. The language itself is open source, and its evolution is
controlled by a process known as the Java Community Process SM (JCP SM). You can read more about that process at
www.jcp.org.
There are many editions of Java, such as the Mobile Edition (ME) and the Enterprise Edition (EE). Java SE
is the Standard Edition and represents the heart of the language. We’ve built the recipes in this book for Java SE
programmers. Those interested in the development of mobile or embedded applications may be interested in
learning more about Java ME. Similarly, those interested in developing web applications and working with enterprise
solutions may be interested in learning more about Java EE.

N Note Enterprise Edition programmers may want to buy and read a copy of Java EE 7 Recipes (Apress, 2013).

There are several good websites that you can visit to learn more about Java and keep up-to-date with the latest on
the platform. A good place to begin for all things Java is the following page on the Oracle Technology Network:

http://www.oracle.com/technetwork/java/index.html

The wealth of resources available from this page can be overwhelming at first, but it’s worth your time to look
around and get passingly familiar with the many links that are available.
One of the links will be to Java SE, which takes you to the page shown earlier in Figure 1-1. It is from there that
you can download Java SE and the NetBeans IDE. Also from there you have access to the official documentation,
to community resources such as forums and newsletters, and to training resources designed to help you build
knowledge in Java and become certified in the language.

2
CHAPTER 1 N GETTING STARTED WITH JAVA 8

1-2. Getting to “Hello, World”


Problem
You’ve installed Java SE 8 and the NetBeans IDE. Now you want to run a simple Java program to verify that your
installation is working properly.

Solution
Begin by opening the NetBeans IDE. You should see a workspace resembling the one in Figure 1-2. You may see some
projects in the left-hand pane if you’ve already been working on projects within the IDE.

Figure 1-2. Opening the NetBeans IDE

3
CHAPTER 1 N GETTING STARTED WITH JAVA 8

Go to the File menu and select New Project. You’ll see the dialog in Figure 1-3. Choose the Java category, and
then Java Application. Click Next to advance to the dialog shown in Figure 1-4.

Figure 1-3. Creating a new Java SE project

4
CHAPTER 1 N GETTING STARTED WITH JAVA 8

Figure 1-4. Naming the project

Give your project a name. For the project related to this book, use the name Java8Recipes. Enter that name into
the Project Name text box at the top of the dialog in Figure 1-4.
Then specify the name of your main class in the Create Main Class text box. Give the following name:

org.java8recipes.chapter01.recipe1_02.HelloWorld

Be sure to that you’ve entered the project name and class name just as we provide them here, because the code
to follow depends upon your doing so. Make sure the Project Name text box specifies Java8Recipes. Make sure the
Create Main Class text box specifies org.java8recipes.chapter01.recipe1_02.HelloWorld.

N Tip Pay attention to case, Java is case-sensitive.

Press Finish to complete the wizard and create a skeleton project. You should now be looking at a Java source file.
Skeleton code is generated for you, and your NetBeans IDE window should resemble the one in Figure 1-5.

5
CHAPTER 1 N GETTING STARTED WITH JAVA 8

Figure 1-5. Viewing the skeleton code generated by NetBeans

Place your cursor anywhere in the source code pane. Press CTRL-A to select all the skeleton code. Then press
Delete to get rid of it. Replace the deleted code with that from Listing 1-1.

Listing 1-1. A “Hello, World” Example


package org.java8recipes.chapter01.recipe1_02;

/* An object of this class will hold the message. */


class HelloMessage {
private String message = "";

public HelloMessage() {
this.message = "Default Message";
}

6
CHAPTER 1 N GETTING STARTED WITH JAVA 8

public void setMessage (String m) {


this.message = m;
}

public String getMessage () {


return this.message.toUpperCase();
}

/* The main program begins in this class */


public class HelloWorld {

public static void main(String[] args) {

HelloMessage hm;
hm = new HelloMessage();

System.out.println(hm.getMessage());

hm.setMessage("Hello, World");

System.out.println(hm.getMessage());
}

You can find the code in Listing 1-1 as part of our example download for the book. It’s in the file HelloWorld.java,
and you’ll find that file within the NetBeans source package named org.java8recipes.chapter01.recipe1_02.
All recipe solutions of substance throughout this book are in that example download.
Make sure you have pasted (or typed) the code from Listing 1-1. Compile and run the program, and you should
see the following output:

run:
DEFAULT MESSAGE
HELLO, WORLD
BUILD SUCCESSFUL (total time: 1 second)

This output will appear in a new pane named “Output” that is opened by NetBeans at the bottom of the
IDE window.

How It Works
You can run almost all the solutions in this chapter using the same general technique shown in this recipe. We’ve
been painstakingly detailed for that reason, showing the step-by-step screenshots just this one time.

7
CHAPTER 1 N GETTING STARTED WITH JAVA 8

Packages
The solution example begins by creating a Java package:

package org.java8recipes.chapter01.recipe1_02;

Packages are a way of grouping related classes together into a shared namespace. The idea is to achieve universal
uniqueness by working your way down your organization’s domain name in reverse order. It is also customary to
write package names in all lowercase.
NetBeans will create a directory structure to mimic your package path. In this case, NetBeans created the
following directory path:

C:\Users\JonathanGennick\Documents\NetBeansProjects\
Java8Recipes\src\org\java8recipes\chapter01\recipe1_02

Following are some things to notice about this path:


u The front part is C:\Users\...\NetBeansProjects. NetBeans creates all projects under a
NetbeansProject directory unless you specify otherwise, which you can do from the dialog in
Figure 1-4. Many developers specify shorter paths.
u Next is the first occurrence of Java8Recipes. This occurrence corresponds to the project name
you gave when you filled in the Project Name text box from Figure 1-4.
u Any source files you create go into the src directory. NetBeans creates other directories at this
level. For example, NetBeans creates a build directory, and then underneath it is a classes
subdirectory to hold your compiled class files.
u Last are the directories mirroring the package path that you specify, in this case
org\java8recipes\chapter01\recipe1_02. When you compile your code, an identical
structure is created under the build\classes directory. Note that if using another IDE,
you may see differences in the directories that are created.
You do not need to explicitly create a package. If you do not create one, the Java compiler will create one for you,
and give it a name that is hidden from you. We prefer to be explicit, and you should too. Being thoughtful and explicit
about Java package names is de rigueur in the professional setting. Organization, as well as judiciously chosen naming
conventions, is important when developing any significant application.

JavaBeans-Style Classes
Next in the solution example you see a class definition following the JavaBeans pattern. The definition of
HelloMessage follows a pattern that you’ll encounter often in Java programming, and we include it for that reason.
The class is a simple one, capable of holding a single, string value named greeting.
Three methods are defined on the class:
HelloMessage(). This method, also known as the constructor, is named the same as the
class. In this case, it takes no arguments. It’s automatically invoked whenever you create a
new object of the class. Note that this is known as a “no-arg” constructor because it is typed
out within the class, and it takes no arguments. If you do not supply a constructor, the JVM
will supply a default constructor (also takes no arguments) automatically.
setMessage(String). This accessor method begins with the word set. It takes one
parameter. It specifies the message to be returned by the corresponding get method.
getMessage(). This accessor method returns the currently-defined message. In our
example, we choose to uppercase the message.

8
CHAPTER 1 N GETTING STARTED WITH JAVA 8

N Note Accessor methods are used in JavaBeans classes to access any privately declared class members. In this case,
the private variable identified as message can be accessed using these methods. Accessor methods are more commonly
referred to as “getters” and “setters.”

Methods beginning with set and get are termed as setter and getter methods. The variable message is private to
the class, which means you have no direct access to message from outside of the class.
You’ll see the keyword this used in the class. It is a special keyword in Java used to reference the current object.
Its use is redundant in Listing 1-1, but would be needed if any of the methods happened to create variables of their
own that were also named message.
It is common in Java to mediate access to class variables through setter and getter methods like those in our
example. Those methods represent a contract of sorts with other classes and your main program. Their benefit is
that you can change the storage implementation of HelloMessage however you like. Other code that depends upon
HelloMessage will continue to work properly so long as you maintain the external behavior of setMessage() and
getMessage().

The Main Program


The incantation public static void main(...) is used from within a public class to denote the beginning point of a
Java program. That declaration begins an executable method named main. You must specify one parameter that is an
array of strings, and typically that parameter is defined as String[] args.
When you execute the currently selected class, NetBeans compiles the code to a set of binary files, and then
transfers control to the main() method. That method, in turn, does the following:
1. Executes HelloMessage hm to create a variable named hm that is capable of holding an
instance of the class HelloMessage. The variable hm is empty at this point.
2. Invokes new HelloMessage() to create an object of the class by that name. The no-arg
constructor will be executed, and "Default Message" is now the greeting text. The new
object is now stored in the variable hm.
3. Makes a call to System.out.println() to show that the object’s no-arg constructor
has indeed executed as expected. The greeting "DEFAULT MESSAGE" is displayed in the
“Output” pane.
4. Sets the message to be the traditional text "Hello, World".
5. Makes another call to System.out.println() to output the new message that has just
been set. Now you see the greeting "hello, world" added to the “Output” pane.
The pattern in the solution is common in Java programming. The main() method is where execution begins.
Variables are defined, and objects are created using the new operator. Object variables are often set and retrieved using
setter and getter methods.

N Tip Command-line apps are passé. System administrators and programmers sometimes write them as utilities, or
to batch-process large amounts of data. But in the main, today’s applications are GUI applications. JavaFX is the way
forward in writing those applications, and you can learn about it in Chapters 14 through 17. Recipe 14-1 provides what is
essentially a “Hello, World” application in GUI form.

9
CHAPTER 1 N GETTING STARTED WITH JAVA 8

1-3. Compiling and Executing from the Command-line Interpreter


Problem
You aren’t able to install an IDE, or you don’t want to do so. You want to compile and execute your Java programs from
the command-line.

Solution
Compile your programs using the javac command. Then execute them via the java command.
Begin by making sure you have your JDK’s bin directory in your execution path. You might need to execute a
command such as one of the following.
Windows:

path %path%C:\Program Files\Java\jdk1.8.0\bin

OS X:

export PATH=/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin

Then make sure your CLASSPATH environment variable includes the directory containing your Java code. The
following is an example of setting the environment variable under Windows:

set CLASSPATH=<<path-to-my-Java>>

Now change your current working directory to be the one corresponding to your project. Recipe 1-2 had you
create a project named Java8Recipes. Change to that project’s directory on a Windows system as follows:

cd <path-to-project>\Java8Recipes

Descend one level into the src subdirectory:

cd src

From here, you can issue javac commands to compile any classes in your project. Prepend the appropriate
package name as part of your path leading to each source file to be compiled. Be sure to include the .java extension
after your file name. For example, issue the following command to compile the HelloWorld class from Recipe 1-2.
Windows:

javac org\java8recipes\chapter01\recipe1_02\HelloWorld.java

OS X:

javac org/java8recipes/chapter01/recipe1_02/HelloWorld.java

You should now have a .class file in the same directory as your .java file. For example:

dir org\java8recipes\chapter01\recipe1_02 /B

HelloMessage.class
HelloWorld.class
HelloWorld.java

10
CHAPTER 1 N GETTING STARTED WITH JAVA 8

Compilation produces two files. One is for HelloMessage, and the other is for the class named HelloWorld
implementing the main() method.
Execute the main() method by issuing the java command to invoke the Java Virtual Machine (JVM). Pass the
fully-qualified class name as a parameter to the command. Qualify the class name by prepending the package name,
but this time use the same dot-notation as used in your source file. For example:

java org.java8recipes.chapter1.recipe1_02.HelloWorld

Do not specify .class at the end of the command. You are referencing HelloWorld now as a class name, and not
as a file name. You should see the same output as from Recipe 1-2.

N Tip One compiles source code. Source code is kept in files, so your operating-system’s file and directory-path
notation is appropriate. One executes a class. A class is an abstract concept in the language, so the language’s
dot-notation becomes appropriate. Keep this distinction in mind to help yourself remember when to use which notation.

How It Works
The first two solution steps are housekeeping steps. You must have the Java compiler and the virtual machine in your
execution path. It’s also necessary for any classes used by your program to be found somewhere along what is termed
the class path. One way to specify the class path is through the CLASSPATH environment variable.
The command java with no c at the end is for executing compiled code. Pass as a parameter the qualified
name of the class containing your main method. The JVM will interpret and execute the byte-code within that class,
beginning from the main method. The JVM will search along the class path for any additionally required classes such
as HelloMessage.
The compiler’s default behavior is to place each generated class file into the same directory as holds the
corresponding source file. You can override that behavior through the -d option. For example:

javac -d "<specify-different-location>" "<path-to-project>


\Java8Recipes\src\org\java8recipes\chapter1\recipe1_02\HelloWorld.java"

The -d option in this command specifies the same directory as NetBeans is using in our own environment as the
target for holding generated class files. The command also specifies the full path and file name of the source file. Thus,
the command can be executed with the same result regardless of the current working directory.

N Tip Configure your system so that your command-line environment has the execution path and class path set
correctly by default. The typical approach in Linux is to put appropriate commands into your .profile or .bash_profile
files. Under Windows you can specify environment variable defaults from the Control Panel applet named System, by
clicking on the Advanced system settings link, and then on the Environment Variables button.

There may be times when you need to specify a custom class path for a specific execution of the JVM. You can do
that through the -cp parameter, as follows:

java -cp ".;<path-to-project>\Java8Recipes\build\classes\org\java8recipes\chapter1\recipe1_02"


org.java8recipes.chapter1.recipe1_02.HelloWorld

11
CHAPTER 1 N GETTING STARTED WITH JAVA 8

This execution will search first in the current working directory (the leading dot in the class path), and then under
the specified package directory corresponding to where NetBeans would place the compiled classes.

N Note See Recipe 1-10 for more on configuring your class path.

1-4. Declaring Simple Variables


Problem
You want to create some variables and manipulate data within your program.

Solution
Java implements eight primitive data types. There is also special support for the String class type. Listing 1-2 shows
an example declaration of each. Draw from the example to declare the variables needed in your own application.

Listing 1-2. Declarations for Primitive and String Types


package org.java8recipes.chapter01.recipe1_04;

public class DeclarationsExample {


public static void main (String[] args) {
boolean BooleanVal = true; /* Default is false */

char charval = 'G'; /* Unicode UTF-16 */


charval = '\u0490'; /* Ukrainian letter Ghe(DZ) */

byte byteval; /* 8 bits, -127 to 127 */


short shortval; /* 16 bits, -32,768 to 32,768 */
int intval; /* 32 bits, -2147483648 to 2147483647 */
long longval; /* 64 bits, -(2^64) to 2^64 - 1 */

float floatval = 10.123456F; /* 32-bit IEEE 754 */


double doubleval = 10.12345678987654; /* 64-bit IEEE 754 */

String message = "Darken the corner where you are!";


message = message.replace("Darken", "Brighten");
}
}

Variables are subject to the concept of visibility. Those created in Listing 1-2 are visible from the main() method
after they have been created, and they are deallocated when the main() method ends. They have no “life” beyond the
main() method, and are not accessible from outside of main().
Variables created at the class level are a different story. Such variables can be termed as fields, as in fields of
the class. Use of a field can be restricted to objects of the class in which it is declared, to the package in which it is
declared, or it can be accessible from any class in any package. Listing 1-3 shows some of how to control visibility via
the private and public keywords.

12
CHAPTER 1 N GETTING STARTED WITH JAVA 8

Listing 1-3. Visibility and the Concept of Fields


package org.java8recipes.chapter01.recipe1_04;

class TestClass {
private long visibleOnlyInThisClass;
double visibleFromEntirePackage;

void setLong (long val) {


visibleOnlyInThisClass = val;
}

long getLong () {
return visibleOnlyInThisClass;
}
}

public class VisibilityExample {


public static void main(String[] args) {
TestClass tc = new TestClass();
tc.setLong(32768);
tc.visibleFromEntirePackage = 3.1415926535;
System.out.println(tc.getLong());
System.out.println(tc.visibleFromEntirePackage);
}
}

Output:

32768
3.1415926535

Fields are typically tied to an object of a class. Each object of a class holds an instance of each field in the class.
However, you can define so-called static fields that occur just once, and with a single value shared by all objects of the
given class. Listing 1-4 illustrates the difference.

Listing 1-4. Static Fields


package org.java8recipes.chapter01.recipe1_04;

class StaticDemo {
public static boolean oneValueForAllObjects = false;
}

public class StaticFieldsExample {


public static void main (String[] args) {
StaticDemo sd1 = new StaticDemo();
StaticDemo sd2 = new StaticDemo();
System.out.println(sd1.oneValueForAllObjects);
System.out.println(sd2.oneValueForAllObjects);
sd1.oneValueForAllObjects = true;

13
CHAPTER 1 N GETTING STARTED WITH JAVA 8

System.out.println(sd1.oneValueForAllObjects);
System.out.println(sd2.oneValueForAllObjects);
}

Listing 1-4 produces the following output:

false
false
true
true

The field oneValueForAllObjects was set to true only for the class instance named sd1. Yet it is true for instance
sd2 also. This is because of the keyword static used in declaring that field. Static fields occur one time for all objects
of their class.

How It Works
Listing 1-2 illustrates the basic format of a variable declaration:

type variable;

It’s common to initialize variables when declaring them, so you’ll often see:

type variable = initialValue;

Field declarations can be preceded by modifiers. For example:

public static variable = initialValue;


private variable;

It’s common to put the visibility modifier — public or private — first, but you are free to list the modifiers in any
order you like. Be aware that there are additional modifiers that you will encounter and need to learn about as you get
deeper into the language.
The String type is special in Java. It’s really a class type, but syntactically you can treat it as a primitive type.
Java automatically creates a String object whenever you enclose a string of characters within double-quotes ("...").
You aren’t required to invoke a constructor, nor to specify the new keyword. Yet String is a class, and there are methods
in that class that are available to you. One such method is the replace() method shown at the end of Listing 1-2.
Strings are composed of characters. Java’s char type is a two-byte construct for storing a single character in
Unicode-s UTF-16 encoding. You can generate literals of the char type in two ways:
u If a character is easy to type, then enclose it within single quotes (e.g.: 'G').
u Otherwise, specify the four-digit UTF-16 code point value prefaced by \u (e.g.: '\u0490').
Some Unicode code points require five digits. These cannot be represented in a single char value. See Chapter 10
if you need more information on Unicode and internationalization.
Avoid using any of the primitive types for monetary values. Especially avoid either of the floating-point types for
that purpose. Refer instead to Chapter 4 and its recipe on using BigDecimal to calculate monetary amounts (Recipe 4-7).
BigDecimal is also useful anytime you need accurate, fixed-decimal arithmetic.

14
CHAPTER 1 N GETTING STARTED WITH JAVA 8

If you are new to Java, you may be unfamiliar with the String[] array notation, as demonstrated in the examples.
Please see Chapter 7 for more information on arrays. It covers enumerations, arrays, and also generic data types. Also
in that chapter are examples showing how to write iterative code to work with collections of values such as an array.

N Note If you’re curious about the Ukrainian letter in Listing 1-2, it is the Cyrillic letter Ghe with upturn. You can read
about its history at: http://en.wikipedia.org/wiki/Ghe_with_upturn. You can find its code point value in the chart at
http://www.unicode.org/charts/PDF/U0400.pdf. And the URL http://www.unicode.org/charts/ is a good place to
start whenever you need to find the code point corresponding to a given character.

1-5. Converting to and from a String


Problem
You have a value in a primitive data type, and you want to represent that value as a human-readable string. Or, you
want to go in the other direction by converting a human-readable string into a primitive data type.

Solution
Follow one of the patterns from Listing 1-5. The listing shows conversion from a string to a double-precision
floating-point value, and shows two methods for getting back to a string again.

Listing 1-5. General Pattern for String Conversions


package org.java8recipes.chapter01.recipe1_05;

public class StringConversion {

public static void main (String[] args) {


double pi;
String strval;

pi = Double.parseDouble("3.14");
System.out.println(strval = String.valueOf(pi));
System.out.println(Double.toString(pi));
}

How It Works
The solution illustrates some conversion patterns that work for all the primitive types. First, there is the conversion of
a floating-point number from its human-readable representation into the IEEE 754 format used by the Java language
for floating-point arithmetic:

pi = Double.parseDouble("3.14");

15
CHAPTER 1 N GETTING STARTED WITH JAVA 8

Notice the pattern. You can replace Double with Float, or by Long, or by whatever other type is your target data
type. Each primitive type has a corresponding wrapper class by the same name but with the initial letter uppercase.
The primitive type here is double, and the corresponding wrapper is Double. The wrapper classes implement helper
methods such as Double.parseDouble(), Long.parseLong(), Boolean.parseBoolean(), and so forth. These parse
methods convert human-readable representations into values of the respective types.
Going the other way, it is often easiest to invoke String.valueOf(). The String class implements this method,
and it is overloaded for each of the primitive data types. Alternatively, the wrapper classes also implement toString()
methods that you can invoke to convert values of the underlying type into their human-readable forms. It’s your own
preference as to which approach to take.
Conversions targeting the numeric types require some exception handling to be practical. You generally need to
gracefully accommodate a case in which a character-string value is expected to be a valid numeric representation, but
it’s not. Chapter 9 covers exception-handling in detail, and the upcoming Recipe 1-7 provides a simple example to get
you started.

N Caution Literals for the Boolean type are "true" and "false". They are case-sensitive. Any value other than
these two is silently interpreted as false when converting from a String using the Boolean parseBoolean()
conversion method.

1-6. Passing Arguments via Command-Line Execution


Problem
You want to pass values into a Java application via the command-line.

Solution
Run the application using the java command, and specify the arguments that you want to pass into it after the
application name. If you’re passing more than one argument, each should be separated by a space. For example,
suppose you want to pass the arguments to the class created in Listing 1-6.

Listing 1-6. Example of Accessing Command-Line Arguments


package org.java8recipes.chapter01.recipe1_06;

public class PassingArguments {


public static void main(String[] args){
if(args.length > 0){
System.out.println("Arguments that were passed to the program: ");
for (String arg:args){
System.out.println(arg);
}
} else {
System.out.println("No arguments passed to the program.");
}
}
}

16
CHAPTER 1 N GETTING STARTED WITH JAVA 8

First, make sure to compile the program so that you have a .class file to execute. You can do that from within
NetBeans by right-clicking the file and choosing the “Compile File” option from the context menu.
Next, open a Command Prompt or terminal window and traverse into the build\classes directory for your project.
(See Recipe 1-3 for an extensive discussion of executing from the command-line). For example:

cd <path-to-project>\Java8Recipes\build\classes

Now issue a java command to execute the class, and type some arguments on the command-line following the
class name. The following example passes two arguments:

java org.java8recipes.chapter01.recipe1_06.PassingArguments Upper Peninsula

You should see the following output:

Arguments that were passed to the program:


Upper
Penninsula

Spaces separate arguments. Enclose strings in double quotes when you want to pass an argument containing
spaces or other special characters. For example:

java org.java8recipes.chapter01.recipe1_06.PassingArguments "Upper Peninsula"

The output now shows just one argument:

Arguments that were passed to the program:


Upper Penninsula

The double quotes translate the string "Upper Peninsula" into a single argument.

How It Works
All Java classes that are executable from the command-line or terminal contain a main() method. If you look at the
signature for the main() method, you can see that it accepts a String[] argument. In other words, you can pass an
array of String objects into the main() method. Command-line interpreters such as the Windows Command Prompt
and the various Linux and Unix shells build an array of strings out of your command-line arguments, and pass that
array to the main() method on your behalf.
The main() method in the example displays each argument that is passed. First, the length of the array named
args is tested to see whether it is greater than zero. If it is, the method will loop through each of the arguments in the
array by executing a for loop, displaying each argument along the way. If there are no arguments passed, the length
of the args array will be zero, and a message indicating such will be printed. Otherwise, you see a different message
followed by a list of arguments.
Command-line interpreters recognize spaces and sometimes other characters as delimiters. It’s generally safe
to pass numeric values as arguments delimited by spaces without bothering to enclose each value within quotes.
However, you should get into the habit of enclosing character-string arguments in double quotes, as shown in the final
solution example. Do that to eliminate any ambiguity over where each argument begins and ends.

N Note All arguments are seen by Java as character strings. If you pass numeric values as parameters, they enter
Java as character strings in human-readable form. You can convert them into their appropriate numeric types using the
conversion methods shown in Recipe 1-5.

17
CHAPTER 1 N GETTING STARTED WITH JAVA 8

1-7. Accepting Input from the Keyboard


Problem
You are interested in writing a command-line or terminal application that will accept user input from the keyboard.

Solution
Make use of the java.io.BufferedReader and java.io.InputStreamReader classes to read keyboard entry and store
it into local variables. Listing 1-7 shows a program that will keep prompting for input until you enter some characters
that represent a valid value of type long.

Listing 1-7. Keyboard Input and Exception Handling


package org.java8recipes.chapter01.recipe1_07;

import java.io.*;

public class AcceptingInput {


public static void main(String[] args){
BufferedReader readIn = new BufferedReader(
new InputStreamReader(System.in)
);
String numberAsString = "";
long numberAsLong = 0;

boolean numberIsValid = false;


do {
/* Ask the user for a number. */
System.out.println("Please enter a number: ");
try {
numberAsString = readIn.readLine();
System.out.println("You entered " + numberAsString);
} catch (IOException ex){
System.out.println(ex);
}

/* Convert the number into binary form. */


try {
numberAsLong = Long.parseLong(numberAsString);
numberIsValid = true;
} catch (NumberFormatException nfe) {
System.out.println ("Not a number!");
}
} while (numberIsValid == false);
}
}

18
CHAPTER 1 N GETTING STARTED WITH JAVA 8

Following is an example run of this program:

Please enter a number:


No
You entered No
Not a number!
Please enter a number:
Yes
You entered Yes
Not a number!
Please enter a number:
42
You entered 42
BUILD SUCCESSFUL (total time: 11 seconds)

The first two inputs did not represent valid values in the long data type. The third value was valid, and the
run ended.

How It Works
Quite often our applications need to accept user input of some kind. Granted, most applications are not used from
the command-line or terminal nowadays, but having the ability to create an application that reads input from the
command-line or terminal helps to lay a good foundation, and may be useful in some applications. Terminal input
can also be useful in developing administrative applications that you or a system administrator may use.
Two helper classes were used in the solution to this recipe. They are java.io.BufferedReader and
java.io.InputStreamReader. The early portion of the code that’s using those classes is especially important to
understand:

BufferedReader readIn = new BufferedReader(


new InputStreamReader(System.in)
);

The innermost object in this statement is System.in. It represents the keyboard. You do not need to declare
System.in. Java’s runtime environment creates the object for you. It is simply “there” to be used.
System.in provides access to raw bytes of data from the input device, which is the keyboard in our example. It is
the job of the InputStreamReader class to take those bytes and convert them into characters in your current character
set. System.in is passed to the InputStreamReader() constructor to create an InputStreamReader object.
InputStreamReader knows about characters, but not about lines. It is the BufferedReader class’s job to detect
line breaks in the input stream, and to enable you to conveniently read a line at a time. BufferedReader also aids
efficiency by allowing physical reads from the input device to be done in different-size chunks than by which your
application consumes the data. This aspect can make a difference when the input stream is a large file rather than the
keyboard.
Following is how the program in Listing 1-7 makes use of an instance (named readIn) of the BufferedReader
class to read a line of input from the keyboard:

numberAsString = readIn.readLine();

Executing this statement triggers the following sequence:


1. System.in returns a sequence of bytes.
2. InputStreamReader converts those bytes into characters.

19
CHAPTER 1 N GETTING STARTED WITH JAVA 8

3. BufferedReader breaks the character stream into lines of input.


4. readLine() returns one line of input to the application.
I/O calls must be wrapped in try...catch blocks. These blocks catch any exceptions that may occur. The try part
in the example will fail in the event a conversion is unsuccessful. A failure prevents the numberIsValid flag from being
set to true, which causes the do loop to make another iteration so that the user can try again at entering a valid value.
The following statement at the top of Listing 1-7 deserves some mention:

import java.io.*;

This statement makes available the classes and methods defined in the java.io package. These include
InputStreamReader and BufferedReader. Also included is the IOException class used in the first try...catch block.

1-8. Documenting Your Code


Problem
You want to document some of your Java classes to assist in future maintenance.

Solution
Use Javadoc to place comments before any class, method, or field that you want to document. To begin such a
comment, write the characters /**. Then begin each subsequent line with an asterisk (*). Lastly, close the comment
with the characters */ on a line by themselves at the end. Listing 1-8 shows a method commented with Javadoc.

Listing 1-8. Comments Made in Javadoc Form


package org.java8recipes.chapter01.recipe1_08;

import java.math.BigInteger;

public class JavadocExample {


/**
* Accepts an unlimited number of values and
* returns the sum.
*
* @param nums Must be an array of BigInteger values.
* @return Sum of all numbers in the array.
*/
public static BigInteger addNumbers(BigInteger[] nums) {
BigInteger result = new BigInteger("0");
for (BigInteger num:nums){
result = result.add(num);
}

return result;
}
/**
Test the addNumbers method.
* @param args not used
*/

20
CHAPTER 1 N GETTING STARTED WITH JAVA 8

public static void main (String[] args) {


BigInteger[] someValues = {BigInteger.TEN, BigInteger.ONE};
System.out.println(addNumbers(someValues));
}
}

Comments can be added to the beginning of classes and fields in the same way. The comments are helpful to
you and other programmers maintaining the code, and their specific format enables easy generation of an HTML
reference to your code.
Generate the HTML reference by invoking the tool named Javadoc. This is a command-line tool that parses a
named Java source file and formulates HTML documentation based upon the defined class elements and Javadoc
comments. For example:

javadoc JavadocExample.java

This command will produce several HTML files containing the documentation for the class, methods, and fields.
If no Javadoc comments exist within the source, some default documentation will still be produced. To view the
documentation, load the following file into your browser:

index.html

The file will be in the same directory as the class or package that you are documenting. There will also be an
index-all.html file giving a strict alphabetical listing of documented entities.
Keep in mind that the same rules apply when using the Javadoc tool as when using javac. You must reside within
the same directory as the source file, or prepend the name of the file with the path to where the file is located.

How It Works
Generating documentation for applications from scratch can be quite tedious. Maintaining documentation can be even
more troublesome. The JDK comes packaged with an extensive system for documentation known as Javadoc. Placing
some special comments throughout your code source and running a simple command-line tool makes it easy to generate
useful documentation and keep it current. Moreover, even if some of the classes, methods, or fields in an application are
not commented specifically for the Javadoc utility, default documentation will still be produced for such elements.

Formatting the Documentation


To create a Javadoc comment, begin with the characters /**. Although optional since Java 1.4, a common practice is to
include an asterisk as the first character of every subsequent line within the comment. Another good practice is to indent
the comment so that it aligns with the code that is being documented. Lastly, close the comment with the characters */.
Javadoc comments should begin with a short description of the class or method. Fields are rarely commented
using Javadoc, unless they are declared public static final (constants), in which case it is a good idea to supply a
comment. A comment can be several lines in length, and can even contain more than one paragraph. If you want to
break comments into paragraphs, then separate those paragraphs using the <p> tag. Comments can include several
tags that indicate various details regarding the method or class that is being commented. Javadoc tags begin with an
ampersand (@), and some of the common tags are as follows:

@param: Name and description of a parameter


@return: What is returned from the method
@see: Reference to another piece of code

21
CHAPTER 1 N GETTING STARTED WITH JAVA 8

You may also include inline links within Javadoc to reference URLs. To include an inline link, use the tag
{@link My Link}, where link is the actual URL that you want to point at and My Link is the text that you want to have
appear. There are also many other tags that can be used within Javadoc comments, including {@literal}, {@code},
{@value org}, and many others. For a complete listing, see the Javadoc reference on the Oracle Technology
Network website.

Executing the Tool


The Javadoc tool can also be run against entire packages or source. Simply pass a package name to the Javadoc tool
rather than individual source file names. For instance, if an application includes a package named org.juneau.beans,
all source files within that package can be documented by running the tool as follows:

javadoc org.juneau.beans

To generate Javadoc for more than one package at a time, separate the package names with spaces as follows:

javadoc org.juneau.beans org.juneau.entity

Another option is to specify the path to the source files using the –sourcepath flag. For example:

javadoc –sourcepath /java/src

By default, the Javadoc tool will generate HTML and place it into the same package as the code being documented.
That result can become a cluttered nightmare if you like to have source files separate from documentation. You can
instead set up a destination for the generated documentation by passing the –d flag to the Javadoc tool.

1-9. Organizing Code with Packages


Problem
Your application consists of a set of Java classes, interfaces, and other types. You want to organize these source files to
make them easier to maintain and avoid potential class-naming conflicts.

Solution
Create Java packages and place source files within them much like a filing system. Java packages can be used to
organize logical groups of source files within an application. Packages can help to organize code, reduce naming
conflicts among different classes and other Java type files, and provide access control. To create a package, simply
create a directory within the root of your application source folder and name it. Packages are usually nested
within each other and conform to a standard naming convention. For the purposes of this recipe, assume that the
organization is named Juneau and that the organization makes widgets. To organize all the code for the widget
application, create a group of nested packages conforming to the following directory structure:

/org/juneau

Any source files that are placed within a package must contain the package statement as the first line in the
source. The package statement lists the name of the package in which the source file is contained. For instance,
suppose that the main class for the widget application is named JuneauWidgets.java. To place this class into a

22
CHAPTER 1 N GETTING STARTED WITH JAVA 8

package named org.juneau, physically move the source file into a directory named juneau, which resides within
the org directory, which in turn resides within the root of the source folder for the application. The directory structure
should look like the following:

/org/juneau/JuneauWidgets.java

The source for JuneauWidgets.java is as follows:

package org.juneau;

/**
* The main class for the Juneau Widgets application.
* @author juneau
*/
public class JuneauWidgets {
public static void main(String[] args){
System.out println("Welcome to my app!");
}
}

The first line in the source contains the package statement, which lists the name of the package that the source file
is located within. The entire package path is listed in the statement, and the names in the path are separated by dots.

N Note A package statement must be the first statement listed within the Java source. However, there may be a
comment or Javadoc comment written before the package statement.

An application can consist of any number of packages. If the widget application contains a few classes that
represent widget objects, they could be placed within the org.juneau.widget package. The application may have
interfaces that can be used to interact with the widget objects. In this case, a package named org.juneau.interfaces
may also exist to contain any such interfaces.

How It Works
Java packages are useful for organizing source files, controlling access to different classes, and ensuring that there are
no naming conflicts. Packages are represented by a series of physical directories on a file system, and they can contain
any number of Java source files. Each source file must contain a package statement before any other statements in the
file. This package statement lists the name of the package in which the source file resides. In the solution to this recipe,
the source included the following package statement:

package org.juneau;

This package statement indicates that the source file resides within a directory named juneau, and that directory
resides within another directory named org. Package-naming conventions can vary by company or organization.
However, it is important that words are in lowercase so they do not conflict with any Java class file names. Many
companies or organizations will use the reverse of their domain name for package naming. However, if a domain
name includes hyphens, underscores should be used instead.

23
Random documents with unrelated
content Scribd suggests to you:
unabridged dictionary, and his talent for sizing people up and telling
you all about them is really remarkable. He is the last person in the
world, though, that I should have picked out as a citizen of Salem,
and one day I told him so. He explained himself by saying that his
mother had made an unfortunate marriage. I felt very sorry, as the
only time I saw his mother I thought her lovely.
"He was very handsome and had a great deal of money, and
was the best and most delightful man I ever knew," Berri went on.
"Well, I don't see anything so dreadfully unfortunate in all that,"
I ventured.
"Ah, but he was n't from Salem," Berri explained simply. "He
didn't even have any cousins there, although for a time mamma's
family tried to delude themselves into believing they were on the
track of some. They traced him back to Humphrey de Bohun and
Elizabeth Plantagenet, but there they lost the scent; and as
mamma's people—perhaps you know—came from the King of
Navarre and Urracca, Heiress of Arragon, why—of course—well, you
know how people talk. It was all very sad. Naturally mamma never
cared to live in Salem after that, and I think my grandparents were
rather relieved that she preferred to stay most of the time in France.
They used to come over and see us every few years, but of course
no one in Salem ever knew about that; every one believed that
grandfather had to take a cure at Carlsbad—at least that was what
was given out whenever he went abroad. I suppose I can't help
seeming somewhat crude now and then," he mused dismally; "dilute
the strain and it's bound to show sooner or later. But there—I don't
know why I've told you all this; it is n't the sort of thing one can
discuss with everybody."
"All this" was intensely interesting and mysterious to me, but I
don't think I can ever get on to it entirely; just when I 'm beginning
to feel that I 've mastered the details I collide with a perfectly new
phase and find I don't know anything at all. My ignorance has led to
several discussions with Berri—the heated kind that always result in
coldness. When I told him, for instance, that I 'd met Billy in town
one morning and he 'd taken me home for luncheon, Berri said,
"How nice," and proceeded to effect a union of his eyebrows and the
top of his head.
"Now what on earth is the matter with Billy?" I exclaimed
indignantly, for I 'd enjoyed my luncheon exceedingly, and the house
was the biggest thing I had ever seen.
"Oh, Billy 's all right. He 's really very nice, I imagine—although,
of course, I don't know him very well," said Berri. "Why do you ask?"
"Who wouldn't ask when you hang your eyebrows on your front
hair that way at the mere mention of his name?" I demanded. "Why
do you say 'of course,' and why do you always make a point of the
fact that you don't know him well? Who cares whether you do or
not?" I pursued, for I wanted to clear this mystery up once and for
all.
"Well, you seem to care a good deal," Berrisford laughed.
"Oh, not personally," I assured him, "only in the interest of
science."
We squabbled for an hour, and at the end of that time I had
discovered that (1) Billy's family spell their name with an e—a most
incriminating thing to do, apparently, and (2) their house is on the
left-hand side of the street as you go up, which (3) makes it easier
for a rich man to pass through the moat into Heaven than to draw a
beam of recognition from the eye of his neighbor. It was all very
confusing—especially as Berrisford insisted that no one had ever told
him these things—he had known that they were so when he came
into the world.
"Well, I don't see how you 've allowed yourself to be so friendly
with me," I wondered sarcastically. "You 've been pretty reckless, it
strikes me. How do you know what side of the street our house is on
in Perugia, Wisconsin—or whether, indeed, we live in a house at all?"
"Oh, you 're different," Berri laughed.
"Different from what?"
"From everything; that's why I 'm willing to run the risk. You 're
a strange, barbarous thing, and I like you immensely."
That was all the satisfaction I got. The reason I thought of this
was because Duggie and I discussed it among other things that
Sunday morning on the rocks.
It was perfectly evident that Duggie's family lived on the right
side of the street, and didn't "spell their name with an e," although I
should never have seen them in this light if Berrisford hadn't opened
my eyes ("poisoned my mind," Duggie called it). Duggie's father
resembles the Duke in Little Lord Fauntleroy, and his mother—well,
his mother is like Duggie; one could n't say very much more than
that. My impression of them is that they are between nineteen and
twenty feet high, and when they and Duggie and his elder sister and
two younger brothers were assembled, they looked the way family
groups of crowned heads ought to look and don't.
The sister met us at the station with a cart and two ponies.
"They told me to take care of myself," Duggie said to her sort of
doubtfully.
"He 's afraid of my nags," she explained to me as I clambered
up beside her.
"I 'm afraid of your driving," Duggie answered. "I brought Jack
Hollis down here to rest one Saturday and Sunday," he said to me,
"and after she'd whirled him around the country for several hours on
two wheels and run into a few trees and spilled him over a cliff, the
poor thing went back to town with heart disease and has never been
the same since."
Now, of course, Duggie merely meant to give me an
exaggerated idea of his sister's driving, and she, of course, knew
that his remark was quite innocent; but nevertheless she began to
blush (it was then, I think, that I first noticed how pretty she was)
and abruptly gave one of the horses a slap with the whip that sent
us plunging and nearly snapped my head off.
"Hold on, Tommy," Duggie called to me. "This is what I go
through every time I come home." Then, as a flock of terrified hens
scuttled shrieking from under the ponies' feet, he added: "Tell them
I was very brave and hopeful to the end and that my last words
were about the team." But pretty soon the horses settled down into
a fast, steady trot, and we bowled along the prettiest road I 've ever
seen—between thick woods, and, farther on, great, uneven
meadows marked off in irregular shapes with low fences of rough
stone. The meadows to the right ran back to the woods, but the
ones on the left stretched away ahead of us into a vast plain. It gave
me a queer, happy feeling that I can't explain—as if I were going to
soar out of the cart and over the meadows—straight on into space. I
could n't imagine where such a sweep of luminous horizon led to—it
seemed extraordinary to come across anything so much like a prairie
in New England. The air, too, had a lot to do with the way I felt. It
was wonderful air—not cold exactly, and not wet; although I thought
every minute that it was going to be both. It had a peculiar smell to
it that, without knowing why, I liked. I filled my lungs with it, and
somehow it made me feel bigger than I usually do. Then all at once
the ponies scampered over the top of a little incline, and, although
Miss Sherwin was telling me something, I gasped out:
"Oh-h-h-h—it's the ocean!" and forgot what she was saying,
and even that she and Duggie and the cart were with me at all. For I
had never seen it before; and it was right there in front of me—
brimming over in long, slow, green, pillowy things that rolled forward
and slipped back, forward and back, until all at once they got top
heavy and lost control of themselves and tumbled over the edge in a
delirious white and green confusion that slid across the sand in swift,
foamy triangles almost up to our wheels and made the ponies shrink
to the other side of the road in a sort of coquettish dance. Then
there was a very slim, refined-looking lighthouse on a gray rock
bordered by a little white frill where it touched the water, and
beyond that, putting out to sea, was a great ship with bulging sails,
and a steamer that left a lonely trail of black smoke sagging after it
for miles.
I don't know how long I stared at these things, or how long I
should have kept on staring at them, if I had n't happened to glance
up and see that Miss Sherwin was looking down at me and laughing.
I think she expected me to say something, but I couldn't bring
myself to come out with either of the only two things that occurred
to me—one of which was that as it looked so exactly as I always
thought it was going to, I did n't see why I felt almost like bursting
into tears when we came over the hill-top and actually saw it; and
the other was—that I should have very much liked to get down and
taste it. However, Miss Sherwin had about all she could do to attend
to the horses and did n't insist on an explanation; so we said hardly
anything all the rest of the way, and just let the wind blow in our
faces and watched the waves tumble across the hard sand for miles.
At first nothing at the Sherwins' seemed in the least real to me.
Even Duggie struck me as altogether different, although he was, of
course, just the same—only seen in unexpected surroundings.
First of all, when we arrived, a groom popped up from behind a
hedge and took the horses; then two young men in dark green
clothes with brass buttons and yellow waistcoats bustled down from
the piazza to get our things out of the cart. They were rather
handsome, but had very troubled expressions, and looked as if they
worried a good deal for fear they shouldn't do it right. Duggie
nodded to them over his shoulder, and I think they were secretly
gratified at this—although I suspect them of having worried terribly
for fear they might betray it. They helped us off with our coats and
hats when we got inside, which is all well enough, and makes you
feel as grand as you do in a barber-shop, but has its disadvantages,
for they run away with everything you have, and lock them up
somewhere in a safe, and when you want to go out to play with the
dogs or take a walk and think it all over, you usually have to tell
Vincent to tell Dempsey to tell Chamberlain that you would like a
hat.
Miss Sherwin led me through some beautiful rooms, and as we
walked along she turned to me and exclaimed,—
"Aren't you fearfully keen for your tea?"
I really don't care in the least for tea; in fact, I rather dislike it.
But she seemed to take it so for granted that I should be in a sort of
tea-guzzling frenzy by half-past five o'clock that I hated to disappoint
her, and was going to say, "Oh, yes—fearfully," when it flashed
through me that I could make my reply more elaborate and
interesting than this, and thought it would be rather effective to
murmur, "One gets so out of the habit in Cambridge." Then (all this
took only about a second) it occurred to me that I 'd never in my
whole life drunk a cup of tea in the afternoon with the exception of
the time that Berrisford had some people out to his rooms. So I
merely said—which was perfectly true: "I don't like tea; but I like
those thin, round cakes that are brown at the edges and yellow in
the middle." This made her laugh, and I was glad I had n't said the
other thing, because she 's very pretty when she laughs.
One corner of the piazza is enclosed in glass, and we had tea
out there where we could watch the sunset and the pink lights on
the water as it rolled up almost to the lawn in the front yard. The
two younger brothers came in—one of them has a tutor and the
other goes to St. Timothy's—and while we were waiting for the tea
things to be brought, Mr. and Mrs. Sherwin sauntered across the
grass. I forget whether they had been gathering orchids in the
conservatory or merely feeding the peacocks, but they were both
exceedingly gracious and glad to see me. Yet their very way of
taking me so for granted (just as Miss Sherwin had about the tea)
made me uncomfortable at first. They could n't, of course, have
asked me to explain myself—to tell them what right I had to
consume cakes in their crystal palace and enjoy their sunset; but the
mere fact that they did n't seem to expect me to justify myself in
any way made me feel like an impostor.
The man who brought in the tea things had a good deal to do
with this. I 'm quite sure that he disapproved of me from the first.
He was older than the two who met us at the door, and I think he
had probably long since ceased to worry on his own account; but he
worried a lot over me. Later—at dinner—he just gave up all his other
duties and stood behind my chair, mentally calculating the chances
of my coming out even or behind the game in the matter of knives
and forks. Whenever I used too many or too few (which I did
constantly) he would glide away and remedy the defect, or craftily
remove the damning evidence of my inattention. In writing to
mamma about my visit I ended my letter by saying: "I had a
delightful time—but it would take me years to get used to their
butler." To which mamma replied: "I'm glad you enjoyed yourself,
dear; they must live charmingly. But I simply can't see why they
should n't have good butter. It's so easy to get it now almost
anywhere. Perhaps they don't eat it themselves and don't realize
that they are being imposed upon." (This will be one of the greatest
triumphs of papa's declining years, as he is always blowing me up
about my handwriting.) Whenever Dempsey (the other servants call
him "Mr. Dempsey") came into the glass place I waited in a sort of
trembling eagerness, half expecting him to announce "Lord and Lady
Belgrave and Miss Muriel Fitz Desmond," but the only person who
dropped in was an old man named Snagg, and although Dempsey
made as much out of his arrival as any one possibly could—you
can't, after all, do miracles with a name like Snagg. However, I was
grateful to Mr. Snagg for coming, as it brought me back to earth
again.
To tell the truth, before the evening was finished I began to get
over the unreal sensation I had at first, and saw very plainly that
whether or not I felt at home depended entirely on me. Duggie and
his family—poor things—did n't have any idea that their Dempsey
paralyzed me with fright, or that (just as Berri had predicted) by the
time dinner was ready I was shaky in the knees with hunger. They
assumed that a friend of Duggie's naturally would feel at home and
know beforehand what was going to happen. This dawned on me
when I realized that Duggie was exactly as he always is, and that
the others were probably exactly as they always were, and I couldn't
help appreciating after a time that if they took me so calmly, it was
rather unreasonable of me not to feel the same way about them. No
one made any effort to entertain me, which is very nice—after you
get used to it. Mrs. Sherwin played solitaire after dinner, while
Duggie and his sister (she was embroidering something) and I sat
around a fire that Miss Sherwin said was built of driftwood from an
old whaler, and Duggie declared was manufactured with chemicals
by a shrewd person in Maine. I don't know who was right, but with
the sea murmuring just outside the windows and coming down
every now and then with a great thud on the little beach at the end
of the lawn, I preferred to believe in the old whaler theory. Mr.
Sherwin would appear every few minutes to read us something he
had come across in a volume of literary reminiscences which
reminded him of something entirely different that had happened to
Thoreau or Emerson or Hawthorne or Margaret Fuller—all of whom
he had, as a young man, known very well, indeed. He was delightful.
The next day was Sunday, and as no one awoke me, I found
when I got downstairs that it was after ten o'clock and that
everybody, with the exception of Duggie, had gone to church.
Duggie had been up for hours taking a long walk with the dogs. He
came into the glass place on the piazza, where I had breakfast, and
read aloud about the game of the day before. Out-of-doors it was
almost as warm as in summer, so we took some books and strolled
along a cliff to a sheltered place on the rocks, and sat down in the
sun. I did n't feel much like reading, although when you 're sitting
out-of-doors in the sun I think it's rather pleasanter, somehow, to
have a book on your lap. Duggie had a shabby little volume that he
read for a minute or two at a time; then he would stop for five or
ten and look at the sea swirling around a rock away below us. After
a while I became curious to know what the book was, and the next
time he closed it over his finger I reached out and took it. The name
of it was M. Aurelius Antoninus, and it seemed to be a series of
short, disconnected paragraphs with a great many footnotes. A good
many of the paragraphs were marked. The only one I can remember
went something like this,—
"Don't act as if thou wert going to live ten thousand years.
Death hangs over thee. While thou livest—while it is in thy power, be
good."
"I suppose you 're studying this for some course," I remarked
after I had read the extract aloud. "It's so solemn I didn't think you
could be reading it for fun," I added.
"I don't suppose I am reading it for fun exactly," Duggie
laughed. "It isn't very funny to realize the force of that paragraph
when there are so many things you hope to do."
"Well, of course I know I 'm not going to live ten thousand
years, but it's so lovely down here that I don't feel a bit as if I were
n't," I said, lying back in the sun and closing my eyes.
"That's why I read the book," answered Duggie; "it's
tremendously easy to feel that way almost anywhere—down here
particularly." He was more serious, I think, than he looked.
"Why should n't one?" I asked. But he only laughed and told me
I 'd better read the book, too, and find out.
"It might be a short cut—a sort of revelation. It took me a good
while to arrive at it by myself," he added. "Why, when I first went to
Cambridge I had an idea that if a man's family were what's called
'nice,' and well known, and if he had good manners and knew a lot
of other fellows whose families were nice and well known, and
people went around saying that he 'd make the first ten of the
Dickey, and be elected into some club or other—I had an idea that
he really amounted to a great deal."
"Well, does n't he?" I asked boldly, for all that seemed to me
pretty fine.
I think Duggie was going to answer rather sharply, but he must
have decided not to, for after a moment he said:
"I suppose whether he does or not depends on the point of
view."
"From yours, I take it, he doesn't?" I mused.
"He has a lot in his favor—all sorts of opportunities that other
people have n't," Duggie admitted, "but I 've come to look at him as
quite unimportant until he tries at least to take some advantage of
them. Good Heavens! the wheels of the world are clogged with 'nice'
people," said Duggie.
"But what on earth can a person do in a place like college, for
instance?" I objected. "You 're there, and you know your own crowd,
and you 're satisfied with it because it's awfully—awfully——" I
hesitated.
"Awfully nice," Duggie laughed; "and you never see any one
else, and they 're all more or less like you—and the rest of your class
is composed of grinds, muckers, and 'probably very decent sort of
chaps, but'——" Here Duggie reached over and gave me a push that
nearly sent me into the sea. "But dontche care—I didn't mean to get
started. And anyhow there 's plenty of time."
"Only ten thousand years," I replied.
"Fleetwood's Wednesday Evenings begin next week. If you want
to remove your infamous towhead from its richly upholstered barrel
for a minute, you 'd better come around," he suggested. "Fleetwood
had his Wednesday Evenings on Friday last year because he thought
it was more quaint—but I see he 's changed back."
"He told me if I came I should hear a lion roar," I said, trying to
remember my talk with Fleetwood at The Holly Tree. At this Duggie
lay back and shrieked aloud.
"That man will be found some day torn into small, neat shreds,"
he managed to say at last.
"Why?" I asked—for I knew he liked Fleetwood.
"Why, because I'm the lion," Duggie giggled.
VII

It must be several weeks since I 've written a word in my diary. To


tell the truth, I spend so much time writing other things—things that
are printed and sold—actually—at the bookstores—that somehow my
own every-day affairs don't seem so important as they did. In a
word—I 've been made an editor of the Advocate. It seems so
wonderful to be an anything of anything with my name in print on
the front page just above the editorials—the editorials that, as
Duggie says sarcastically, have made the President and the
University what they are. Mamma was delighted at my success, and
so was Mildred—although she tried to be funny over my triolet,
When Gladys Sings, in the last number, and wrote me that, unless
Gladys were the name of a quadruped of some kind, amputation
here and there would have improved her. Even papa was pleased, I
think, although my first story made him very angry and he wrote me
a terrible letter about it. I had simply described, as accurately as I
could remember it, the time he went as "The Silver-Tongued Orator
from Perugia" to make a political speech in the country and took
Mildred and me with him. I told about the people at whose house
we stayed, described the house and recorded our conversations at
dinner and supper. That was really all there was to it. I considered it
quite harmless. The Crimson in criticising it said: "The Jimsons—a
humorous sketch by a new writer—is the only ray of sunlight in a
number devoted almost exclusively to battle, murder, and sudden
death;" a Boston paper reprinted it in full, and papa was perfectly
furious. He wrote to me saying (among several pages of other
things): "While admitting that your description of my friends is
photographic and, in an inexpensive and altogether odious fashion,
rather amusing, I take occasion to call your attention to the fact—it
seems to have escaped you—that they are, after all, my friends.
Furthermore (passing from the purely ethical to the sternly
practical), it is among just these people that you will, in the not very
distant future, be engaged in making (or trying to make) a living.
Kindly snatch a moment or two from your literary pursuits and think
this over in some of its more grim possibilities." He also rather
superfluously informed me that I would "be older some day" than I
am now. (This remark, by the way, seems to have a peculiar
fascination for men who have passed the age of fifty.) I showed the
letter to Berri, and when he had finished it he said thoughtfully: "A
few communications like this, and the keen edge of one's humor
would become a trifle dulled."
My election to the Advocate came about in the most unexpected
way possible. It's queer how things happen. Berri was sitting in my
room one afternoon apparently reading by the fire. Suddenly he
looked up and exclaimed:
"Do you realize, Tommy, that failure is staring us in the face?"
"Why, I was in hopes that it had begun to—to avert its gaze
somewhat," I answered, for I thought of course he was referring to
the hour exams—and I 've studied a little every day since that
calamity. "Besides," I added, "I don't see why you need complain;
you got through."
"Oh, I'm not talking about our studies," Berri said impatiently;
"they 're a detail. I mean that we don't seem to be getting
anywhere; we 're not turning our accomplishments to any practical
account; we 're not helping the college any and making ourselves
prominent—prominent in a lawful sense, I mean."
"But we haven't any accomplishments," I objected. "We both
tried for the Glee Club and they would n't have us; and everybody
agreed that we couldn't play football—although we went out and did
everything they told us to. We can't play the banjo or mandolin, and
it's too early in the year to find out whether we 're any good at
rowing or track athletics or baseball; so there 's nothing left. What
on earth can a person do who has n't any talent or skill or ability of
any kind?" I demanded gloomily.
"He can always write," Berri answered, "and he can always be
an editor."
"Oh! you mean we ought to try for the Crimson or something."
"Well, not the Crimson exactly," Berrisford mused; "they say you
have to work like anything on the Crimson; they make you rush
about finding out when things are going to happen, or why they
didn't happen when they said they would. That would be awfully
tiresome—because of course you wouldn't care whether they
happened or not. I 'd just like to sit around and edit; any one could
do that."
"I should think you 'd go in for the Lampoon," I suggested; for I
remembered that one of the Lampoon men had drawn a picture of
something Berri had done. Professor Snook, who knows such a lot
about folk-lore, was going to give a lecture in Sever Hall on The
Devil. It was announced on all the bulletin boards by means of
printed placards that read like this: "Thursday, November 10,
Professor John Snook will deliver a lecture on The Devil;" and under
the one outside of University, Berri wrote in pencil: "The first of a
series on personalities that have influenced me." If he got himself
noticed by the Lampoon without trying, I thought there was no
telling what he could do if he put his mind to it. We discussed the
matter awhile without, however, deciding on any definite plan.
That night we went to Fleetwood's first Wednesday Evening,
and there I was introduced to— But I 'm going too fast. I 'd better
tell about the Wednesday Evening first.
When I suggested going Berri was n't particularly enthusiastic
about it. He said he was afraid it would resemble one of his aunt's
receptions where everybody was so cultivated that it was just like
reading Half Hours with the Best Authors on a warm Sunday
afternoon. I had an idea that it might be something like that myself,
but I finally persuaded Berri to go with me notwithstanding.
I don't know what to make of myself sometimes. When I 'm
with Duggie I 'm inclined to take things rather seriously; but when I
'm with Berri it all seems like a joke. They 're so different, and yet I
feel as if I were so much a friend of both. When all three of us
happen to be together I find it most uncomfortable. Of course Berri
thought the Wednesday Evening highly amusing.
It was rather late when we arrived, and the room was crowded
with fellows, very few of whom I had ever seen before. Fleetwood
opened the door for us, with a Shakespearian quotation trembling
aptly on his lips, and led us through the crowd to his inside room,
where we left our coats and hats.
"You must come and meet my lions and hear them roar,"
Fleetwood said to us; and was about to take us across the study to
where Duggie was standing against the wall with a semicircle of
Freshmen in front of him drinking in his every word.
"Good gracious, man—you don't mean to say you got me away
over here on a cold night to hear Duggie Sherwin drool about
football," Berri exclaimed to me. Mr. Fleetwood laughed, and seemed
to think this was very funny.
"Just look how glad of the chance all those others are, you
unappreciative boy," he said reproachfully to Berri.
"Oh, well—he doesn't wake them up at a horrible hour every
morning yelling like a fiend under a shower-bath," Berri explained.
"You see, the lion and I occupy the same lair—or do lions live in a
den? I never can remember."
"Perhaps Mr. Ranny knows," said Fleetwood to a tall, studious-
looking fellow who had evidently planned his escape and was in the
act of shyly carrying it out when Fleetwood detained him. Fleetwood
introduced him to Berri and slid away to greet another man who had
just opened the door. As I moved off to join Duggie's group, Berri
gave me a queer look; but a few minutes later I happened to glance
across at him, and as the tall fellow was laughing at everything Berri
said I knew that Berri was enjoying himself.
Duggie shook hands with me and said good-evening just as if
he had n't been in my room sprawling on the floor in front of the fire
an hour and a half before, and then went on with what he was
saying to the fellows nearest him—some polite looking little chaps;
Freshmen, although I had never seen them before.
The talk was mostly about football; the games that had been
played and the ones still to come—comparative scores and the
merits and defects of players at other colleges. Of course Duggie
could discuss only with the fellows just in front of him. I think he
realized how embarrassing it would be to any of the others if he
were to single them out and address remarks to them. Besides, it
might have sounded patronizing. Yet every now and then, when
whoever was talking happened to say something funny, Duggie
somehow included the whole crowd in the laugh that followed. I
think he managed it by catching everybody's eye at just the right
time; I know that—although I was merely standing there looking on
—whenever he caught mine, I felt as if I were right in the game.
This often had the effect of causing a fellow to say something to the
fellow next to him, and so it frequently happened that people who
had joined the group merely to rubber in embarrassed silence at
Duggie, found themselves making acquaintances and talking on their
own account. I learned afterward that this was precisely what
Fleetwood and Duggie counted on. It was Fleetwood's chief reason
for having Duggie as often as he could at his Wednesday Evenings,
and Duggie's only reason for going.
Across the room there was another centre of attraction in the
person of a fine but rather pompous-looking old gentleman with a
pink face and a snowy beard. His audience was more talkative than
Duggie's, but not so large. It was n't composed entirely of
Freshmen, either. As I was standing there making up my mind to
slide through the intervening crowd and find out what he was talking
about, Berri, who had been standing with a rapt expression on the
outskirts of the second group, detached himself and came over to
me. "You simply must come and listen to him; it's perfectly thrilling,"
he said.
"I was just going over to investigate," I answered. "What 's his
specialty?"
"I don't know how to describe it exactly," Berri replied; "he's a
kind of connecting link with the literary past; he 's what
phonographs will be when we get them perfected. Dickens once
borrowed his opera-glasses on the evening of the twelfth of June
years ago, and some years later Thackeray stepped on his foot at a
dinner-party. He remembers what they said perfectly, and gets asked
out a lot. I 've heard him tell the Thackeray thing twice now, and he
's going to do it again in a minute if there 's enough of a crowd."
We went over and listened to him for ever so long, and
although Dickens had borrowed his opera-glasses and Thackeray
had stepped on his foot, he was n't in the least what Berri had led
me to expect. I found him delightful and was sorry when he had to
leave. (Berri insisted that he was driven rapidly to town to the Palace
Theatre, where he was due to appear at 10.50—between a trick
bicyclist and a Dutch comedian.)
When we had said good-by to him, Fleetwood came up bringing
a pleasant-looking chap with spectacles. (I had often seen him in the
Yard.)
"This is Mr. Paul," Fleetwood said to me, "and he wants to have
words with you."
Mr. Paul talked about the old gentleman for a minute or two,
and then said quite abruptly,—
"We 've been reading your stuff in English 83, Mr. Wood, and
the fellows think it's darned good. I wish you 'd let us have some of
it for the Advocate."
I was so astonished I just looked at him. Then he went on to
say that he wanted to print two of my themes—The Jimsons, and a
description of something I saw one night in town—and that if I
wrote a third and it turned out to be good, they would make me an
editor! He had said that the Monthly had designs on me (imagine),
and that although the Advocate did n't often do things so hastily, it
(I wonder if it's silly of me to write this down?) didn't want to lose
me. I told him that I 'd never dreamed of getting on one of the
papers and felt as if he were making fun of me. But he assured me
he was n't.
Duggie and Berrisford and I walked home together, and when
we reached my room Duggie and Berri began to squabble over
Fleetwood's Wednesday Evenings, and talked and talked until
Duggie, seeing how late it was, got undressed (talking all the time)
and left his clothes on my floor, and continued the conversation even
after he had gone into his own room, turned out the lights and got
into bed.
Berri, of course, started out by saying,—
"Well, I don't see what 's the good of it," and Duggie
immediately undertook to enlighten him. Whereupon Berri—fearing
that the attempt might be successful—took another tack and
exclaimed,—
"I should think you'd feel so ridiculous backed up there against
the wall making conversation—or perhaps you enjoy being an object
of curiosity." Duggie got very red, and I think he considered Berri
unusually cheeky and impertinent, but he did n't snub him and I 'm
sure Berri was disappointed; he loves to irritate people.
"I don't think my feelings in the matter are particularly
important," Duggie answered. "I don't see why you haul them in."
"Oh! but they are," Berri insisted. "I was n't in the least
interested in you when you were over there doing your stunts; but
here, at home—in the bosom of the family, so to speak—you 're
perfectly absorbing. Now, honestly, Duggie, don't you think that in
the end it 'll do you a lot of harm—exhibiting yourself this way, and
sort of saying to yourself: 'I am the only Duggie Sherwin; when
Fleetwood tells the Freshmen that I am going to be there, the room
is jammed'—and all that sort of thing. For of course that's what it
amounts to."
Duggie threw back his head and laughed. Then he leaned
forward and gave Berrisford (who was sitting on the floor with his
hands clasped around his knees), a neat little push that rolled him
back until he seemed to be standing on his neck and groping for the
ceiling with his feet.
"Berrisford, sometimes you make me very, very sick," Duggie
said to him.
"But own up like a man—isn't that the way you look at it?" Berri
pursued after he had collected himself.
"Of course it is n't—idiot!" Duggie declared indignantly.
"Fleetwood can't do the whole thing himself; he can't turn a lot of
shy kids into a pen and say, 'Now talk and get to know one another.'
So he asks other people to help him. Once in a while he asks me.
To-night there were two of us."
"Two Little Evas—two Uncle Toms—two side-splitting Topsies,"
Berri giggled.
"Heaven knows I can talk about other things than football,"
Duggie went on, "but I like to talk about it, and they do, too—so
why shouldn't we? And when they have enough of me they get to
talking with some one else—some one in their own class, very likely
—or maybe to two or three. Then they come back again next week,
and after a few times they find that they 've made a lot of
acquaintances, and perhaps some friends. And there you are! Their
whole four years is probably changed for them and made infinitely
more worth while, merely because Fleetwood takes the trouble to
round them up and make them feel that somebody really wants
them. It's perfectly natural that you should think his Wednesdays
funny and boresome; you always had dozens of rooms to go to from
the first day you came here, and some one in every room who was
glad to see you when you went. But I tell you it isn't that way with
everybody, and you 're not the kind that Fleetwood tries to get at."
"Why did he invite me, then?" Berri asked.
"Upon my soul, I don't know," Duggie declared sarcastically,
"but I 'd be willing to bet that if I see him first he won't invite you
again," he laughed.
Then Berri admitted that Fleetwood's idea was well enough in
theory, but doubted if it really worked.
"That tall spook I jollied this evening for a while was
exceedingly nice; but I sha'n't dash off and call on him to-morrow. I
don't suppose I'll ever see him again," Berri said.
"No, probably not," Duggie assented, "but it's altogether likely
that after time has healed the wound left by your indifference, he
may find consolation in the companionship of some one else. You
may not be able to grasp the fact, Berri, but it is a fact that 'there
are others.'" It was in the midst of this that he began to get ready
for bed.
"Why don't you open a salon yourself if you think they 're such
'life-sweeteners'?" Berri called after him when he went into his own
room.
"When I come to the Law School next year, I'm going to,"
Duggie shouted back, "but you 'll never see the inside of it; I 'll tell
you that right now."
I did n't join in the discussion at all, for I got to thinking how
lucky I had been from the first. Mamma overheard an old woman on
a piazza say that she made the "young men" change their shoes
when it was "snow-in'"—and that was all there was to it. That
chance remark led to my living in the same house with Duggie and
Berri; and what a difference it has made! Without Berri I never in
the world should have known such a lot of people in so short a time;
and without Duggie—well, I think I understand what my adviser
meant when he said he was glad I knew Duggie.
There has been one Advocate meeting since my election and I
thought it was great. All the editors meet in the Advocate President's
room on Tuesday evening to hear the Secretary read the
manuscripts that have been sent in or collected from the English
courses during the week. It took them a long time to settle down to
business; in fact no one seemed to want to hear the manuscripts at
all—although I secretly thought this would be very interesting—and
several fellows made remarks and tried to interrupt (the poetry
especially) all the time the Secretary was reading. But he read on in
a businesslike voice and never paid any attention to them except
once, when he grabbed a college catalogue from the table, and
without looking away from the page shied it at a fellow who was
repeating the verses the Secretary was trying to read—only
repeating them all wrong and making them sound ridiculous. In the
case of most of the contributions the fellows began to vote "no"
before they had read them half through; but several of them were
hard to decide on, and the board had a lively time making up its
mind. After the reading we sat around the fire and had beer and
crackers and cheese while (as several of the manuscripts expressed
it) "the storm howled without."
A few afternoons ago the Secretary (he has such a queer name
—it's Duncan Duncan), came to my room to see how much I had
done on a story I was writing. It was a little after six o'clock when he
got up to go, and as he was on his way to dinner at Memorial he
asked me to dine with him. I had never been to Memorial at meal
time and was glad of the chance to go. It's a very interesting
experience, although I think I prefer the comparative peacefulness
of Mrs. Brown's as a usual thing.
We were joined in the Yard by a friend of Duncan's who sits at
the same table. Duncan is a thoughtful, rather dreamy kind of
person (he writes a lot of poetry for the Advocate), and on the way
over he told me how much he enjoyed living at Memorial—that he
never got tired of looking up at the stained-glass windows and the
severe portraits.
"Even with the crowd and clatter there 's always something
inspiring about its length and height," he said. "It has a calmness
and dignity that quite transcend the fact of people's eating there. It's
so academic."
"It's so cheap," the other fellow amended; but Duncan did n't
mind him and became almost sentimental on the subject.
Well, I felt sorry for Duncan. We had hardly begun on our
turkey and cranberry sauce when two of the colored waiters got into
the most dreadful fight and rushed at each other with drawn forks.
All the men jumped up on their chairs and waved their napkins and
yelled: "Down in front—down in front!" and "Trun him out!" As the
newspapers say of the Chamber of Deputies, "A scene of
indescribable confusion ensued." It was several minutes before the
combatants were hustled off to the kitchen and we could go on with
our dinner. Then a party appeared in the visitors' gallery—a middle-
aged man, two women, and some girls. One of the girls was
decidedly pretty and attracted everybody's attention the moment she
leaned over the rail. The man, however, was what caused the
demonstration in the first place. He didn't take his hat off, which
Duncan says always makes trouble. I don't think anybody really
cares one way or the other, but it furnishes an excuse for noise. A
murmur of disapproval travelled across the room and grew louder
and louder until the man with a genial air of "Ah—these boys have
recognized me," came to the front of the gallery and bowed. He took
off his hat, which produced a burst of applause from below, and
then put it on again, which changed the clapping of hands to
ominous groans. The poor thing looked mystified and embarrassed,
and I don't know how it would have ended if the pretty girl hadn't
just at that instant been inspired to pluck a big rose from her belt
and toss it over the rail. It fell with a thud in the middle of our table
and twenty-four eager hands shot out to seize it. I grabbed
instinctively with the others, and with the others I 'm exceedingly
ashamed of what happened. The tablecloth and all the dishes were
swept off, and in the scrimmage that followed the table was
overturned. I have a terrifying, hideous recollection of everybody in
the world kneeling on my chest and of something warm and wet on
my face and neck. Then Duncan was saying,—
"It's all right, old man—lie perfectly still; you 've cut yourself a
little, but it doesn't amount to anything. Only don't exert yourself."
He looked so scared and white that I began to be frightened myself
and tried to get up. But he and some of the other fellows very gently
restrained me, saying that I was all right in the peculiar, hurried
fashion that, more than anything else, convinces you that you're all
wrong. Duncan's friend and another fellow were mumbling
somewhere near me; I caught these fragments of their
conversation: "It must be an artery—eight or ten minutes if it is n't
attended to—Doctor Banning and Doctor Merrick—telephoned—don't
talk so loud—he might hear."
Then I lay quite still and closed my eyes and tried to think.

VIII

Looked at in one way, it was a humiliating thing to have happen; but


on the other hand, after it was all over, I was able to derive
considerable satisfaction from the fact that I had n't lost my
presence of mind. The remarks I overheard as I lay on the floor of
Memorial were anything but reassuring. I realized that in the
scrimmage for the rose I had been submerged in china, glass, and
cutlery,—that some of these things had severed one of my arteries
and that the worst might happen. Of course I was very much
frightened at first, and it was then that I tried to get up; but after
they restrained me, I sank back and began to think of poor mamma.
I was on the point of asking for writing materials, but on
remembering that an accident of this kind was always attended by a
sort of dreamy weakness, I became—actually—so languid that I
recall telling myself that it would be of no use—I would n't have
strength with which to write, even if a pen were thrust into my
hand. So I went on thinking about mamma until suddenly a man
with a pointed beard (I have since learned he was a medical student
who happened to be dining with some friends at Memorial) dropped
on one knee beside me and with rapid, skilful fingers began to open
my shirt. Then he stopped very abruptly, and with the most
disgusted expression I ever saw, turned toward the light and
examined his fingers. After which he got up, brushed the dust from
his knee, and said in a loud, peevish voice,—
"Tell that child to get up and go home and wash the cranberry-
sauce off his face and neck and put on clean clothes," which I did as
quickly as possible without even waiting to say good-bye to Duncan.
They don't call me "Tommy Trusting" any more. It became
"Cranberry" for a day or two, then it was shortened to "Cranny," and
now it's "Granny"—"Granny Wood." Berri says that it has a ring of
finality to it, and that I 'll never be known by any other name.
Since the great game (I don't believe I 've touched upon the
great game), the college seems to have settled down once more to
an every-day sort of existence, with the Christmas holidays looming
up now and then in letters from home. (As I was going out this
morning, the postman met me at the gate and gave me four letters
with the Perugia postmark. It 's funny how my feelings toward that
poor man vary. When he hands me letters from home, I think he 's
one of the nicest-looking persons I ever saw, but when he doles out
a lot of bills, he seems to have a hard, cynical expression that I hate.
I meet him at The Holly Tree occasionally, where he goes to snatch a
nourishing breakfast of coffee and lemon-pie.)
I have n't alluded to the great game for several reasons—the
chief one being that (as Berri says when people explain why they
didn't pass certain exams), "I dislike post-mortems." I suppose it
might have been, in various ways, a more distressing event than it
actually was. The seats, for instance, might have collapsed and killed
all the spectators; there might have been a railway collision on the
way down; there might have been an earthquake or a tidal-wave.
That none of these things happened is, of course, cause for
congratulation—if not for bonfires and red lights on Holmes' Field. It
is always well, I suppose, to have something definite to rejoice over.
The long trip in the train back to Boston after the game, with every
one hoarse and tired out and cross and depressed, was— But I had
determined not to mention it at all.
Poor Duggie! I know it nearly killed him. He has tried to refer to
it philosophically and calmly in my room once or twice since then;
but he never gets very far. He knows what he wants to say and
ought to say, but he 's so intimate with Berri and me that I don't
think he altogether trusts himself to say it. I imagine he finds it
easier to talk to comparative strangers. I was afraid at first that Berri
was going to find in the subject a sort of inexhaustible opportunity
for the exercise of his genius for making people uncomfortable; but
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