100% found this document useful (1 vote)
470 views

Java 1 Basic syntax and semantics Software Development Poul Klausen - The ebook in PDF and DOCX formats is ready for download

The document provides an overview of various eBooks available for download at ebookmeta.com, including titles on Java programming, data modeling, and literature. It highlights the book 'Java 1: Basic Syntax and Semantics' by Poul Klausen, which serves as an introduction to Java programming, covering fundamental concepts and providing exercises for practice. The document also outlines the structure and purpose of the book series focused on software development, emphasizing hands-on learning through coding examples and exercises.

Uploaded by

bhpveugen
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 (1 vote)
470 views

Java 1 Basic syntax and semantics Software Development Poul Klausen - The ebook in PDF and DOCX formats is ready for download

The document provides an overview of various eBooks available for download at ebookmeta.com, including titles on Java programming, data modeling, and literature. It highlights the book 'Java 1: Basic Syntax and Semantics' by Poul Klausen, which serves as an introduction to Java programming, covering fundamental concepts and providing exercises for practice. The document also outlines the structure and purpose of the book series focused on software development, emphasizing hands-on learning through coding examples and exercises.

Uploaded by

bhpveugen
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/ 67

Read Anytime Anywhere Easy Ebook Downloads at ebookmeta.

com

Java 1 Basic syntax and semantics Software


Development Poul Klausen

https://ebookmeta.com/product/java-1-basic-syntax-and-
semantics-software-development-poul-klausen/

OR CLICK HERE

DOWLOAD EBOOK

Visit and Get More Ebook Downloads Instantly at https://ebookmeta.com


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

Exploring the Syntax and Semantics of South Asian


Languages 1st Edition Reena Ashem

https://ebookmeta.com/product/exploring-the-syntax-and-semantics-of-
south-asian-languages-1st-edition-reena-ashem/

ebookmeta.com

Java 17 Quick Syntax Reference 3rd Edition Mikael Olsson

https://ebookmeta.com/product/java-17-quick-syntax-reference-3rd-
edition-mikael-olsson/

ebookmeta.com

NoSQL and SQL Data Modeling: Bringing Together Data,


Semantics, and Software First Edition Hills

https://ebookmeta.com/product/nosql-and-sql-data-modeling-bringing-
together-data-semantics-and-software-first-edition-hills/

ebookmeta.com

Religion in America The Basics 2nd Edition Michael


Pasquier

https://ebookmeta.com/product/religion-in-america-the-basics-2nd-
edition-michael-pasquier/

ebookmeta.com
The Sun Dragon First Edition,New Edition Jay Annabelle

https://ebookmeta.com/product/the-sun-dragon-first-editionnew-edition-
jay-annabelle/

ebookmeta.com

Candlelight Promise A Kwanzaa Kisses Holiday Romance 1st


Edition Lia Violet

https://ebookmeta.com/product/candlelight-promise-a-kwanzaa-kisses-
holiday-romance-1st-edition-lia-violet/

ebookmeta.com

Selling and Sales Management, 11e 11th Edition David


Jobber

https://ebookmeta.com/product/selling-and-sales-management-11e-11th-
edition-david-jobber/

ebookmeta.com

Trauma and Motherhood in Contemporary Literature and


Culture

https://ebookmeta.com/product/trauma-and-motherhood-in-contemporary-
literature-and-culture/

ebookmeta.com

Modified Posterior Approach to the Hip Joint 2nd Edition


K. Mohan Iyer

https://ebookmeta.com/product/modified-posterior-approach-to-the-hip-
joint-2nd-edition-k-mohan-iyer/

ebookmeta.com
Resurrected as a Drow 2 1st Edition Logan Jacobs

https://ebookmeta.com/product/resurrected-as-a-drow-2-1st-edition-
logan-jacobs/

ebookmeta.com
Poul Klausen

Java 1: Basic syntax and


semantics
Software Development
Java 1: Basic syntax and semantics: Software Development

1st edition

© 2017 Poul Klausen & bookboon.com

ISBN 978-87-403-1689-6

Peer review by Ove Thomsen, EA Dania

Contents
Foreword 6
1 Introduction 8
2 Hello World 11

2.1 NetBeans 11

2.2 The source code 15


2.3 Run the program 16

2.4 The NetBeans project 17

2.5 Gedit 19

2.6 Something about comments 21

2.7 Example: Kings 22

Exercise 1 23

Exercise 2 23

3 Commands and console programs 24

3.1 Commands 24

3.2 Example: PrintAddress 27

Problem 1 28

3.3 Console programs 29

Problem 2 32

4 Variables and data types 33

Exercise 3 38

4.1 Operators 38

Exercise 4 44
Exercise 5 45

4.2 Literals 46

4.3 Objects 49

Exercise 6 59

Problem 3 59

4.4 Example: Cubes 63

Exercise 7 65

4.5 Arrays 67

Exercise 8 71

4.6 Example: CupProgram 72

4.7 Multidimensional arrays 76

Exercise 9 78

5 Program control 79

5.1 The if statement 79

Exercise 10 81

Problem 4 82

Problem 5 83
5.2 do and while statements 84

Exercise 11 85

Problem 6 87

5.3 The for statement 88

Exercise 12 92

Exercise 13 92

Problem 7 94

5.4 The switch statement 94

Exercise 14 96

5.5 Return statement 97

5.6 Break and continue 97

Problem 8 101

Problem 9 102

6 ArrayList 104
7 Comparison and sorting 107
8 Files 114

8.1 Text files 114


Excercise 15 118

8.2 Serialization of objects 119

Exercise 16 121

9 Final example 123

9.1 Design 126

9.2 Programming and test 130

Appendix A 131
Foreword
This book is the first in a series of books on software development.
The programming language is Java, and the language and its syntax
and semantics fills obviously much, but the books have also largely
focus on the process and how to develop good and robust
applications. The subject of the current book is an introduction to
the programming language Java with an emphasis on basic language
syntax and semantics, but it is also a book about what programming
in general is and how to practically write and test simple programs.
The book requires no knowledge about programming or the
language Java, and the goal is to show how to get started writing
computer programs. After reading the book and worked through the
book’s exercises and problems, the reader should be able to write
simple console applications in the language Java.

As the title says this series of books deals with software


development, and the goal is to teach the reader how to develop
applications in Java. It can be learned by reading about the subject
and by studying complete sample programs, but most importantly by
yourself to do it and write your own programs from scratch.
Therefore, an important part of the books is exercises and problems,
where the reader has to write programs that correspond to the
substance being treated in the books. All books in the series is built
around the same skeleton and will consist of text and examples and
exercises and problems that are placed in the text where they
naturally belongs. The difference between exercises and problems is
that the exercises largely deals with repetitions of the substance that
is presented in the text, and furthermore it is relatively accurately
described what to do. Problems are in turn more loosely described,
and are typically a little bigger and there is rarely any clear best
solution. These are books to be read from start to finish, but the
many code examples, including exercises and problems plays a
central role, and it is important that the reader predict in detail
studying the code to the many examples and also solves the
exercises and problems or possibly just studying the recommended
solutions.

All books ends with one or two larger sample programs, which focus
primarily is on process and an explanation of how the program is
written. On the other hand appears the code only to a limited extent
– if at all – and the reader should instead study the finished program
code perhaps while testing the program. In addition to show the
development of programs that are larger than the examples, which
otherwise is presented, the aim of the concluding examples also is to
show program examples from varying fields of application.

Most books also ends with an appendix dealing with a subject that
would not be treated in the books. It may be issues on the
installation of software or other topics in computer technology, which
are not about software development, but where it is necessary to
have an introductory knowledge. If the reader already is familiar
with the subject, the current appendix can be skipped.
The programming language is, as mentioned Java, and besides the
books use the following products:

NetBeans as IDE for application development

MySQL to the extent there is a need for a database server (from


the book Java 6 onwards)

GlassFish as a web server and application server (from the book


Java 11 onwards)

It is products that are free of charge and free to install, and there is
even talk about products, where the installation is progressing all by
itself and without major efforts and challenges. In addition, there
are on the web detailed installation instructions for all the three
products. The products are available on Windows and Linux, and it
therefore plays no special role if you use Linux or Windows.

All sample programs are developed and tested on machines running


Linux. In fact, it plays no major role, as both Java and other
products work in exactly the same way whether the platform is one
or the other. Some places will be in the books where you could see
that the platform is Linux, and this applies primarily commands that
concerning the file system. Otherwise it has no meaning to the
reader that the programs are developed on a Linux machine, and
they can immediately also run under Windows unless a program
refers to the file system where it may be necessary to change the
name of a file.
Finally a little about what the books are not. It is not “how to write”
or for that matter reference manuals in Java, but it is as the title
says books on software development. It is my hope that the reader
when reading the books and through the many examples can find
inspiration for how to write good programs, but also can be used as
a source collection with a number of examples of solutions to
concrete everyday programming problems that you regularly face as
a software developer.
1 Introduction
A computer program is a series of commands executed in a certain
order, and together they solve a specific task. A program is written
as a text document that contains all the necessary commands. This
document is called the program code or source code. The individual
commands must be written in a very precise way for the computer
to understand them, and it is here that programming languages
comes into the picture. A programming language lays down precise
rules for how the commands should be entered. There are many
programming languages, and although they are different, each with
their advantages and disadvantages, the similarities outweigh the
differences, and once you have learned a language, it is easy to
learn the next. The following are used throughout the Java
programming language, which is a widely used languages on many
platforms. How the individual commands and orders exactly must be
written is called the language’s syntax. What the individual
commands are doing or performing is called the language’s
semantics.

As mentioned above, a program is written as a text document (in


practice several or many), and it is simply a document of commands.
Commands are also called statements. These commands or
statements being only text, the machine can not immediately
perform the comands, but they must be translated into an internal
format that the computer understands. This process is called
translation or compilation and is performed by a program that can
convert statements written in a particular programming language to
the computer’s internal commands. The program is usually called a
compiler. During the translation the program is checked for errors,
and if there are errors, you get an error message, and the errors
must then be corrected before the program is translated again. Not
all errors are found during translation, but only syntax errors, which
covers the issue where a statement is not written in accordance with
the programming language’s rules. A translated program can easily
contain errors, for example a miscalculation.

To write a program you must of course learn the programming


language that is selected, but also you must learn how the solution
of a task can be formulated by statements in the language. It is the
latter that is the most difficult, and there is rarely a clear solution. A
solution of a problem by means of a program is also called an
algorithm. Programming is largely a matter of writing algorithms,
something that I will return to several times.

When you have to write software, you need a tool that can be used
to enter the program code, and in principle you could use a simple
input program (a text editor) and then the compiler, but in practice
you will always use a specific development tool, as it makes the job
much easier. In the following I will everywhere use NetBeans, a
development tool for a wide variety of tasks, including writing code
in Java. It is an integrated software package, which includes all the
tools necessary for the development of a number of different types
of programs.

Java is an object oriented programming language. The fundamental


architectural element in a program is a class, and from the
programmer’s point of view a Java program consists of a family of
classes that collectively define all the application’s features and
functionality. Writing a program is thus to define – design – and
write the code to the program’s classes. Nothing in Java exists
outside of a class. A program will also always apply other classes
that are not written by the programmer, but classes coming from the
Java API, and thus is available for the programmer as finished
components. One of the program’s classes have a special role as the
program’s “entry point” and the place where the program starts and
this class should be written with a special naming, but it is almost
the only formal requirements for the architecture of a Java program.

Java is technically both a platform and a programming language.


Seen as a programming language, it is a high-level language, which
is characterized by

it is a simple language

it is an object-oriented language

the language is architecture neutral

Java programs are portable

it supports development of multithreaded applications


it supports the development of distributed applications

it supports the development of programs with strong security

development of effective programs

development of robust programs

development of maintenance-friendly and dynamic programs

All Java code are as mentioned written as plain text files – which
filename must have the extension .java – and then these files are
translates to .class files. The translation is performed by the Java
compiler called javac. Java class files do not contain machine code
for a particular platform, but rather so-called bytecode, which is the
machine code for the Java Virtual Machine, which is a virtual
computer, commonly referred to as VM or JVM. The program
(consisting of a set of class files) can then be carried out by the
virtual machine, which is a program that is running on a particular
machine. Since Java and thus the virtual machine is available for
many different operating systems, the same class files can run on
many machines for example Windows, Solaris, Linux, etc.

With a platform wee understand the hardware and software, where


a program is running, and in relation to an usual PC you can think of
Windows, Linux and Mac machines. Compared to this is a Java
platform a software-only solution that runs on a different hardware
based platform. The Java Platform consists in principle of two parts:

JVM, the Java Virtual Machine


an API, the Java Application Programming Interface

where the last is a large collection of ready to use software


components that a program can use. They are grouped into libraries
called packages, which consists of classes and interfaces.

The result of the above technology is that Java programs, in


principle, is a bit slower than programs translated into an actual
physical machine. However, since Java was born there has been an
incredible number of improvements and optimizations of both the
compiler and the virtual machine, so the difference in performance is
negligible if at all measurable.
2 Hello World
The subject of this chapter is to show how to write and run a Java
program using NetBeans and the aim is solely to get started. There are
several kinds of programs, or you can say that the programs can be
categorized in several ways, but in the first books I will look at three
types of programs:

commands, which is a program that is typically performed from a


command window (a Terminal ) where you enters the program’s
name that may be followed by one or more arguments

consol applications, which also is performed at a command prompt,


but here the program runs in a dialogue with the user, where the
user must enter values when the program is executed

GUI-programs, where the program opens one or more windows with


components as buttons and input fields used by the user to interact
with the program

This division is only for practical reasons, as I will sometimes


characterize the program examples in relation to this, but common to the
three types of programs is that they are standalone applications that run
on a single machine and without using resources on other machines.

I’ll start with the classic Hello World program, a program that prints a
text on the screen. It is an example of a command, but it is also an
example of a program that has absolutely no practical interest. Although
it is a simple program, it will nevertheless treat a number of basic
principles that apply to all Java programs.
2.1 NetBeans
As mentioned a Java program is written as text files, which will then be
translated. When the files are translated without errors the program can
be executed by the virtual machine. In practice is always used a
development tool, which is a program or software package that
integrates all the functions that a developer needs. Such a tool is usually
called an IDE (Integrated Development Environment), and there are
several, but I will everywhere use NetBeans, which contains everything
that is needed, and the following requires that both Java and NetBeans
are installed on the machine. Do not have it, you can start by reading
Appendix A which explains how to download and install both Java and
NetBeans.

To write the first Java program, open NetBeans and create a new
project. In the menu, choose

File | New Project (see below)

A NetBeans project creates all the necessary files required to develop


and test the program and eliminates a variety of configurations that are
otherwise necessary. Using NetBeans you can build and run the program
just by clicking the menu. To create the project, you must note that in
this case,

Java is marked in Categories

Java Application is selected in Projects

but otherwise I have not done anything in the first window.


When you then click Next you get the following window:

Here I:
Entered HelloWorld as Protect Name

Selected /home/pa/doc/noter/note01 for Project Location

Regarding the latter, it is just a question that I have decided that the
project should be created in the /home/pa/doc/notes/note01 direcory. I
have also decided that the project should be called HelloWorld. NetBeans
will then create a folder

/home/pa/doc/noter/note01/HelloWorld

and all project files are placed by NetBeans in this folder. You should
note that there is a checkmark in the Create Main Class, which is
important.

When you then click Finish, the project is created and NetBeans displays
multiple windows:
Projects window, where all the project’s components are organized in
a hierarchy

Source Editor, where there is an open file called HelloWorld.java

Navigater, which can be used to quickly find a specific item

Source Editor contains the program’s code, and as you can see,
NetBeans automatically creates a skeleton for a program. Actually, it’s a
full-fledged program – it performs nothing not yet. The program code
consists of Java statements and comments. Comments are removed by
the compiler and does not affect the finished program. They are inserted
solely for the sake of us people who should read and understand the
program code.

2.2 The source code


Below I’ve shown the finished program after I have changed or removed
the comments that NetBeans has generated and written a single
statement:

There is only one comment back, which is at the top and says something
about what the program does. The rest of the code is Java statements. A
Java program consists of classes, and in this case there is one class
called HelloWorld and thus has the name that I chose as project name.
The class consists of a method called main(), which has a single
statement – not created by NetBeans, but as I entered. It is a statement
that prints a text on the screen.

The code is simple, and so far you just accept that it should be written,
as shown above, but there is however a few things that you should note.

Java is case-sensitive, so everywhere you must distinguish between


uppercase and lowercase letters.
Every Java program consists as already mentioned by at least one class
here called HelloWorld. A class consists of variables and methods. In this
case, the class has only one method called main(), which is the method
that is called when the program starts. A method consists of statements
that can be perceived as commands that perform one or other on the
machine. That a method is called means that the methods statements is
performed. Note that the method main() must be prefixed by the words
public static void. The explanation will follow. In this case, main() has
only a single statement, that write a text on the screen.
System.out.println() is actually a method in a class PrintStream, that
among other things, represents the screen. When the program is
running, nothing happens than the println() statement in main() is
performed that prints a text on the screen.

Note that in Java, each statement ends with a semicolon – above there
is a semicolon after System.out.println(). It tells the compiler where a
statement ends.

In Java classes are grouped in so-called packages. A class’s full name


consists of the package that the class it is grouped under, as well as the
class name. NetBeans automatically define a package for a program that
is the application name written in lowercase, and the first statement is a
package statement indicating the class’s package. A package statement
must be the first statement in the file that contains a class, but can be
prefixed by a comment. Note that in Java you generally has to place
each class in its own file, but more on that later.

2.3 Run the program


When the program is written as above (without errors), you can from the
menu in NetBeans choose

NetBeans will automatically translate the program, and if it not contains


errors, the program will be performed:

If the program contains errors, the result could be the following:

The program then is not performed, and the translator instead offers an
error message, and the error must then be corrected before trying to run
the program again.

2.4 The NetBeans project


If you open Files you can as shown below find the class file, which is the
translated program:
HelloWorld.class is an example of a complete Java program that can run
on a specific machine. Apparently, the program is tied closely to
NetBeans and performed using NetBeans, but it is not the case. In the
menu in NetBeans choose

and the program is translated again, and if you opens Files you will
discover that that there is created another folder called dist, which
contains two files (see below). Here is HelloWorld.jar a package (actually
a compressed zip file) containing the program files – only the translated
class files and other ancillary files that are necessary for the program to
run. In this case, there are actually only two.
If you copy the file HelloWorld.jar to a folder – for example temp – and if
you open a Terminal, stand in this folder and perform the following
command:

the program is performed:

Here the command java is a message to Linux to start the Java runtime
system and execute the program HelloWorld.

2.5 gedit
Above I have written and performed a Java program using NetBeans,
and in the following, all programs will be developed in this way.
NetBeans is a large and complex program, and until this place, you have
seen only a very small fraction of what the program can. The program is
relatively user-friendly, and I will not give any general description of the
program and its possibilities, but I will mention important features as I
need them in the individual examples. NetBeans is similar to all other
IDEs for software development, so the forces you use to learn more
about the program, is definitely not wasted. Using an IDE for developing
applications provides in practice such large benefits that it makes no
sense to develop programs in other ways, but in principle you can, and I
will in this section show how to write the program Hello World without
NetBeans.

I start by creating a directory named Hello in my home directory. Then I


open gedit and enter the code below. It is important to enter the code
exactly as shown below, and especially you should be aware that it is
case-sensitive. You should also be aware that you do not insert extra
spaces. Note also that the text is displayed in several colors. This is
because gedit know Java, and thus highlights reserved words.

When the program is written, I save it in the folder Hello and call it
HelloWorld.java. Again, please note upper and lower case and the
filename must have the extension java written in lower case. Then I
open a Terminal and set the current directory to the folder Hello. Here I
performs the following command:

javac is the name of the compiler, and the result is that the program is
being translated, and creates a file with the translated program called
HelloWorld.class:

Then you can execute the program as follows:

As mentioned, I practically always use NetBeans, and even if the above


is not of great practical interest, it may nevertheless serve to illustrate
what NetBeans is doing. It is basically an advanced editor program that
help you when you enter code and point out incorrect entries. Moreover
NetBeans calls both the javac compiler and the runtime system java.
NetBeans will provide support to the programmer and support the
development of large and complex applications. Therefore even small
NetBeans projects contains many directories and files, and it can hide
what really is the program itself. This example can show how little it
really is.

2.6 Something about comments


As you have seen, NetBeans inserts comments in the program’s code.
They will as mentioned be ignored by the compiler and are inserted for
the sake of the people who must read and understand the code.

There are three types of comments. The first starts with /* and ends
with */ and everything in between these character combinations is
considered as a comment, for example

which is the comment that NetBeans inserts at the beginning of a new


source file. Another kind of comments start with the characters /** and
ends with */, for example

Again, everything between the start and end character combinations is


comments, but there can be inserted special symbols that are
interpreted by a tool to generate html documentation of the program
code, but about that later. The last type of comment has the form
That comment can be inserted anywhere, and all after the characters //
to the end of the line are considered as a comment.

This is the syntax for inserting comments in the code, but a whole other
thing is what you should write. Also I come back to that later, but
generally you have to write what you think might be valuable at a later
reading of the code. What it is, is certainly not unique, and it can be
good inspiration to examine what comments others have inserted into
programs.

2.7 Example: Kings


The example is a program called Kings, in principle it is written in the
same way as HelloWorld, but the program prints the following text:

The final code is shown below:


The only difference compared to HelloWorld is that this time there are
several System.out.println() statements.

Exercise 1
Write a program, as you can call Digits, that on the screen prints the
following table:

Exercise 2
Write a program that you can call Label, that prints your name, your
address and your email address, for example
3 Commands and console
programs
In the previous section I divided the programs into three categories,
and in this chapter I will look at commands and console programs. In
principle there is no big difference, and the division alone has to do
with how the user is transferring data to the program. Both
HelloWorld and the example Kings from the previous chapter are
examples of commands.

3.1 Commands
Every Java program must have a main() method that has the
following signature:

For the moment you should ignore the meaning of the words public,
static and void and just accept that they should be there, but the
main() method is the place where the program starts. After the
method name is a parameter in parentheses, indicating arguments
from the command line that can be transferred to the program.
Consider the following program:
args is an array, as I explains later, but the arguments that are
transferred on the command line, are in the program referred to as

and so on. An argument is a text string, and arguments are


separated by spaces. If, for example you copy the file Command.jar
to the temp folder, the program can be perform as follows:

There are two arguments, called respectively Svend and Knud, and
the program prints the two arguments of the screen. If you execute
the program in the following way:
the result is the same. This time there is three arguments, but only
the first two are used in the program. If, however, the application
performs without having two arguments, you get an error:

The reason is that the second argument does not exist, and therefore
fails the statement:

The example shows, what I will understand by a command. Another


question is how to test the application from NetBeans when you has
to transferre arguments. This can be done through the menu to
choose

Here you must select the category Run, where you will be able to
enter the arguments:
Note that contains the argument spaces, it is necessary to specify
them in quotes.

3.2 Example: PrintAddress


The following program will print the name and address of a person,
but so that the values to be printed are transferred on the command
line. The program is therefore a command. The program is called
PrintAddress, and threre must be transfered four arguments on the
command line. Arguments on the command line are separated by
spaces, and if an argument contains spaces, it is necessary to put the
argument in quotes. Then the runtime system will perceive it as one
argument. An example of running the program could, for example be
as shown below:
For writing the program I have in NetBeans created a project called
PrintAddress. The program code can then be written as follows:

The statements in the main() method is all System.out.println()


statements that prints a line on the screen. The first only prints a
text, while the second prints a blank line. The third prints a text
followed by the value of args[0], which is the person’s name. Note
particularly the plus operator, which means string concatenation,
wherein the text is added after the other. The last two
System.out.println() statements works in principle in the same way.

A program like the above are not robust, as it will fail if not
transferred the right number of arguments. You should also note that
the program does not test the arguments (which incidentally is also
not so easy), but simply prints the arguments as they are.

Problem 1
You should write a program for a library that can print a recall of a
book. When the program is executed, you must on the command line
transfer five arguments:

borrower’s name

borrower’s address

borrower’s zipcode and town

ISBN of the book

the books title

An example of an execution of the program might be:


3.3 Console programs
Compared to a command a console program (in this books) is a
program that performs a dialogue with the user, where the user must
enter data.

Above I have shown a program that prints the name and address of a
person when the values are passed as arguments on the command
line. Below is the same program, but this time the user must enter
the values during running the program. There is thus a dialogue with
the user.
As you can see, the code has been substantially larger, and there is
also new things that has to be explained.

To enter text, you must have an object that represents the keyboard
and provides a service available for entering text. In addition I apply
a Scanner that use the objekt System.in that just represents the
keyboard. Scanner is a class that is not readily available, and
therefore there is added an import statement that refers to the
package containing the class Scanner. in is then an object that can
be used to enter a text. The next line prints a text on the screen,
telling the user to enter the name. It happens with
The text that the user enters, must be stored somewhere, and for
that purpose a variable is used. Variables are considered in the next
chapter, but a variable is a place where you can store a value. An
example could be the statement

Here, the text that the user enters is stored in the variable name. The
next statements are identical in principle and are used for entering
other values. The last statements are used to print the result and is
similar in principle to the previous version of the program, but the
arguments args[0], args[1], … are replaced with variables. If you run
the program (from NetBeans), the result could be as shown below:

Today it is rarely – if ever – developing console applications, and


when is a need for a program with a user dialogue (and it is of
course often), you write a Windows or GUI program. Console
programs may, however, for testing and learning be useful, and
therefore it is excellent to know how to write a simple console
program.
Problem 2
You must solve the same task as in problem 1, but instead of
transferring values as arguments on the command line, you must
enter information about

borrower’s name

borrower’s address

borrower’s zipcode and town

ISBN of the book

the books title

when then the program is running in a dialogue with the user. The
program should print the same recall as in problem 1.
4 Variables and data types
Programs has to deal with data, and for that they need a way where
to save or store data. To that purpose programs use variables that
are items, where the program may store a value. You must note that
I have already used variables associated with data entry. A variable is
characterized by

a name

a type

operators

Variables must have a name, so you can refer to them in the


program. Java is similar to other modern programming languages
relatively flexible in terms of naming variables, but the following shall
(should) be met:

a variable name must start with a letter, a dollar sign ‘$’ or an


underscore ‘_’

a variable name should always start with a lowercase letter, and


one should avoid ‘$’ and only occasionally use ‘_’

then have to follow any number of characters consisting of letters,


digits, $ and _

a name must not contain spaces


Another Random Scribd Document
with Unrelated Content
infinite ripeness. In a word, he is an artist accomplished even to
sophistication, whose constant theme is the unsophisticated. Sometimes, as
in Kidnapped, the art is so ripe that it lifts even the subject into the general
air: the execution is so serious that the idea (the idea of a boy’s romantic
adventures), becomes a matter of universal relations. What he prizes most
in the boy’s ideal is the imaginative side of it, the capacity for successful
make-believe. The general freshness in which this is a part of the gloss
seems to him the divinest thing in life; considerably more divine, for
instance, than the passion usually regarded as the supremely tender one.
The idea of making believe appeals to him much more than the idea of
making love. That delightful little book of rhymes, the Child’s Garden,
commemorates from beginning to end the picturing, personifying,
dramatising faculty of infancy—the view of life from the level of the
nursery-fender. The volume is a wonder for the extraordinary vividness
with which it reproduces early impressions: a child might have written it if
a child could see childhood from the outside, for it would seem that only a
child is really near enough to the nursery floor. And what is peculiar to Mr.
Stevenson is that it is his own childhood he appears to delight in, and not
the personal presence of little darlings. Oddly enough, there is no strong
implication that he is fond of babies; he doesn’t speak as a parent, or an
uncle, or an educator—he speaks as a contemporary absorbed in his own
game. That game is almost always a vision of dangers and triumphs, and if
emotion, with him, infallibly resolves itself into memory, so memory is an
evocation of throbs and thrills and suspense. He has given to the world the
romance of boyhood, as others have produced that of the peerage and the
police and the medical profession.
This amounts to saying that what he is most curious of in life is heroism
—personal gallantry, if need be with a manner, or a banner, though he is
also abundantly capable of enjoying it when it is artless. The delightful
exploits of Jim Hawkins, in Treasure Island, are unaffectedly performed;
but none the less “the finest action is the better for a piece of purple,” as the
author remarks in the paper on “The English Admirals” in Virginibus
Puerisque, a paper of which the moral is, largely, that “we learn to desire a
grand air in our heroes; and such a knowledge of the human stage as shall
make them put the dots on their own i’s, and leave us in no suspense as to
when they mean to be heroic.” The love of brave words as well as brave
deeds—which is simply Mr. Stevenson’s essential love of style—is
recorded in this little paper with a charming, slightly sophistical ingenuity.
“They served their guns merrily when it came to fighting, and they had the
readiest ear for a bold, honourable sentiment of any class of men the world
ever produced.” The author goes on to say that most men of high destinies
have even high-sounding names. Alan Breck, in Kidnapped, is a wonderful
picture of the union of courage and swagger; the little Jacobite adventurer, a
figure worthy of Scott at his best, and representing the highest point that
Mr. Stevenson’s talent has reached, shows us that a marked taste for tawdry
finery—tarnished and tattered, some of it indeed, by ticklish occasions—is
quite compatible with a perfectly high mettle. Alan Breck is at bottom a
study of the love of glory, carried out with extreme psychological truth.
When the love of glory is of an inferior order the reputation is cultivated
rather than the opportunity; but when it is a pure passion the opportunity is
cultivated for the sake of the reputation. Mr. Stevenson’s kindness for
adventurers extends even to the humblest of all, the mountebank and the
strolling player, or even the pedlar whom he declares that in his foreign
travels he is habitually taken for, as we see in the whimsical apology for
vagabonds which winds up An Inland Voyage. The hungry conjurer, the
gymnast whose maillot is loose, have something of the glamour of the hero,
inasmuch as they too pay with their person. “To be even one of the
outskirters of art leaves a fine stamp on a man’s countenance.... That is the
kind of thing that reconciles me to life: a ragged, tippling, incompetent old
rogue, with the manners of a gentleman and the vanity of an artist, to keep
up his self-respect!” What reconciles Mr. Stevenson to life is the idea that in
the first place it offers the widest field that we know of for odd doings, and
that in the second these odd doings are the best of pegs to hang a sketch in
three lines or a paradox in three pages.
As it is not odd, but extremely usual, to marry, he deprecates that course
in Virginibus Puerisque, the collection of short essays which is most a
record of his opinions—that is, largely, of his likes and dislikes. It all comes
back to his sympathy with the juvenile and that feeling about life which
leads him to regard women as so many superfluous girls in a boy’s game.
They are almost wholly absent from his pages (the main exception is Prince
Otto, though there is a Clara apiece in The Rajah’s Diamond and The
Pavilion on the Links), for they don’t like ships and pistols and fights, they
encumber the decks and require separate apartments, and, almost worst of
all, have not the highest literary standard. Why should a person marry when
he might be swinging a cutlass or looking for a buried treasure? Why
should he waste at the nuptial altar precious hours in which he might be
polishing periods? It is one of those curious and to my sense fascinating
inconsistencies that we encounter in Mr. Stevenson’s mind, that though he
takes such an interest in the childish life he takes no interest in the fireside.
He has an indulgent glance for it in the verses of the Garden, but to his
view the normal child is the child who absents himself from the family-
circle, in fact when he can, in imagination when he cannot, in the disguise
of a buccaneer. Girls don’t do this, and women are only grown-up girls,
unless it be the delightful maiden, fit daughter of an imperial race, whom he
commemorates in An Inland Voyage.
“A girl at school, in France, began to describe one of our regiments on parade to her
French schoolmates; and as she went on, she told me, the recollection grew so vivid, she
became so proud to be the countrywoman of such soldiers, that her voice failed her and she
burst into tears. I have never forgotten that girl; and I think she very nearly deserves a
statue. To call her a young lady, with all its niminy associations, would be to offer her an
insult. She may rest assured of one thing; although she never should marry a heroic
general, never see any great or immediate result of her life, she will not have lived in vain
for her native land.”

There is something of that in Mr. Stevenson; when he begins to describe


a British regiment on parade (or something of that sort), he too almost
breaks down for emotion: which is why I have been careful to traverse the
insinuation that he is primarily a chiseller of prose. If things had gone
differently with him (I must permit myself this allusion to his personal
situation, and I shall venture to follow it with two or three others), he might
have been an historian of famous campaigns—a great painter of battle-
pieces. Of course, however, in this capacity it would not have done for him
to break down for emotion.
Although he remarks that marriage “is a field of battle and not a bed of
roses,” he points out repeatedly that it is a terrible renunciation and
somehow, in strictness, incompatible even with honour—the sort of roving,
trumpeting honour that appeals most to his sympathy. After that step,
“There are no more bye-path meadows where you may innocently linger, but the road
lies long and straight and dusty to the grave.... You may think you had a conscience and
believed in God; but what is a conscience to a wife?... To marry is to domesticate the
Recording Angel. Once you are married, there is nothing left for you, not even suicide, but
to be good.... How then, in such an atmosphere of compromise, to keep honour bright and
abstain from base capitulations?... The proper qualities of each sex are eternally surprising
to the other. Between the Latin and the Teuton races there are similar divergences, not to be
bridged by the most liberal sympathy.... It is better to face the fact and know, when you
marry, that you take into your life a creature of equal if unlike frailties; whose weak,
human heart beats no more tunefully than yours.”

If there be a grimness in that it is as near as Mr. Stevenson ever comes to


being grim, and we have only to turn the page to find the corrective—
something delicately genial, at least, if not very much less sad.
“The blind bow-boy who smiles upon us from the end of terraces in old Dutch gardens
laughingly hurls his bird-bolts among a fleeting generation. But for as fast as ever he
shoots, the game dissolves and disappears into eternity from under his falling arrows; this
one is gone ere he is struck; the other has but time to make one gesture and give one
passionate cry; and they are all the things of a moment.”

That is an admission that though it is soon over, the great sentimental


surrender is inevitable. And there is geniality too, still over the page (in
regard to quite another matter), geniality, at least, for the profession of
letters, in the declaration that there is
“One thing you can never make Philistine natures understand; one thing which yet lies
on the surface, remains as unseizable to their wit as a high flight of metaphysics—namely,
that the business of life is mainly carried on by the difficult art of literature, and according
to a man’s proficiency in that art shall be the freedom and fulness of his intercourse with
other men.”

Yet it is difficult not to believe that the ideal in which our author’s spirit
might most gratefully have rested would have been the character of the
paterfamilias, when the eye falls on such a charming piece of observation as
these lines about children in the admirable paper on Child’s Play:
“If it were not for this perpetual imitation we should be tempted to fancy they despised
us outright, or only considered us in the light of creatures brutally strong and brutally silly,
among whom they condescended to dwell in obedience, like a philosopher at a barbarous
court.”

II
We know very little about a talent till we know where it grew up, and it
would halt terribly at the start, any account of the author of Kidnapped
which should omit to insist promptly that he is a Scot of the Scots. Two
facts, to my perception, go a great way to explain his composition: the first
of which is that his boyhood was passed in the shadow of Edinburgh Castle,
and the second that he came of a family that had set up great lights on the
coast. His grandfather, his uncle, were famous constructors of lighthouses,
and the name of the race is associated above all with the beautiful and
beneficent tower of Skerryvore. We may exaggerate the way in which, in an
imaginative youth, the sense of the “story” of things would feed upon the
impressions of Edinburgh—though I suspect it would be difficult really to
do so. The streets are so full of history and poetry, of picture and song, of
associations springing from strong passions and strange characters, that, for
our own part, we find ourselves thinking of an urchin going and coming
there as we used to think (wonderingly, enviously), of the small boys who
figured as supernumeraries, pages or imps, in showy scenes at the theatre:
the place seems the background, the complicated “set” of a drama, and the
children the mysterious little beings who are made free of the magic world.
How must it not have beckoned on the imagination to pass and repass, on
the way to school, under the Castle rock, conscious, acutely yet familiarly,
of the gray citadel on the summit, lighted up with the tartans and bagpipes
of Highland regiments? Mr. Stevenson’s mind, from an early age, was
furnished with the concrete Highlander, who must have had much of the
effect that we nowadays call decorative. We have encountered somewhere a
fanciful paper[3] of our author’s, in which there is a reflection of half-
holiday afternoons and, unless our own fancy plays us a trick, of lights red,
in the winter dusk, in the high-placed windows of the old town—a
delightful rhapsody on the penny sheets of figures for the puppet-shows of
infancy, in life-like position and awaiting the impatient yet careful scissors.
“If landscapes were sold,” he says in Travels with a Donkey, “like the sheets
of characters of my boyhood, one penny plain and twopence coloured, I
should go the length of twopence every day of my life.”
Indeed the colour of Scotland has entered into him altogether, and
though, oddly enough, he has written but little about his native country, his
happiest work shows, I think, that she has the best of his ability, the best of
his ambition. Kidnapped (whose inadequate title I may deplore in passing)
breathes in every line the feeling of moor and loch, and is the finest of his
longer stories, and Thrawn Janet, a masterpiece in thirteen pages (lately
republished in the volume of The Merry Men), is, among the shorter, the
strongest in execution. The latter consists of a gruesome anecdote of the
supernatural, related in the Scotch dialect, and the genuineness which this
medium (at the sight of which, in general, the face of the reader grows long)
wears in Mr. Stevenson’s hands is a proof of how living the question of
form always is to him, and what a variety of answers he has for it. It would
never have occurred to us that the style of Travels with a Donkey or
Virginibus Puerisque and the idiom of the parish of Balweary could be a
conception of the same mind. If it be a good fortune for a genius to have
had such a country as Scotland for its primary stuff, this is doubly the case
when there has been a certain process of detachment, of extreme
secularisation. Mr. Stevenson has been emancipated: he is, as we may say, a
Scotchman of the world. None other, I think, could have drawn with such a
mixture of sympathetic and ironical observation the character of the canny
young Lowlander, David Balfour, a good boy but an exasperating. Treasure
Island, The New Arabian Nights, Prince Otto, Doctor Jekyll and Mr. Hyde,
are not very directly founded on observation; but that quality comes in with
extreme fineness as soon as the subject involves consideration of race.
I have been wondering whether there is something more than this that
our author’s pages would tell us about him, or whether that particular
something is in the mind of an admirer because he happens to have had
other lights on it. It has been possible for so acute a critic as Mr. William
Archer to read pure high spirits and the gospel of the young man rejoicing
in his strength and his matutinal cold bath between the lines of Mr.
Stevenson’s prose. And it is a fact that the note of a morbid sensibility is so
absent from his pages, they contain so little reference to infirmity and
suffering, that we feel a trick has really been played upon us on discovering
by accident the actual state of the case with the writer who has indulged in
the most enthusiastic allusion to the joy of existence. We must permit
ourselves another mention of his personal situation, for it adds immensely
to the interest of volumes through which there draws so strong a current of
life, to know that they are not only the work of an invalid, but that they
have largely been written in bed, in dreary “health-resorts,” in the intervals
of sharp attacks. There is almost nothing in them to lead us to guess this: the
direct evidence indeed is almost all contained in the limited compass of The
Silverado Squatters. In such a case, however, it is the indirect that is the
most eloquent, and I know not where to look for that, unless in the paper
called “Ordered South,” and its companion “Aes Triplex,” in Virginibus
Puerisque. It is impossible to read “Ordered South” attentively without
feeling that it is personal: the reflections it contains are from experience, not
from fancy. The places and climates to which the invalid is carried to
recover or to die are mainly beautiful, but
“In his heart of hearts he has to confess that [they are] not beautiful for him.... He is
like an enthusiast leading about with him a stolid, indifferent tourist. There is some one by
who is out of sympathy with the scene, and is not moved up to the measure of the occasion;
and that some one is himself.... He seems to himself to touch things with muffled hands
and to see them through a veil.... Many a white town that sits far out on the promontory,
many a comely fold of wood on the mountain side, beckons and allures his imagination
day after day, and is yet as inaccessible to his feet as the clefts and gorges of the clouds.
The sense of distance grows upon him wonderfully; and after some feverish efforts and the
fretful uneasiness of the first few days he falls contentedly in with the restrictions of his
weakness.... He feels, if he is to be thus tenderly weaned from the passion of life, thus
gradually inducted into the slumber of death, that when at last the end comes it will come
quietly and fitly.... He will pray for Medea: when she comes let her either rejuvenate or
slay.”

The second of the short essays I have mentioned has a taste of mortality
only because the purpose of it is to insist that the only sane behaviour is to
leave death and the accidents that lead to it out of our calculations. Life “is
a honeymoon with us all through, and none of the longest. Small blame to
us if we give our whole hearts to this glowing bride of ours.” The person
who does so “makes a very different acquaintance with the world, keeps all
his pulses going true and fast, and gathers impetus as he runs, until if he be
running towards anything better than wildfire, he may shoot up and become
a constellation in the end.” Nothing can be more deplorable than to “forego
all the issues of living in a parlour with a regulated temperature.” Mr.
Stevenson adds that as for those whom the gods love dying young, a man
dies too young at whatever age he parts with life. The testimony of “Aes
Triplex” to the author’s own disabilities is after all very indirect. It consists
mainly in the general protest not so much against the fact of extinction as
against the theory of it. The reader only asks himself why the hero of
Travels with a Donkey, the historian of Alan Breck, should think of these
things. His appreciation of the active side of life has such a note of its own
that we are surprised to find that it proceeds in a considerable measure from
an intimate acquaintance with the passive. It seems too anomalous that the
writer who has most cherished the idea of a certain free exposure should
also be the one who has been reduced most to looking for it within, and that
the figures of adventurers who, at least in our literature of to-day, are the
most vivid, should be the most vicarious. The truth is, of course, that as the
Travels with a Donkey and An Inland Voyage abundantly show, the author
has a fund of reminiscences. He did not spend his younger years “in a
parlour with a regulated temperature.” A reader who happens to be aware of
how much it has been his later fate to do so may be excused for finding an
added source of interest—something indeed deeply and constantly touching
—in this association of peculiarly restrictive conditions with the vision of
high spirits and romantic accidents, of a kind of honourably picaresque
career. Mr. Stevenson is, however, distinctly, in spite of his occasional
practice of the gruesome, a frank optimist—an observer who not only loves
life but does not shrink from the responsibility of recommending it. There is
a systematic brightness in him which testifies to this and which is after all
but one of the innumerable ingenuities of patience. What is remarkable in
his case is that his productions should constitute an exquisite expression, a
sort of whimsical gospel of enjoyment. The only difference between An
Inland Voyage or Travels with a Donkey and The New Arabian Nights or
Treasure Island or Kidnapped, is that in the later books the enjoyment is
reflective (though it simulates spontaneity with singular art), whereas in the
first two it is natural and, as it were, historical.
These little histories—the first volumes, if I mistake not, that introduced
Mr. Stevenson to lovers of good writing—abound in charming illustrations
of his disposition to look at the world as a not exactly refined but glorified,
pacified Bohemia. They narrate the quest of personal adventure, on one
occasion in a canoe on the Sambre and the Oise and on another at a
donkey’s tail over the hills and valleys of the Cévennes. I well remember
that when I read them in their novelty, upwards of ten years ago, I seemed
to see the author, unknown as yet to fame, jump before my eyes into a style.
His steps in literature presumably had not been many; yet he had mastered
his form—it had in these cases perhaps more substance than his matter—
and a singular air of literary experience. It partly, though not completely,
explains the phenomenon, that he had already been able to write the
exquisite little story of Will of the Mill, published previously to An Inland
Voyage, and republished to-day in the volume of The Merry Men, for in Will
of the Mill there is something exceedingly rare, poetical and unexpected,
with that most fascinating quality a work of imagination can have—a dash
of alternative mystery as to its meaning, an air (the air of life itself), of half
inviting, half defying you to interpret. This brief but finished composition
stood in the same relation to the usual “magazine story” that a glass of
Johannisberg occupies to a draught of table d’hôte vin ordinaire.
“One evening he asked the miller where the river went.... ‘It goes out into the lowlands,
and waters the great corn country, and runs through a sight of fine cities (so they say)
where kings live all alone in great palaces, with a sentry walking up and down before the
door. And it goes under bridges, with stone men upon them, looking down and smiling so
curious at the water, and living folks leaning on their elbows on the wall and looking over
too. And then it goes on and on, and down through marshes and sands, until at last it falls
into the sea, where the ships are that bring tobacco and parrots from the Indies.’ ”

It is impossible not to open one’s eyes at such a paragraph as that,


especially if one has taken a common texture for granted. Will of the Mill
spends his life in the valley through which the river runs, and through
which, year after year, post-chaises and waggons and pedestrians, and once
an army, “horse and foot, cannon and tumbrel, drum and standard,” take
their way, in spite of the dreams he once had of seeing the mysterious
world, and it is not till death comes that he goes on his travels. He ends by
keeping an inn, where he converses with many more initiated spirits; and
though he is an amiable man he dies a bachelor, having broken off with
more plainness than he would have used had he been less untravelled (of
course he remains sadly provincial), his engagement to the parson’s
daughter. The story is in the happiest key and suggests all kinds of things:
but what does it in particular represent? The advantage of waiting, perhaps
—the valuable truth that, one by one, we tide over our impatiences. There
are sagacious people who hold that if one does not answer a letter it ends by
answering itself. So the sub-title of Mr. Stevenson’s tale might be “The
Beauty of Procrastination.” If you do not indulge your curiosities your
slackness itself makes at last a kind of rich element, and it comes to very
much the same thing in the end. When it came to the point poor Will had
not even the curiosity to marry; and the author leaves us in stimulating
doubt as to whether he judges him too selfish or only too philosophic.
I find myself speaking of Mr. Stevenson’s last volume (at the moment I
write), before I have spoken, in any detail, of its predecessors: which I must
let pass as a sign that I lack space for a full enumeration. I may mention two
more of his productions as completing the list of those that have a personal
reference. The Silverado Squatters describes a picnicking episode,
undertaken on grounds of health, on a mountain-top in California; but this
free sketch, which contains a hundred humorous touches, and in the figure
of Irvine Lovelands one of Mr. Stevenson’s most veracious portraits, is
perhaps less vivid, as it is certainly less painful, than those other pages in
which, some years ago, he commemorated the twelvemonth he spent in
America—the history of a journey from New York to San Francisco in an
emigrant train, performed as a sequel to a voyage across the Atlantic in the
same severe conditions. He has never made his points better than in this
half-humorous, half-tragical recital, nor given a more striking instance of
his talent for reproducing the feeling of queer situations and contacts. It is
much to be regretted that this little masterpiece had not been brought to
light a second time, as also that he has not given the world (as I believe he
came very near doing), his observations in the steerage of an Atlantic liner.
If, as I say, our author has a taste for the impressions of Bohemia, he has
been very consistent, and has not shrunk from going far afield in search of
them. And as I have already been indiscreet, I may add that if it has been his
fate to be converted in fact from the sardonic view of matrimony, this
occurred under an influence which should have the particular sympathy of
American readers. He went to California for his wife, and Mrs. Stevenson,
as appears moreover by the title-page of his work, has had a hand—
evidently a light and practised one—in The Dynamiter, the second series,
characterised by a rich extravagance, of The New Arabian Nights. The
Silverado Squatters is the history of a honeymoon, prosperous it would
seem, putting Irvine Lovelands aside, save for the death of dog Chuchu “in
his teens, after a life so shadowed and troubled, continually shaken with
alarm and with the tear of elegant sentiment permanently in his eye.”
Mr. Stevenson has a theory of composition in regard to the novel on
which he is to be congratulated, as any positive and genuine conviction of
this kind is vivifying so long as it is not narrow. The breath of the novelist’s
being is his liberty, and the incomparable virtue of the form he uses is that it
lends itself to views innumerable and diverse, to every variety of
illustration. There is certainly no other mould of so large a capacity. The
doctrine of M. Zola himself, so jejune if literally taken, is fruitful, inasmuch
as in practice he romantically departs from it. Mr. Stevenson does not need
to depart, his individual taste being as much to pursue the romantic as his
principle is to defend it. Fortunately, in England to-day, it is not much
attacked. The triumphs that are to be won in the portrayal of the strange, the
improbable, the heroic, especially as these things shine from afar in the
credulous eye of youth, are his strongest, most constant incentive. On one
happy occasion, in relating the history of Doctor Jekyll, he has seen them as
they present themselves to a maturer vision. Doctor Jekyll is not a “boy’s
book,” nor yet is Prince Otto; the latter, however, is not, like the former, an
experiment in mystification—it is, I think, more than anything else, an
experiment in style, conceived one summer’s day when the author had
given the reins to his high appreciation of Mr. George Meredith. It is
perhaps the most literary of his works, but it is not the most natural. It is
one of those coquetries, as we may call them for want of a better word,
which may be observed in Mr. Stevenson’s activity—a kind of artful
inconsequence. It is easy to believe that if his strength permitted him to be a
more abundant writer he would still more frequently play this eminently
literary trick—that of dodging off in a new direction—upon those who
might have fancied they knew all about him. I made the reflection, in
speaking of Will of the Mill, that there is a kind of anticipatory malice in the
subject of that fine story: as if the writer had intended to say to his reader
“You will never guess, from the unction with which I describe the life of a
man who never stirred five miles from home, that I am destined to make my
greatest hits in treating of the rovers of the deep.” Even here, however, the
author’s characteristic irony would have come in; for—the rare chances of
life being what he most keeps his eye on—the uncommon belongs as much
to the way the inquiring Will sticks to his door-sill as to the incident, say, of
John Silver and his men, when they are dragging Jim Hawkins to his doom,
hearing in the still woods of Treasure Island the strange hoot of the maroon.
The novelist who leaves the extraordinary out of his account is liable to
awkward confrontations, as we are compelled to reflect in this age of
newspapers and of universal publicity. The next report of the next divorce
case (to give an instance) shall offer us a picture of astounding
combinations of circumstance and behaviour, and the annals of any
energetic race are rich in curious anecdote and startling example. That
interesting compilation Vicissitudes of Families is but a superficial record of
strange accidents: the family (taken of course in the long piece), is as a
general thing a catalogue of odd specimens and tangled situations, and we
must remember that the most singular products are those which are not
exhibited. Mr. Stevenson leaves so wide a margin for the wonderful—it
impinges with easy assurance upon the text—that he escapes the danger of
being brought up by cases he has not allowed for. When he allows for Mr.
Hyde he allows for everything, and one feels moreover that even if he did
not wave so gallantly the flag of the imaginative and contend that the
improbable is what has most character, he would still insist that we ought to
make believe. He would say we ought to make believe that the
extraordinary is the best part of life even if it were not, and to do so because
the finest feelings—suspense, daring, decision, passion, curiosity, gallantry,
eloquence, friendship—are involved in it, and it is of infinite importance
that the tradition of these precious things should not perish. He would
prefer, in a word, any day in the week, Alexandre Dumas to Honoré de
Balzac, and it is indeed my impression that he prefers the author of The
Three Musketeers to any novelist except Mr. George Meredith. I should go
so far as to suspect that his ideal of the delightful work of fiction would be
the adventures of Monte Cristo related by the author of Richard Feverel.
There is some magnanimity in his esteem for Alexandre Dumas, inasmuch
as in Kidnapped he has put into a fable worthy of that inventor a closeness
of notation with which Dumas never had anything to do. He makes us say,
Let the tradition live, by all means, since it was delightful; but at the same
time he is the cause of our perceiving afresh that a tradition is kept alive
only by something being added to it. In this particular case—in Doctor
Jekyll and Kidnapped—Mr. Stevenson has added psychology.
The New Arabian Nights offer us, as the title indicates, the wonderful in
the frankest, most delectable form. Partly extravagant and partly very
specious, they are the result of a very happy idea, that of placing a series of
adventures which are pure adventures in the setting of contemporary
English life, and relating them in the placidly ingenuous tone of
Scheherezade. This device is carried to perfection in The Dynamiter, where
the manner takes on more of a kind of high-flown serenity in proportion as
the incidents are more “steep.” In this line The Suicide Club is Mr.
Stevenson’s greatest success, and the first two pages of it, not to mention
others, live in the memory. For reasons which I am conscious of not being
able to represent as sufficient, I find something ineffaceably impressive—
something really haunting—in the incident of Prince Florizel and Colonel
Geraldine, who, one evening in March, are “driven by a sharp fall of sleet
into an Oyster Bar in the immediate neighbourhood of Leicester Square,”
and there have occasion to observe the entrance of a young man followed
by a couple of commissionaires, each of whom carries a large dish of cream
tarts under a cover—a young man who “pressed these confections on every
one’s acceptance with exaggerated courtesy.” There is no effort at a picture
here, but the imagination makes one of the lighted interior, the London sleet
outside, the company that we guess, given the locality, and the strange
politeness of the young man, leading on to circumstances stranger still. This
is what may be called putting one in the mood for a story. But Mr.
Stevenson’s most brilliant stroke of that kind is the opening episode of
Treasure Island, the arrival of the brown old seaman with the sabre-cut at
the “Admiral Benbow,” and the advent, not long after, of the blind sailor,
with a green shade over his eyes, who comes tapping down the road, in
quest of him, with his stick. Treasure Island is a “boy’s book” in the sense
that it embodies a boy’s vision of the extraordinary, but it is unique in this,
and calculated to fascinate the weary mind of experience, that what we see
in it is not only the ideal fable but, as part and parcel of that, as it were, the
young reader himself and his state of mind: we seem to read it over his
shoulder, with an arm around his neck. It is all as perfect as a well-played
boy’s game, and nothing can exceed the spirit and skill, the humour and the
open-air feeling with which the thing is kept at the palpitating pitch. It is not
only a record of queer chances, but a study of young feelings: there is a
moral side in it, and the figures are not puppets with vague faces. If Jim
Hawkins illustrates successful daring, he does so with a delightful rosy
good-boyishness and a conscious, modest liability to error. His luck is
tremendous, but it does not make him proud, and his manner is refreshingly
provincial and human. So is that, even more, of the admirable John Silver,
one of the most picturesque and indeed in every way most genially
presented villains in the whole literature of romance. He has a singularly
distinct and expressive countenance, which of course turns out to be a
grimacing mask. Never was a mask more knowingly, vividly painted.
Treasure Island will surely become—it must already have become and will
remain—in its way a classic: thanks to this indescribable mixture of the
prodigious and the human, of surprising coincidences and familiar feelings.
The language in which Mr. Stevenson has chosen to tell his story is an
admirable vehicle for these feelings: with its humorous braveries and
quaintnesses, its echoes of old ballads and yarns, it touches all kinds of
sympathetic chords.
Is Doctor Jekyll and Mr. Hyde a work of high philosophic intention, or
simply the most ingenious and irresponsible of fictions? It has the stamp of
a really imaginative production, that we may take it in different ways; but I
suppose it would generally be called the most serious of the author’s tales.
It deals with the relation of the baser parts of man to his nobler, of the
capacity for evil that exists in the most generous natures; and it expresses
these things in a fable which is a wonderfully happy invention. The subject
is endlessly interesting, and rich in all sorts of provocation, and Mr.
Stevenson is to be congratulated on having touched the core of it. I may do
him injustice, but it is, however, here, not the profundity of the idea which
strikes me so much as the art of the presentation—the extremely successful
form. There is a genuine feeling for the perpetual moral question, a fresh
sense of the difficulty of being good and the brutishness of being bad; but
what there is above all is a singular ability in holding the interest. I confess
that that, to my sense, is the most edifying thing in the short, rapid,
concentrated story, which is really a masterpiece of concision. There is
something almost impertinent in the way, as I have noticed, in which Mr.
Stevenson achieves his best effects without the aid of the ladies, and Doctor
Jekyll is a capital example of his heartless independence. It is usually
supposed that a truly poignant impression cannot be made without them,
but in the drama of Mr. Hyde’s fatal ascendency they remain altogether in
the wing. It is very obvious—I do not say it cynically—that they must have
played an important part in his development. The gruesome tone of the tale
is, no doubt, deepened by their absence: it is like the late afternoon light of
a foggy winter Sunday, when even inanimate objects have a kind of wicked
look. I remember few situations in the pages of mystifying fiction more to
the purpose than the episode of Mr. Utterson’s going to Doctor Jekyll’s to
confer with the butler when the Doctor is locked up in his laboratory, and
the old servant, whose sagacity has hitherto encountered successfully the
problems of the sideboard and the pantry, confesses that this time he is
utterly baffled. The way the two men, at the door of the laboratory, discuss
the identity of the mysterious personage inside, who has revealed himself in
two or three inhuman glimpses to Poole, has those touches of which
irresistible shudders are made. The butler’s theory is that his master has
been murdered, and that the murderer is in the room, personating him with a
sort of clumsy diabolism. “Well, when that masked thing like a monkey
jumped from among the chemicals and whipped into the cabinet, it went
down my spine like ice.” That is the effect upon the reader of most of the
story. I say of most rather than of all, because the ice rather melts in the
sequel, and I have some difficulty in accepting the business of the powders,
which seems to me too explicit and explanatory. The powders constitute the
machinery of the transformation, and it will probably have struck many
readers that this uncanny process would be more conceivable (so far as one
may speak of the conceivable in such a case), if the author had not made it
so definite.
I have left Mr. Stevenson’s best book to the last, as it is also the last he
has given (at the present speaking) to the public—the tales comprising The
Merry Men having already appeared; but I find that on the way I have
anticipated some of the remarks that I had intended to make about it. That
which is most to the point is that there are parts of it so fine as to suggest
that the author’s talent has taken a fresh start, various as have been the
impulses in which it had already indulged, and serious the hindrances
among which it is condemned to exert itself. There would have been a kind
of perverse humility in his keeping up the fiction that a production so
literary as Kidnapped is addressed to immature minds, and, though it was
originally given to the world, I believe, in a “boy’s paper,” the story
embraces every occasion that it meets to satisfy the higher criticism. It has
two weak spots, which need simply to be mentioned. The cruel and miserly
uncle, in the first chapters, is rather in the tone of superseded tradition, and
the tricks he plays upon his ingenuous nephew are a little like those of
country conjurers. In these pages we feel that Mr. Stevenson is thinking too
much of what a “boy’s paper” is expected to contain. Then the history stops
without ending, as it were; but I think I may add that this accident speaks
for itself. Mr. Stevenson has often to lay down his pen for reasons that have
nothing to do with the failure of inspiration, and the last page of David
Balfour’s adventures is an honourable plea for indulgence. The remaining
five-sixths of the book deserve to stand by Henry Esmond as a fictive
autobiography in archaic form. The author’s sense of the English idiom of
the last century, and still more of the Scotch, has enabled him to give a
gallant companion to Thackeray’s tour de force. The life, the humour, the
colour of the central portions of Kidnapped have a singular pictorial virtue:
these passages read like a series of inspired footnotes on some historic page.
The charm of the most romantic episode in the world, though perhaps it
would be hard to say why it is the most romantic, when it was associated
with so much stupidity, is over the whole business, and the forlorn hope of
the Stuarts is revived for us without evoking satiety. There could be no
better instance of the author’s talent for seeing the familiar in the heroic,
and reducing the extravagant to plausible detail, than the description of
Alan Breck’s defence in the cabin of the ship and the really magnificent
chapters of “The Flight in the Heather.” Mr. Stevenson has in a high degree
(and doubtless for good reasons of his own) what may be called the
imagination of physical states, and this has enabled him to arrive at a
wonderfully exact translation of the miseries of his panting Lowland hero,
dragged for days and nights over hill and dale, through bog and thicket,
without meat or drink or rest, at the tail of an Homeric Highlander. The
great superiority of the book resides to my mind, however, in the fact that it
puts two characters on their feet with admirable rectitude. I have paid my
tribute to Alan Breck, and I can only repeat that he is a masterpiece. It is
interesting to observe that though the man is extravagant, the author’s touch
exaggerates nothing: it is throughout of the most truthful, genial, ironical
kind; full of penetration, but with none of the grossness of moralising satire.
The figure is a genuine study, and nothing can be more charming than the
way Mr. Stevenson both sees through it and admires it. Shall I say that he
sees through David Balfour? This would be perhaps to under-estimate the
density of that medium. Beautiful, at any rate, is the expression which this
unfortunate though circumspect youth gives to those qualities which
combine to excite our respect and our objurgation in the Scottish character.
Such a scene as the episode of the quarrel of the two men on the mountain-
side is a real stroke of genius, and has the very logic and rhythm of life; a
quarrel which we feel to be inevitable, though it is about nothing, or almost
nothing, and which springs from exasperated nerves and the simple shock
of temperaments. The author’s vision of it has a profundity which goes
deeper, I think, than Doctor Jekyll. I know of few better examples of the
way genius has ever a surprise in its pocket—keeps an ace, as it were, up its
sleeve. And in this case it endears itself to us by making us reflect that such
a passage as the one I speak of is in fact a signal proof of what the novel
can do at its best, and what nothing else can do so well. In the presence of
this sort of success we perceive its immense value. It is capable of a rare
transparency—it can illustrate human affairs in cases so delicate and
complicated that any other vehicle would be clumsy. To those who love the
art that Mr. Stevenson practises he will appear, in pointing this incidental
moral, not only to have won a particular triumph, but to have given a
delightful pledge.
1887.
VI

MISS WOOLSON

Flooded as we have been in these latter days with copious discussion as to


the admission of women to various offices, colleges, functions, and
privileges, singularly little attention has been paid, by themselves at least, to
the fact that in one highly important department of human affairs their cause
is already gained—gained in such a way as to deprive them largely of their
ground, formerly so substantial, for complaining of the intolerance of man.
In America, in England, to-day, it is no longer a question of their admission
into the world of literature: they are there in force; they have been admitted,
with all the honours, on a perfectly equal footing. In America, at least, one
feels tempted at moments to exclaim that they are in themselves the world
of literature. In Germany and in France, in this line of production, their
presence is less to be perceived. To speak only of the latter country, France
has brought forth in the persons of Madame de Sévigné, Madame de Staël,
and Madame Sand, three female writers of the first rank, without counting a
hundred ladies to whom we owe charming memoirs and volumes of
reminiscence; but in the table of contents of the Revue des Deux Mondes,
that epitome of the literary movement (as regards everything, at least, but
the famous doctrine, in fiction, of “naturalism”), it is rare to encounter the
name of a female contributor. The covers of American and English
periodicals tell a different story; in these monthly joints of the ladder of
fame the ladies stand as thick as on the staircase at a crowded evening party.
There are, of course, two points of view from which this free possession
of the public ear may be considered—as regards its effect upon the life of
women, and as regards its effect upon literature. I hasten to add that I do not
propose to consider either, and I touch on the general fact simply because
the writer whose name I have placed at the head of these remarks happens
to be a striking illustration of it. The work of Miss Constance Fenimore
Woolson is an excellent example of the way the door stands open between
the personal life of American women and the immeasurable world of print,
and what makes it so is the particular quality that this work happens to
possess. It breathes a spirit singularly and essentially conservative—the sort
of spirit which, but for a special indication pointing the other way, would in
advance seem most to oppose itself to the introduction into the feminine lot
of new and complicating elements. Miss Woolson evidently thinks that lot
sufficiently complicated, with the sensibilities which even in primitive ages
women were acknowledged to possess; fenced in by the old disabilities and
prejudices, they seem to her to have been by their very nature only too
much exposed, and it would never occur to her to lend her voice to the plea
for further exposure—for a revolution which should place her sex in the
thick of the struggle for power. She sees it in preference surrounded
certainly by plenty of doors and windows (she has not, I take it, a love of
bolts and Oriental shutters), but distinctly on the private side of that
somewhat evasive and exceedingly shifting line which divides human
affairs into the profane and the sacred. Such is the turn of mind of the
author of Rodman the Keeper and East Angels, and if it has not prevented
her from writing books, from competing for the literary laurel, this is a
proof of the strength of the current which to-day carries both sexes alike to
that mode of expression.
Miss Woolson’s first productions were two collections of short tales,
published in 1875 and 1880, and entitled respectively Castle Nowhere and
Rodman the Keeper. I may not profess an acquaintance with the former of
these volumes, but the latter is full of interesting artistic work. Miss
Woolson has done nothing better than the best pages in this succession of
careful, strenuous studies of certain aspects of life, after the war, in Florida,
Georgia and the Carolinas. As the fruit of a remarkable minuteness of
observation and tenderness of feeling on the part of one who evidently did
not glance and pass, but lingered and analysed, they have a high value,
especially when regarded in the light of the voicelessness of the conquered
and reconstructed South. Miss Woolson strikes the reader as having a
compassionate sense of this pathetic dumbness—having perceived that no
social revolution of equal magnitude had ever reflected itself so little in
literature, remained so unrecorded, so unpainted and unsung. She has
attempted to give an impression of this circumstance, among others, and a
sympathy altogether feminine has guided her pen. She loves the whole
region, and no daughter of the land could have handled its peculiarities
more indulgently, or communicated to us more of the sense of close
observation and intimate knowledge. Nevertheless it must be confessed that
the picture, on the whole, is a picture of dreariness—of impressions that
may have been gathered in the course of lonely afternoon walks at the end
of hot days, when the sunset was wan, on the edge of rice-fields, dismal
swamps, and other brackish inlets. The author is to be congratulated in so
far as such expeditions may have been the source of her singularly exact
familiarity with the “natural objects” of the region, including the negro of
reality. She knows every plant and flower, every vague odour and sound,
the song and flight of every bird, every tint of the sky and murmur of the
forest, and she has noted scientifically the dialect of the freedmen. It is not
too much to say that the negroes in Rodman the Keeper and in East Angels
are a careful philological study, and that if Miss Woolson preceded Uncle
Remus by a considerable interval, she may have the credit of the initiative
—of having been the first to take their words straight from their lips.
No doubt that if in East Angels, as well as in the volume of tales, the
sadness of Miss Woolson’s South is more striking than its high spirits, this
is owing somewhat to the author’s taste in the way of subject and situation,
and especially to her predilection for cases of heroic sacrifice—sacrifice
sometimes unsuspected and always unappreciated. She is fond of
irretrievable personal failures, of people who have had to give up even the
memory of happiness, who love and suffer in silence, and minister in secret
to the happiness of those who look over their heads. She is interested in
general in secret histories, in the “inner life” of the weak, the superfluous,
the disappointed, the bereaved, the unmarried. She believes in personal
renunciation, in its frequency as well as its beauty. It plays a prominent part
in each of her novels, especially in the last two, and the interest of East
Angels at least is largely owing to her success in having made an extreme
case of the virtue in question credible to the reader. Is it because this
element is weaker in Anne, which was published in 1882, that Anne strikes
me as the least happily composed of the author’s works? The early chapters
are charming and full of promise, but the story wanders away from them,
and the pledge is not taken up. The reader has built great hopes upon Tita,
but Tita vanishes into the vague, after putting him out of countenance by an
infant marriage—an accident in regard to which, on the whole, throughout
her stories, Miss Woolson shows perhaps an excessive indulgence. She likes
the unmarried, as I have mentioned, but she likes marriages even better, and
also sometimes hurries them forward in advance of the reader’s exaction.
The only complaint it would occur to me to make of East Angels is that
Garda Thorne, whom we cannot think of as anything but a little girl,
discounts the projects we have formed for her by marrying twice; and
somehow the case is not bettered by the fact that nothing is more natural
than that she should marry twice, unless it be that she should marry three
times. We have perceived her, after all, from the first, to be peculiarly
adapted to a succession of pretty widowhoods.
For the Major has an idea, a little fantastic perhaps, but eminently
definite. This idea is the secret effort of an elderly woman to appear really
as young to her husband as (owing to peculiar circumstances) he believed
her to be when he married her. Nature helps her (she happens to preserve,
late in life, the look of comparative youth), and art helps nature, and her
husband’s illusions, fostered by failing health and a weakened brain, help
them both, so that she is able to keep on the mask till his death, when she
pulls it off with a passionate cry of relief—ventures at last, gives herself the
luxury, to be old. The sacrifice in this case has been the sacrifice of the
maternal instinct, she having had a son, now a man grown, by a former
marriage, who reappears after unsuccessful wanderings in far lands, and
whom she may not permit herself openly to recognise. The sacrificial
attitude is indeed repeated on the part of her step-daughter, who, being at
last taken into Madam Carroll’s confidence, suffers the young man—a
shabby, compromising, inglorious acquaintance—to pass for her lover,
thereby discrediting herself almost fatally (till the situation is straightened
out), with the Rev. Frederick Owen, who has really been marked out by
Providence for the character, and who cannot explain on any comfortable
hypothesis her relations with the mysterious Bohemian. Miss Woolson’s
women in general are capable of these refinements of devotion and
exaltations of conscience, and she has a singular talent for making our
sympathies go with them. The conception of Madam Carroll is highly
ingenious and original, and the small stippled portrait has a real fascination.
It is the first time that a woman has been represented as painting her face,
dyeing her hair, and “dressing young,” out of tenderness for another: the
effort usually has its source in tenderness for herself. But Miss Woolson has
done nothing of a neater execution than this fanciful figure of the little
ringleted, white-frocked, falsely juvenile lady, who has the toilet-table of an
actress and the conscience of a Puritan.
The author likes a glamour, and by minute touches and gentle,
conciliatory arts, she usually succeeds in producing a valid one. If I had
more space I should like to count over these cumulative strokes, in which a
delicate manipulation of the real is mingled with an occasionally frank
appeal to the romantic muse. But I can only mention two of the most
obvious: one the frequency of her reference to the episcopal church as an
institution giving a tone to American life (the sort of tone which it is usually
assumed that we must seek in civilisations more permeated with
ecclesiasticism); the other her fondness for family histories—for the idea of
perpetuation of race, especially in the backward direction. I hasten to add
that there is nothing of the crudity of sectarianism in the former of these
manifestations, or of the dreariness of the purely genealogical passion in the
latter; but none the less is it clear that Miss Woolson likes little country
churches that are dedicated to saints not vulgarised by too much notoriety,
that are dressed with greenery (and would be with holly if there were any),
at Christmas and Easter; that have “rectors,” well connected, who are
properly garmented, and organists, slightly deformed if possible, and
addicted to playing Gregorian chants in the twilight, who are adequately
artistic; likes also generations that have a pleasant consciousness of a few
warm generations behind them, screening them in from too bleak a past,
from vulgar draughts in the rear. I know not whether for the most part we
are either so Anglican or so long-descended as in Miss Woolson’s pages we
strike ourselves as being, but it is certain that as we read we protest but little
against the soft impeachment. She represents us at least as we should like to
be, and she does so with such discretion and taste that we have no fear of
incurring ridicule by assent. She has a high sense of the picturesque; she
cannot get on without a social atmosphere. Once, I think, she has looked for
these things in the wrong place—at the country boarding-house
denominated Caryl’s, in Anne, where there must have been flies and grease
in the dining-room, and the ladies must have been overdressed; but as a
general thing her quest is remarkably happy. She stays at home, and yet
gives us a sense of being “abroad”; she has a remarkable faculty of making
the new world seem ancient. She succeeds in representing Far Edgerly, the
mountain village in For the Major, as bathed in the precious medium I
speak of. Where is it meant to be, and where was the place that gave her the
pattern of it? We gather vaguely, though there are no negroes, that it is in
the south; but this, after all, is a tolerably indefinite part of the United
States. It is somewhere in the midst of forests, and yet it has as many
idiosyncrasies as Mrs. Gaskell’s Cranford, with added possibilities of the
pathetic and the tragic. What new town is so composite? What composite
town is so new? Miss Woolson anticipates these questions; that is she
prevents us from asking them: we swallow Far Edgerly whole, or say at
most, with a sigh, that if it couldn’t have been like that it certainly ought to
have been.
It is, however, in East Angels that she has been most successful in this
feat of evoking a local tone, and this is a part of the general superiority of
that very interesting work, which to my mind represents a long stride of her
talent, and has more than the value of all else she has done. In East Angels
the attempt to create an atmosphere has had, to a considerable degree, the
benefit of the actual quality of things in the warm, rank peninsula which she
has studied so exhaustively and loves so well. Miss Woolson found a tone
in the air of Florida, but it is not too much to say that she has left it still
more agreeably rich—converted it into a fine golden haze. Wonderful is the
tact with which she has pressed it into the service of her story, draped the
bare spots of the scene with it, and hung it there half as a curtain and half as
a background. East Angels is a performance which does Miss Woolson the
highest honour, and if her talent is capable, in another novel, of making an
advance equal to that represented by this work in relation to its
predecessors, she will have made a substantial contribution to our new
literature of fiction. Long, comprehensive, copious, still more elaborate than
her other elaborations, East Angels presents the interest of a large and well-
founded scheme. The result is not flawless at every point, but the
undertaking is of a fine, high kind, and, for the most part, the effect
produced is thoroughly worthy of it. The author has, in other words,
proposed to give us the complete natural history, as it were, of a group of
persons collected, in a complicated relationship, in a little winter-city on a
southern shore, and she has expended on her subject stores of just
observation and an infinite deal of the true historical spirit. How much of
this spirit and of artistic feeling there is in the book, only an attentive
perusal will reveal. The central situation is a very interesting one, and is
triumphantly treated, but I confess that what is most substantial to me in the
book is the writer’s general conception of her task, her general attitude of
watching life, waiting upon it and trying to catch it in the fact. I know not
what theories she may hold in relation to all this business, to what camp or

You might also like