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

Practical Vaadin: Developing Web Applications in Java 1st Edition Alejandro Duarte download

The document is a promotional and informational overview of the book 'Practical Vaadin: Developing Web Applications in Java' by Alejandro Duarte, which focuses on Java web application development using the Vaadin framework. It outlines the book's structure, intended audience, and key topics covered, including web development fundamentals, advanced features, and integrations with Spring and Jakarta EE. Additionally, it provides links to other related books and resources available on the ebookmeta website.

Uploaded by

carewmades40
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)
18 views

Practical Vaadin: Developing Web Applications in Java 1st Edition Alejandro Duarte download

The document is a promotional and informational overview of the book 'Practical Vaadin: Developing Web Applications in Java' by Alejandro Duarte, which focuses on Java web application development using the Vaadin framework. It outlines the book's structure, intended audience, and key topics covered, including web development fundamentals, advanced features, and integrations with Spring and Jakarta EE. Additionally, it provides links to other related books and resources available on the ebookmeta website.

Uploaded by

carewmades40
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/ 85

Practical Vaadin: Developing Web Applications in

Java 1st Edition Alejandro Duarte install


download

https://ebookmeta.com/product/practical-vaadin-developing-web-
applications-in-java-1st-edition-alejandro-duarte/

Download more ebook from https://ebookmeta.com


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

Quantum entanglement engineering and applications F. J.


Duarte

https://ebookmeta.com/product/quantum-entanglement-engineering-
and-applications-f-j-duarte/

Practical Laravel Develop clean MVC web applications


1st Edition Daniel Correa Paola Vallejo

https://ebookmeta.com/product/practical-laravel-develop-clean-
mvc-web-applications-1st-edition-daniel-correa-paola-vallejo/

Primary Mathematics 3A Hoerst

https://ebookmeta.com/product/primary-mathematics-3a-hoerst/

The Pucking Wrong Number A Hockey Romance 1st Edition


C.R. Jane

https://ebookmeta.com/product/the-pucking-wrong-number-a-hockey-
romance-1st-edition-c-r-jane/
Tracing the Politicisation of the EU: The Future of
Europe Debates Before and After the 2019 Elections 1st
Edition Palgrave

https://ebookmeta.com/product/tracing-the-politicisation-of-the-
eu-the-future-of-europe-debates-before-and-after-
the-2019-elections-1st-edition-palgrave/

Data Visualization with Python and JavaScript 2nd


Edition Eighth Early Release Kyran Dale

https://ebookmeta.com/product/data-visualization-with-python-and-
javascript-2nd-edition-eighth-early-release-kyran-dale/

Anthropocene Antarctica Perspectives from the


Humanities Law and Social Sciences Routledge
Environmental Humanities 1st Edition Elizabeth Leane

https://ebookmeta.com/product/anthropocene-antarctica-
perspectives-from-the-humanities-law-and-social-sciences-
routledge-environmental-humanities-1st-edition-elizabeth-leane-2/

In the Shadow of My Country 1st Edition Tennu Mbuh

https://ebookmeta.com/product/in-the-shadow-of-my-country-1st-
edition-tennu-mbuh/

Becoming a Visible Man 2nd Edition Jamison Green

https://ebookmeta.com/product/becoming-a-visible-man-2nd-edition-
jamison-green/
Once Taken Blake Pierce

https://ebookmeta.com/product/once-taken-blake-pierce/
Alejandro Duarte

Practical Vaadin
Developing Web Applications in Java
1st ed.
Alejandro Duarte
Turku, Finland

ISBN 978-1-4842-7178-0 e-ISBN 978-1-4842-7179-7


https://doi.org/10.1007/978-1-4842-7179-7

© Alejandro Duarte 2021

This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks,


service marks, etc. in this publication does not imply, even in the
absence of a specific statement, that such names are exempt from the
relevant protective laws and regulations and therefore free for general
use.

The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

This Apress imprint is published by the registered company APress


Media, LLC part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY
10004, U.S.A.
To my father. There’s no better teacher than a good father.
Introduction
This book teaches you how to be productive with Java web application
development. Java is the number one programming language and
runtime environment for high-quality, enterprise-ready software in the
industry, and it will remain as such in the years to come. From credit
cards (through Java Card) to remote-controlled rovers searching for
water and life on Mars, Java has proven to be fast, secure, reliable, and
modern.
The rich Java ecosystem provides developers with an army of
libraries, frameworks, tools, patterns, and practices to triumph in the
software development field. One of the soldiers in the Java ecosystem is
Vaadin—an open source web framework that reduces costs by
shortening the development time of business web applications. Vaadin
is a Finnish word that means “reindeer,” and this reindeer’s motto is
“Fight for Simplicity.” Vaadin simplifies web software development by
offering the best developer experience in the market to Java developers
who prefer to code in Java.

Audience
This book is for software developers with a basic or higher knowledge
of the Java programming language who want to build on their Java skills
to create web graphical user interfaces. It’s tailored to those who want
to create web applications without having to code in JavaScript and
HTML and, instead, leverage the power of Java and its ecosystem in the
presentation layer. It’s also a good resource for developers preparing to
take and pass the Vaadin certification exams or who want to strengthen
their expertise with the framework.

Structure of the Book


A picture is worth a thousand words. And mostly so in a book that
explains how to create graphical user interfaces. The book contains
more than 140 screenshots and figures that make the topics easier to
grasp. The book includes example projects that can be run
independently and, in most cases, are formed by independent screens
to reduce the need to remember code from previous chapters or even
sections.
The book contains 13 chapters grouped into four main parts:
1. Chapters 1 and 2 get you started with web development and
Vaadin. You’ll learn about the Web platform technologies, web
servers, and Java web development.

2. Chapters 3–6 cover the fundamentals of Vaadin—the building


blocks that you’ll use to create web user interfaces with the
framework.

3. Chapters 7–11 cover advanced topics such as Server Push , custom


styles, responsive design, and client-side views with TypeScript.

4. Chapters 12 and 13 cover the basics of the Vaadin integrations with


Spring and Jakarta EE and SQL database connectivity using these
frameworks.

This book doesn’t pretend to be a complete reference document


about Vaadin. I made a good effort to explain the concepts using an
informal, relaxed writing style in contrast to the more reference-like
style often required in official product documentation. I’m convinced
that the Vaadin documentation and this book are the perfect mix to
master Vaadin.
For topics not covered in this book or in the official documentation,
I invite you to join the active Vaadin Community on the channels
available at www.vaadin.com .
Acknowledgments
Writing a book is quite an adventure. Although you have a map, the
fine-grained details of the terrain are uncharted. I took on this
adventure fully aware of the fantastic people who, in one way or
another, would walk the journey with me.
I had an outstanding cartographer—the team at Apress. Jonathan
Gennick helped me to make the most out of the journey. Jill Balzano
made sure that my gear worked through the ride. Andres Sacco pointed
out the immediate dangers and suggested safer pathways.
Writing this book would have been impossible without the almost
unconditional support from Vaadin Ltd. This extraordinary company
allowed me to use a substantial part of my work time to write the draft.
Marcus Hellberg made sure to clear up many of the obstacles I would
have never detected by gazing at the map. My teammates, especially
Mikael Sukoinen and Luis Gutierrez, watched my back and told
inspiring stories every Monday at 5 p.m.
When you take on an adventure like this, the stories that many
other adventurers have told you come to mind and inspire you. In every
paragraph that forms the chapters of this book, there is a software
developer with whom I interacted before. Sami Ekblad, Matti Tahvonen,
Leif Å strand, Petter Hö lmströ m, Jani Laakso, Geovanny Mendoza,
Ricardo Cantillo, Camilo Gonzales, Yury Niñ o, Julien Monnier, Karan
Biawat, Alexandros Milaios, Orlando Vá squez, Andrea Bosio, Jet Beray,
and many others left a mark in this voyage.
Like in every endeavor that imposes challenges, I was accompanied
by those who provide comfort and love when you need to take a break
to prepare for the next leg of the journey. My parents and siblings, Mari
Vento, Jussi Kalliokorpi, Eva Adolfsson, Noomi Ö rså , Dora Quintero, José
Pabó n, Yenny Bermú dez, Camilo Macias, and Erkki Suikki. To all of you,
thank you!
Table of Contents
Part I: Getting Started
Chapter 1:​The World of Vaadin
A CRUD in One Line of Code
The Web platform
HTML
JavaScript and DOM
CSS
Web Components
Server-Side Technologies
Web Servers
CGI
Servlets
Web Development with Vaadin
Summary
Chapter 2:​Setting Up the Development Environment
Installing the JDK
Installing the IDE
Using the Examples of This Book
Importing the Code in the IDE
Running the Examples
Your First Vaadin Application
Routes and Views
UI Components and Layouts
Events and Listeners
Debugging
Server-Side Debugging
Client-Side Debugging
Summary
Part II: The Fundamentals of Vaadin
Chapter 3:​Layouts
Vertical and Horizontal Layouts
Component Composition
The Composite Class
Implementing Reusable UI Components
Accessing the Component Tree
Padding, Margin, and Spacing
Sizing
Grow
Alignment
Justify-Content Mode
Scrolling
FlexLayout
Direction
Wrap
Alignment
Shrink
Other Layouts
Summary
Chapter 4:​UI Components
Input Components
Text Input
Password Input
Boolean Input
Date and Time Input
Numeric Input
Single Selection Input
Multiple Selection Input
File Upload
Interaction Components
Buttons
How Are Events Sent to the Server?​
Links
Menus
Visualization Components
Notifications and Dialogs
Tabs
Icons
Images
Summary
Chapter 5:​Data Binding
Implementing Data Binding Manually
Implementing the Domain Model
Implementing the View
Implementing the Form
The Binder Helper Class
Defining Bindings Programmatically​
Defining Bindings Using Property Names
Using Automatic Binding
Defining Bindings for Nested Properties
Data Conversion and Validation
Using Converters
Implementing Validation Rules
Using Jakarta Bean Validation
Summary
Chapter 6:​The Grid Component
Adding Columns
Managing Columns by Key
Defining Columns with ValueProvider
Adding Rows
In-Memory Data
Lazy Loading
Sorting
Handling Row Selection
Adding UI Components to Cells
Component Columns
Item Details
Exporting to CSV
Summary
Part III: Advanced Features
Chapter 7:​Multiview Navigation and Routing
Routes
Defining Routes at Runtime
Router Layouts
Navigation Lifecycle
Before Enter Observer
Before Leave Observer
URL Parameters
URL Templates
Typed Parameters
Query Parameters
Updating the Page Title
Summary
Chapter 8:​Server Push
When Is Server Push Used?​
How Server Push Works
Performing Asynchronous UI Updates
Automatic Server Push Updates
Manual Server Push Updates
Using Thread Pools
WebSocket vs.​Long Polling
Summary
Chapter 9:​The Element API
Creating DOM Elements
Creating Custom Components
Styling
Mixin Interfaces
Handling Events
JavaScript Integration
Adding JavaScript to a Vaadin Application
Invoking JavaScript from Java
Invoking Java from JavaScript
Summary
Chapter 10:​Custom Styles and Responsiveness
Built-In Themes
Using Theme Variants
Using Component Variants
Styling with CSS
Importing CSS Files
Using Lumo Theme Properties
Adding CSS Classes to UI Components
Styling Shadow DOM
Responsive Web Design
FormLayout
AppLayout
CSS Media Queries
Summary
Chapter 11:​Client-Side Views with TypeScript
Vaadin Flow vs.​Vaadin Fusion
Quick Introduction to TypeScript
Installing the TypeScript Compiler
Implementing “Hello, World” in TypeScript
Static Typing
Web Components with Lit
Creating a New Lit Project
Creating a “Hello, World” Web Component
Client-Side Views with Vaadin Fusion
Enabling Client-Side Bootstrapping
Adding a Client-Side View
Adding Vaadin Components
Event Listeners
Reactive Views
A Word on Offline Capabilities
Summary
Part IV: Integrations and Database Connectivity
Chapter 12:​Spring Boot
Creating a New Spring Boot Project
Creating a New Database
Configuring the Database Connection
Implementing an Entity
Adding a Repository
Inversion of Control and Dependency Injection
Implementing a CRUD
Summary
Chapter 13:​Jakarta EE
Creating a New Jakarta EE Project
Creating a New Database
Configuring the Database Connection
Implementing an Entity
Adding a Repository
Contexts and Dependency Injection
Implementing a CRUD
Summary
Index
About the Author
Alejandro Duarte
is a software engineer currently working
for Vaadin Ltd as their Developer
Relations Manager. This is his third book
on Vaadin. Alejandro started to code at
age 13 using the BASIC programming
language on a black screen with a
blinking cursor serving as the IDE. He
quickly moved to C and C++—languages
he still loves and enjoys—and then to
Java during his computer science studies
at the National University of Colombia
from where he graduated. Alejandro
moved to the UK and later to Finland to
foster his career in the open source
software industry. He became one of the
well-known faces in the Vaadin and Java communities, having published
articles and videos with hundreds of thousands of views in official
Vaadin channels and other content portals, and presented technical
topics at international Java conferences and Java User Groups.
Alejandro splits his free time between his passion for the electric guitar
and the photography world. You can contact him through his personal
blog at www.programmingbrain.com .
About the Technical Reviewer
Andres Sacco
has been working as a developer since
2007 in different languages including
Java, PHP, Node.js, and Android. Most of
his background is in Java and the
libraries or frameworks associated with
this language, for example, Spring,
Hibernate, JSF, and Quarkus. In most of
the companies that he worked for, he
researched new technologies in order to
improve the performance, stability, and
quality of the applications of each
company.
Part I
Getting Started
© The Author(s), under exclusive license to APress Media, LLC, part of Springer
Nature 2021
A. Duarte, Practical Vaadin
https://doi.org/10.1007/978-1-4842-7179-7_1

1. The World of Vaadin


Alejandro Duarte1
(1) Turku, Finland

This chapter serves as a general introduction to web development and


the technologies around Vaadin. This is one of the few chapters in
which you will see HTML and JavaScript code (and even the Python
interpreter), I promise.

A CRUD in One Line of Code


When I started my career in web development, I joined a group of
developers in the enrollment department of one of the largest
universities in South America. The department operation was
supported by a web application written in Java with Struts 2 (a Java
web framework), Hibernate (a database persistence framework),
Spring Framework (the enterprise configuration framework or, as we
used to describe it, the glue of the application), and many other
libraries.
Many of the web pages in the application shared a common UI (user
interface) pattern: they all had a form to search data, a table to present
the data, and options to operate on the data. In other words, the
application had tons of Create, Read, Update, and Delete (CRUD ) views.
The code of the application included helpers for implementing these
kinds of views. However, this involved duplicating code—something I
wasn’t very happy about.
I started to research Java web frameworks in hopes of finding ideas
that helped me solve this problem when I discovered Google Web
Toolkit (GWT) . GWT included a Java to JavaScript compiler which
allowed developers to implement web user interfaces in Java rather
than in JavaScript. I enjoyed the innovative approach, and as I learned
more about it, I discovered that there was an even more mature web
framework that used the same philosophy, except it didn’t compile Java
code to JavaScript. Its name, Vaadin.
After some days playing with Vaadin, I relatively quickly
implemented a reusable library to dynamically create CRUD views with
one line of Java. Here’s an example:

GridCrud<User> crud = new GridCrud<>(User.class);

Figure 1-1 shows the type of CRUD views that can be created with
this library.

Figure 1-1 A CRUD view implemented with Vaadin

The fact that Vaadin allowed me to code the web user interface
using Java running on the server side was the main reason I decided to
adopt it in many of my future projects. Being able to use the same
programming language in all the layers of the application removed the
associated efforts in context shifting. Similarly, the learning curve that
developers had to go through when they joined a project was almost
flat—if they knew Jvava, they were productive with Vaadin almost
instantly.
The same will happen to you as you go through this book—you’ll
quickly be able to implement web UIs for your Java projects as you
learn Vaadin. By the end of the book, you’ll have the skills to implement
and maintain Vaadin applications and, why not, create and publish your
own reusable libraries like I did with the CRUD library.

Note If you are curious, the CRUD library is open source and
available for free at
https://vaadin.com/directory/component/crud-ui-
add-on.

The Web platform


Sometimes, developing with Vaadin feels like magic. You type a Java
snippet of code that’s supposed to show a button on the browser, and
the button indeed magically appears there. I want to show you that
there’s no such thing as magic in software development. If you
understand the underlying mechanisms, you’ll see there are no tricks,
and you’ll be in a better position to master any technology.
Beside the Java programming language, the fundamental
technologies are those in the Web platform . The Web platform is a set
of programming languages and API standards developed mainly by the
World Wide Web Consortium and implemented by web browsers. This
includes HTTP, HTML, ECMAScript (the standard governing JavaScript),
DOM Events, XMLHttpRequest, CSS, Web Components, Web Workers,
WebSocket, WebAssembly, Geolocation API, Web Storage, and several
others.
It can be daunting to master all these technologies, but the reality is
that you will mostly use three of them directly in everyday web
development: HTML, JavaScript, and CSS. Vaadin abstracts away HTML
and JavaScript (alongside related APIs), so you end up using only Java
and CSS most of the time. However, it’s always good to understand the
underlying technologies at least to some degree.

HTML
HTML (Hypertext Markup Language ) is what browsers use as the
source when they render a web page. Hypertext means text with
hyperlinks. You have probably clicked many hyperlinks before when
you navigated from one page to another. When you see a web page, you
are seeing the rendered version of an HTML document. An HTML
document is a file (in memory or in a hard drive) that consists of tags
and text and, since HTML5, starts with a Document Type Declaration:

<!DOCTYPE html>

Most tags are used in pairs. For example:

<h1>It works!</h1>

In this example, <h1> is the opening tag, and </h1> the closing tag.
The text between the tags is the content of the tag and can also contain
other HTML tags. In the previous example, the text The Web platform is
rendered by browsers using a heading style. There are several levels of
headings, for example, <h2>, <h3>, etc.
HTML tags not only format code but render UI controls like buttons
and text fields. The following snippet of code renders a button:

<button>Time in the client</button>

The main parts of an HTML document are structured in three tags:


<html>: The root or top-level element of the document
<head>: Metadata about the document to add resources (images,
JavaScript, CSS) or configure things such as the title of the page
(using the <title> tag)
<body>: The renderable content of the document
Opening tags may include attributes. For instance, you can specify
the language of the page by using the lang attribute of the <html>
tag:

<html lang="en"></html>
If we put together the previous snippets of code inside the <body>
element, we can form a complete and valid HTML document that all
browsers can render. Listing 1-1 shows a complete and valid HTML
document.

<!DOCTYPE html>
<html lang="en">
<head>
<title>The Web platform</title>
<link rel="stylesheet" href="browser-time.css">
</head>
<body>

<h1>It works!</h1>
<button>Time in the client</button>

</body>
</html>
Listing 1-1 A complete HTML document

Note HTML doesn’t care about indentations. Developers do, and


some choose to indent the content of the <html> and <body> tags,
while others prefer not to do it. I prefer to not indent these since
they present in almost all documents, and they just shift everything
to the right. However, I do indent the content of the HTML tags inside
the <body> tag for readability. In the previous example, none of
these tags have other tags as content, so there’s nothing to indent
inside the <body> tag. Moreover, most IDEs indent with the style I
used in the example.

If you use a plain text editor (next chapters cover setting up a


development environment) to create a browser-time.html file and open
this file in a web browser, you’ll see something similar to the screenshot
in Figure 1-2.

Figure 1-2 A simple HTML document rendered in a web browser


I encourage you to try this on your computer and experiment with
the code. Try adding tags such as <input> and formatting text with
<b>, <i>, and <code>.

Note You can find a comprehensive list of all the tags in HTML on
the Mozilla Developer Network (MDN) website at
https://developer.mozilla.org/en-
US/docs/Web/HTML/Element. In fact, the MDN is an excellent
source for learning everything about the technologies of the Web
platform.

JavaScript and DOM


JavaScript is a multipurpose, prototype-based (allows the creation of
objects without defining classes prior), single-threaded, scripting
programming language with first-class functions. Besides its name and
the Date object (which is a direct port of Java’s java.util.Date
class), JavaScript has nothing to do with the Java language itself.
However, JavaScript is frequently used in conjunction with Java to
develop web applications—Java on the server, JavaScript on the client.
JavaScript is the programming language of the web browsers.
The DOM (Document Object Model ) is a language-independent API
that represents an HTML (or more generally, XML) document as a tree.
Web browsers implement the DOM as a JavaScript API. Figure 1-3
depicts the DOM hierarchy of the HTML document developed in the
previous section.

Figure 1-3 Example of Document Object Model for an HTML document


With the JavaScript DOM API, developers can add, change, and
remove HTML elements and its attributes, enabling the creation of
dynamic web pages. To add JavaScript logic to an HTML document, you
can use the <script> tag:

<!DOCTYPE html>
<html>
...
<body>
...
<script>
... JavaScript code goes here ...
</script>
</body>
</html>
I like to have the JavaScript code in separate files. An alternative way
to add JavaScript is by leaving the content of the <script> tag empty
and using the src attribute to specify the location of the file:

<script src="time-button.js"></script>

Returning to the HTML document of the previous section, the


JavaScript logic to make the button work can be placed in the time-
button.js file (next to the browser-time.html file) with the following
content:

let buttons =
document.getElementsByTagName("button");

buttons[0].addEventListener("click", function() {
let paragraph = document.createElement("p");
paragraph.textContent = "The time is: " +
Date();
document.body.appendChild(paragraph);
});

I tried to write the previous JavaScript code as clear as possible for


Java developers. This script gets all the <button> elements in the
document as an array and adds a click listener to the first one
(incidentally, there’s only one button). The click listener is implemented
as a function that gets called when the user clicks the button. This
listener creates a new <p> element using the DOM API and sets its text
content to show the current time. It then appends the newly created
element to the end of the <body> element. The result is shown in
Figure 1-4.
Figure 1-4 A simple JavaScript application running in a web browser

CSS
CSS (Cascading Style Sheets ) is a language that allows to configure
fonts, colors, spacing, alignment, and other styling features that dictate
how an HTML document should be rendered. One easy way to add CSS
code to an HTML document is to use a <style> tag in the <head>
element:

<!DOCTYPE html>
<html>
<head>
...
<style>
... CSS code goes here ...
</style>
</head>
...
</html>

As with JavaScript files, I like to have separate files to define CSS


styles. This is done by using a <link> tag in the <head> section:

<head>
<link rel="stylesheet" href="browser-time.css">
<head>

Tip <link> is one of the tags that doesn’t have an end tag
(</link>). In HTML5, the end tag is not allowed; however,
browsers just ignore </link> or the cargo cult practice of adding a
/ before > when rendering a page.

CSS rules apply styles to the HTML document. Each CSS rule is written
as a selector that targets HTML elements and declarations with the
styles to apply to those elements. For example, the following CSS rule
changes the font of the entire HTML document:

html {
font: 15px Arial;
}

The html part is the selector. Inside braces are the declarations.
There’s only one declaration in this rule, but it’s possible to define
multiple declarations as well. The following CSS rule changes all <h1>
elements to have a full width (100%), a semi-transparent blue
background color, and a padding (space around the element text) of 10
pixels:

h1 {
width: 100%;
background-color: rgba(22, 118, 243, 0.1);
padding: 10px;
}

Selectors allow targeting by tag name (like in the previous


examples), element ID, attribute values, and others. One of the most
important selectors is the class selector. A class selector allows to target
elements that have a specified value in their class attribute. The
following snippet shows how to add the time-button CSS class to the
button in the example:
<button class="time-button">Time in the
client</button>
A CSS class selector starts with a period followed by the name of the
class to target. To style the button in the previous example, you can use
a rule like the following:

.time-button {
font-size: 15px;
padding: 10px;
border: 0px;
border-radius: 4px;
}

This rule changes the size of the font to 15 pixels, adds a padding of
10 pixels around the text in the button, removes the border, and makes
its corners slightly rounded. Combining these concepts, it’s possible to
style the full HTML document in a separate browser-time.css file:

html {
font: 15px Arial;
}

body {
margin: 30px;
}

h1 {
width: 100%;
background-color: rgba(22, 118, 243, 0.1);
padding: 10px;
}

.time-button {
font-size: 15px;
padding: 10px;
border: 0px;
border-radius: 4px;
}
Figure 1-5 shows the previous CSS rules applied to the HTML
document.

Figure 1-5 An HTML document rendered with custom CSS styles

Web Components
Web Components are a set of technologies that allows creating reusable
custom HTML elements. In this section, I’ll introduce you to the main
technology: custom elements. This should be enough for you to
understand the key Web platform concepts and see there’s no magic
really.
A Web Component is a reusable and encapsulated custom tag. The
“Time in the client” button of the example is a good candidate for this
kind of component. It’d be handy to be able to use the component in
multiple HTML documents via a custom tag:

<time-button></time-button>

Custom elements must have a dash in their names so that browsers


(and you) know it’s not a standard HTML element. There are two things
that are required to be able to use a custom element:
Implement a class that extends HTMLElement (or a specific
element).
Register the new element using
customElements.define(name, constructor).
Here’s how:

class TimeButtonElement extends HTMLElement {

constructor() {
super();
...
}
}

customElements.define("time-button",
TimeButtonElement);

In the constructor, you can define the content of the element by


using this.innerHTML or any functionality available in the DOM API:

let button = document.createElement("button");


button.textContent = "Time in the client";
button.classList.add("time-button");

button.addEventListener("click", function () {
let paragraph = document.createElement("p");
paragraph.textContent = "The time is: " +
Date();
document.body.appendChild(paragraph);
});

this.appendChild(button);

This creates the button programmatically and appends it to the


custom element. To make the element more flexible for reuse, it’s a
good idea to allow specifying values like the text shown in the button
instead of hardcoding them ("Time in the client"):

button.textContent = this.getAttribute("text");
With this, the button can be used as follows:

<time-button text="Time in the client"></time-


button>

It’s possible to use the component multiple times by just adding


more <time-button> tags to the document. Listing 1-2 shows a full
HTML document that includes two buttons with different texts, and
Listing 1-3 shows the companion time-button.js file that implements
and registers the custom element.

<!DOCTYPE html>
<html lang="en">
<head>
<title>The Web platform</title>
<link rel="stylesheet" href="browser-time.css">
</head>
<body>

<h1>It works!</h1>
<time-button text="Time in the client"></time-
button>
<time-button text="What time is it?"></time-
button>
<script src="time-button.js"></script>

</body>
</html>
Listing 1-2 An HTML document reusing a custom element

class TimeButtonElement extends HTMLElement {

constructor() {
super();
let button = document.createElement("button");
button.textContent =
this.getAttribute("text");
button.classList.add("time-button");
button.addEventListener("click", function () {
let paragraph = document.createElement("p");
paragraph.textContent = "The time is: " +
Date();
document.body.appendChild(paragraph);
});

this.appendChild(button);
}
}

customElements.define("time-button",
TimeButtonElement);
Listing 1-3 A custom element implemented in JavaScript (time-button.js)

You only need a text editor and a browser to try this out. I
recommend doing so if you are new to web development. Try creating
these files, placing them in the same directory, and opening the HTML
file in a web browser. Make sure you understand what’s going on before
continuing. The client-side step of the journey ends with Figure 1-6
which shows a screenshot of the final pure HTML/JavaScript
application developed so far.
Figure 1-6 The final pure client-side web application

Server-Side Technologies
With the fundamentals of the Web platform in place, you can now
approach the not-less-exciting server side of the equation. In short, this
means understanding what a web server is, how to add custom
functionality to a web server, and how to connect the client (browser)
with the web server.

Web Servers
The term web server is used to refer to both hardware and software
entities. In the hardware realm, a web server is a machine that contains
web server software and resources such as HTML documents,
JavaScript files, CSS files, images, audio, video, and even Java programs.
In the software realm, a web server is the software that serves the
resources in the host machine (the hardware web server) to clients
(web browsers) through HTTP (the protocol that browsers
understand). This book uses the software definition of the term web
server. Figure 1-7 shows the main components in a client-server
architecture and the flow of data through requests and responses over
HTTP.

Figure 1-7 The client-server architecture over HTTP


Often, web servers are called HTTP servers or application servers,
depending on whether the content that is served is static or dynamic. A
static web server maps URLs to files in the host and sends them when
requested by the browser. A dynamic web server is a static web server,
but it offers developers the possibility to process the hosted files before
serving them.
A web server is software that you can install and run on your
machine. You probably have one (or several) already installed in your
computer. In fact, nearly all Unix platforms (Linux, macOs, FreeBSD, and
others) come out of the box with Python, which in turn includes a
module to easily run an HTTP web server to serve the files in the
current directory. On Windows systems, you’ll have to install Python or,
even better, enable WSL (Windows Subsystem for Linux ) and use the
Windows store to install a Linux distribution such as Ubuntu which
includes Python by default.
Depending on the version of Python, you have to run one of the
following commands to start a web server that allows access through
HTTP to the files in the current directory:

> python -m SimpleHTTPServer 8080


> python3 -m http.server 8080
Tip If you have Node.js installed on your computer, you can
alternatively install an HTTP server with npm install -g
http-server and run it with http-server -p 8080.

You can request HTML documents using a URL from any device
connected to your network or even the Internet (granted that the
firewall and other security mechanisms don’t prevent access to your
web server). Figure 1-8 shows the example HTML document when I
requested it from my phone (the result you get might be slightly
different depending on the browser and operating system you use).
Notice how I used my IP address to access the file instead of opening it
directly in the browser.

Figure 1-8 An HTML document served from a web server

CGI
CGI (Common Gateway Interface ) is one of the simplest ways to serve
dynamic content from a web server. I’ll avoid the discussion on whether
CGI is dead or whether it’s good or not. My aim is to make you take one
step forward toward server-side technologies, and this technology is
easy to understand from a practical point of view.
CGI defines a way to allow web servers to interact with external
programs in the server. These programs can be implemented in any
programming language. CGI maps URLs to these programs. The
external programs communicate with the client using the standard
input (STDIN) and standard output (STDOUT), which in Java are
available through the System.in and System.out objects. The main
difference between a standard program and a CGI program is that the
output should start with a line containing a Content-Type header.
For example, to serve plain text, the output must start with Content-
Type: text/html followed by an empty line followed by the content
of the file to serve.
The Python HTTP server module includes CGI. To enable it, start the
server using the --cgi argument:

> python -m SimpleHTTPServer 8080 --cgi


> python3 -m http.server 8080 --cgi

With this server, CGI programs should be placed in the cgi-bin


directory when you are using this server. Other web servers may use
different locations and might need the installation of additional
modules to make it work.
Let’s see how to implement a CGI program in Java. Since version 11,
it’s possible to create a Java program that can be executed directly from
the command line:

#!/usr/bin/java --source 11
public class ServerTime {
public static void main(String[] args) {
System.out.println("Content-Type:
text/plain\n");
System.out.println("It works!");
}
}

Note The first line in the preceding example is a shebang—a magic


number recognized by Unix-based systems to determine whether a
file is a script or an executable binary. Remember to use the full path
to the java command and make the file executable with chmod +x
server-time. In Windows systems, you can create a .bat file to invoke
the java program. In this case, you’ll need a separate file to place the
Java code.
If you name this file server-time (don’t use the .java extension) and
place it inside the cgi-bin directory (relative to where you started the
Python web server), you’ll be able to access the program from the
browser at http://localhost:8080/cgi-bin/server-time. Figure 1-9 shows
the result.

Figure 1-9 Plain text returned by a CGI program written in Java

The previous example doesn’t really create dynamic content—every


time you request the page, the browser shows exactly the same.
However, it’s easy to understand that the Java program can do more
than returning a hardcoded string. It could instead read an HTML file
and process it to add dynamic content by replacing a placeholder and
then sending the result to STDOUT. This is a technique many web
frameworks use. Here’s a possible implementation:

#!/usr/bin/java --source 11

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Date;

public class ServerTime {

public static void main(String[] args) throws


IOException {
Path path = Path.of("cgi-bin/template.html");
String template = Files.readString(path,
Charset.defaultCharset());
String content = "Time in the server: " + new
Date();
String output = template.replace("
{{placeholder}}", content);

System.out.println("Content-Type:
text/html\n");
System.out.println(output);
}
}
This program takes the cgi-bin/template.html file, reads its content,
and replaces {{placeholder}} with a string that contains the time
calculated in the server. The template file could be something like this:

<!DOCTYPE html>
<html lang="en">
<head>
<title>CGI Example</title>
</head>
<body>

<h1>It works!</h1>
{{placeholder}}

</body>
</html>

Figure 1-10 shows the result of invoking the program in the


browser. This is now a dynamic page that shows something different
every time you request it.
Figure 1-10 Dynamic HTML document generated by a CGI program

Servlets
Jakarta Servlet (previously known as Java Servlet) is an API
specification for Java that allows developers to extend the capabilities
of a server using the Java programming language. Although I showed
you how to do so with Java in the previous section, CGI has several
disadvantages when compared to Java servlets. The main challenges
with CGI are related to the fact that the server starts a new process
every time the user requests a page (or CGI program in the server). This
slows requests to the server, potentially consumes more memory,
makes it harder to use in-memory data caches, and makes programs
less portable.
Servlets are the Java solution for web development and provide an
object-oriented abstraction of request-response protocols such as
HTTP through a solid and battle-tested API. A servlet is a Java program
(or a class) that you implement and that a software component called
servlet container manages. A servlet container is a concrete
implementation of the Jakarta Servlet API. There are web servers that
include a servlet container implementation out of the box. The most
popular ones are Apache Tomcat and Eclipse Jetty.

Tip How to decide between Tomcat and Jetty? I don’t have a good
answer here but a quick guideline to help you start your own
research. Both are production-ready and have been tested by many
serious projects. Tomcat is more popular and incorporates latest
versions of the specifications quicker. Jetty seems to be used in
projects where high performance is key and gives priority to
incorporating fixes required by the community over supporting the
latest versions of the specifications.

In short, the operating system runs processes. The JVM is run as a


process that executes bytecode-compiled programs (written in Java,
Kotlin, Scala, Groovy, or other languages for the JVM). Both the Tomcat
and Jetty Java servers are implemented in Java (although servlet
containers can be implemented in any language as long as they comply
with the Jakarta Servlet specification). The Java servers read the files
that make up your Java web application, which in turn interacts with
the servlet API to handle requests and produce responses. Figure 1-11
shows an overview of this stack.

Figure 1-11 The server-side Java stack

Here’s a simple servlet implementation:

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/*")
public class ServletExample extends HttpServlet {
private String replace;

public void doGet(HttpServletRequest request,


HttpServletResponse response)
throws
IOException, ServletException {

response.setContentType("text/plain");
response.getWriter().println("It works!");
}
}
This class uses the servlet API to write plain text to the response,
similarly to how CGI programs write the response to STDOUT. The
@WebServlet annotation configures the URL that the server uses to
dispatch requests to this servlet. In this case, all requests to the
application will be sent to an instance of the ServletExample class
created and managed by the servlet container.
To compile this class, you need to add the servlet API to the JVM
class path (the next chapter shows how to do this with Maven). Java
servers come with this API. For example, download Apache Tomcat 9.0
as a ZIP and extract its contents. You can download the server at
http://tomcat.apache.org. You will find a servlet-api.jar file
which contains the servlet API in the lib directory inside your Tomcat
installation. Copy the full path to this file and compile the
ServletExample class as follows (change the location of your own
JAR file):

javac ServletExample.java -cp /apache-


tomcat/lib/servlet-api.jar

Java web applications expect a certain directory structure in order


to be used by the Java server. Create a new java-web-development
directory inside the webapps directory of your Tomcat installation. This
is the root of your application. Compiled Java class files should be
placed in a subdirectory in your application root directory: WEB-
INF/classes. Create this directory and copy the ServletExample.class file
to it.
Start the server using the bin/startup.sh or bin/startup.bat scripts.
You might have to make these files executable with, for example, chmod
+x *.sh. The servlet can now be invoked at
http://localhost:8080/java-web-development. Figure 1-12 shows the
result.

Figure 1-12 A text document generated by a Java servlet running on Tomcat

You can also serve static HTML, CSS, and JavaScript files using the
Java server. As an exercise, try copying the example files developed in
previous sections to the root directory of your application. You’ll need
to map the servlet to a different URL to make the files available (e.g.,
@WebServlet("/example")), recompile, and restart the server. You
can stop the server by running shutdown.sh or shutdown.bat.

Web Development with Vaadin


At this point, it should be clear to you that there’s no magic in serving
HTML, JavaScript, and CSS files regardless of whether they are
generated by a Java program, a Java servlet, or the file system. Most Java
web frameworks use these technologies to make web development
easier. Vaadin is one of them.
The core of Vaadin includes a Java servlet (VaadinServlet) that
handles everything (or almost everything) for you. This servlet scans
your classes and builds a component tree that makes up your web user
interface. This component tree is similar (but not the same) to that of
the DOM in the browser. You build this tree using a Java API called
Vaadin Flow.
When a Vaadin application is invoked in the browser, the Vaadin
servlet responds with a lightweight client-side JavaScript engine. As the
user interacts with the application in the browser, the client-side engine
dynamically adds, removes, or modifies elements (implemented as Web
Components) in the DOM by sending requests and receiving responses
from the Vaadin servlet.
The client-side engine is a set of static resources that include
configuration files, Web Components, and HTML documents that are
automatically generated by Vaadin when you build the application.
These resources are created by a Maven plugin that you will learn about
in the next chapter.

Summary
By teaching you the very fundamentals of web development, this
chapter put you in a good position to start learning the specifics of
Vaadin. You saw how the Web platform allows you to render web pages
using HTML documents that can be styled with CSS rules and
dynamically modified with JavaScript. You learned what web servers
are and how to add functionality to them not only by using CGI
programs that can be written in any programming language but also by
creating servlets deployed to servlet containers that implement the
Jakarta Servlet API. You also got a glimpse of how Vaadin includes a
servlet implementation that communicates with a client-side engine to
render Web Components in the browser.
The next chapter will teach you how to set up your development
environment and how to create and debug Vaadin applications. All this
while you learn the key fundamental concepts in the framework.
Random documents with unrelated
content Scribd suggests to you:
“What does this mean?” I exclaimed in a rage. “Has he taken leave
of his senses?”
“I do not know, your lordship,” replied the sergeant-major. “Only his
Highness has ordered that your lordship should be taken to prison,
and her ladyship conducted into his presence, your lordship!”
I dashed up the steps. The sentinel did not think of detaining me,
and I made my way straight into the room, where six Jiussar officers
were playing at cards. The major was dealing. What was my
astonishment when, looking at him attentively, I recognized Ivan
Ivanovitch Zourin, who had once beaten me at play in the Simbirsk
tavern.
“Is it possible?” I exclaimed. “Ivan Ivanovitch! Is it really you?”
“Zounds! Peter Andreitch! What chance has brought you here?
Where have you come from? How is it with you, brother? Won’t you
join in a game of cards?”
“Thank you, but I would much rather you give orders for quarters to
be assigned to me.”
“What sort of quarters do you want? Stay with me.”
“I cannot: I am not alone.”
“Well, bring your comrade with you.”
“I have no comrade with me; I am with a—lady.”
“A lady! Where did you pick her up? Aha, brother mine!”
And with these words, Zourin whistled so significantly that all the
others burst out laughing, and I felt perfectly confused.
“Well,” continued Zourin: “let it be so. You shall have quarters. But it
is a pity.... We should have had one of our old sprees.... I say, boy!
Why don’t you bring in Pougatcheff’s lady friend? Or is she
obstinate? Tell her that she need not be afraid, that the gentleman is
very kind and will do her no harm—then bring her in by the collar.”
“What do you mean?” said I to Zourin. “What lady-friend of
Pougatcheff’s are you talking of? It is the daughter of the late
Captain Mironoff. I have released her from captivity, and I am now
conducting her to my father’s country seat, where I am going to
leave her.”
“What! Was it you then who was announced to me just now? In the
name of Heaven! what does all this mean?”
“I will tell you later on. For the present, I beg of you to set at ease
the mind of this poor girl, who has been terribly frightened by your
hussars.”
Zourin immediately issued the necessary orders. He went out himself
into the street to apologize to Maria Ivanovna for the involuntary
misunderstanding, and ordered the sergeant-major to conduct her to
the best lodging in the town. I remained to spend the night with
him.
We had supper, and when we two were left together, I related to
him my adventures. Zourin listened to me with the greatest
attention. When I had finished, he shook his head, and said:
“That is all very well, brother; but there is one thing which is not so;
why the devil do you want to get married? As an officer and a man
of honour, I do not wish to deceive you; but, believe me, marriage is
all nonsense. Why should you saddle yourself with a wife and be
compelled to dandle children? Scout the idea. Listen to me: shake
off this Captain’s daughter. I have cleared the road to Simbirsk, and
it is quite safe. Send her to-morrow by herself to your parents, and
you remain with my detachment. There is no need for you to return
to Orenburg. If you should again fall into the hands of the rebels,
you may not escape from them so easily a second time. In this way
your love folly will die a natural death, and everything will end
satisfactorily.”
Although I did not altogether agree with him, yet I felt that duty and
honour demanded my presence in the army of the Empress. I
resolved to follow Zourin’s advice: to send Maria Ivanovna to my
father’s estate, and to remain with his detachment.
Savelitch came in to help me to undress; I told him that he was to
get ready the next day to accompany Maria Ivanovna on her
journey. He began to make excuses.
“What do you say, my lord? How can I leave you? Who will look after
you? What will your parents say?”
Knowing the obstinate disposition of my follower, I resolved to get
round him by wheedling and coaxing him.
“My dear friend, Arkhip Savelitch!” I said to him: “do not refuse me;
be my benefactor. I do not require a servant here, and I should not
feel easy if Maria Ivanovna were to set out on her journey without
you. By serving her you will be serving me, for I am firmly resolved
to marry her, as soon as circumstances will permit.”
Here Savelitch clasped his hands with an indescribable look of
astonishment.
“To marry!” he repeated: “the child wants to marry! But what will
your father say? And your mother, what will she think?”
“They will give their consent, without a doubt, when they know
Maria Ivanovna,” I replied. “I count upon you. My father and mother
have great confidence in you; you will therefore intercede for us,
won’t you?”
The old man was touched.
“Oh, my father, Peter Andreitch!” he replied, “although you are
thinking of getting married a little too early, yet Maria Ivanovna is
such a good young lady, that it would be a pity to let the opportunity
escape. I will do as you wish. I will accompany her, the angel, and I
will humbly say to your parents, that such a bride does not need a
dowry.”
I thanked Savelitch, and then lay down to sleep in the same room
with Zourin. Feeling very much excited, I began to chatter. At first
Zourin listened to my remarks very willingly; but little by little his
words became rarer and more disconnected, and at last, instead of
replying to’ one of my questions, he began to snore. I stopped
talking and soon followed his example.
The next morning I betook myself to Maria Ivanovna. I
communicated to her my plans. She recognized the reasonableness
of them, and immediately agreed to carry them out. Zourin’s
detachment was to leave the town that day. There was no time to be
lost. I at once took leave of Maria Ivanovna, confiding her to the
care of Savelitch, and giving her a letter to my parents.
Maria burst into tears.
“Farewell, Peter Andreitch,” said she in a gentle voice. “God alone
knows whether we shall ever see each other again or not; but I will
never forget you; till my dying day you alone shall live in my heart!”
I was unable to reply. There was a crowd of people around us, and I
did not wish to give way to my feelings before them. At last she
departed. I returned to Zourin, silent and depressed. He
endeavoured to cheer me up, and I tried to divert my thoughts; we
spent the day in noisy mirth, and in the evening we set out on our
march.
It was now near the end of February. The winter, which had
rendered all military movements extremely difficult, was drawing to
its close, and our generals began to make preparations for combined
action. Pougatcheff was still under the walls of Orenburg, but our
divisions united and began to close in from every side upon the rebel
camp. On the appearance of our troops, the revolted villages
returned to their allegiance; the rebel bands everywhere retreated
before us, and everything gave promise of a speedy and successful
termination to the campaign.
Soon afterwards Prince Golitzin defeated Pougatcheff under the walls
of the fortress of Tatischtscheff, routed his troops, relieved
Orenburg, and to all appearances seemed to have given the final
and decisive blow to the rebellion. Zourin was sent at this time
against a band of rebellious Bashkirs, who, however, dispersed
before we were able to come up with them. The spring found us in a
little Tartar village. The rivers overflowed their banks, and the roads
became impassable. We consoled ourselves for our inaction with the
thought that there would soon be an end to this tedious petty
warfare with brigands and savages.
But Pougatcheff was not yet taken. He soon made his appearance in
the manufacturing districts of Siberia, where he collected new bands
of followers and once more commenced his marauding expeditions.
Reports of fresh successes on his part were soon in circulation. We
heard of the destruction of several Siberian fortresses. Then came
the news of the capture of Kazan, and the march of the impostor to
Moscow, which greatly disturbed the leaders of the army, who had
fondly imagined that the power of the despised rebel had been
completely broken. Zourin received orders to cross the Volga.
I will not describe our march and the conclusion of the war. I will
only say that the campaign was as calamitous as it possibly could
be. Law and order came to an end everywhere, and the land-holders
concealed themselves in the woods. Bands of robbers scoured the
country in all directions; the commanders of isolated detachments
punished and pardoned as they pleased; and the condition of the
extensive territory in which the conflagration raged, was terrible....
Heaven grant that we may never see such, a senseless and
merciless revolt again!
Pougatcheff took to flight, pursued by Ivan Ivanovitch Michelson. We
soon heard of his complete overthrow. At last Zourin received news
of the capture of the impostor, and, at the same time, orders to halt.
The war was ended. At last it was possible for me to return to my
parents. The thought of embracing them, and of seeing Maria
Ivanovna, again, of whom I had received no information, filled me
with delight. I danced about like a child. Zourin laughed and said
with a shrug of his shoulders:
“No good will come of it! If you get married, you are lost!”
In the meantime a strange feeling poisoned my joy: the thought of
that evil-doer, covered with the blood of so many innocent victims,
and of the punishment that awaited him, troubled me involuntarily.
“Emelia, Emelia!”[1] I said to myself with vexation, “why did you not
dash yourself against the bayonets, or fall beneath the bullets? That
was the best thing you could have done.”[2]
And how could I feel otherwise? The thought of him was inseparably
connected with the thought of the mercy which he had shown to me
in one of the most terrible moments of my life, and with the
deliverance of my bride from the hands of the detested Shvabrin.
Zourin granted me leave of absence. In a few days’ time I should
again be in the midst of my family, and should once again set eyes
upon the face of my Maria Ivanovna.... Suddenly an unexpected
storm burst upon me.
On the day of my departure, and at the very moment when I was
preparing to set out, Zourin came to my hut, holding in his hand a
paper, and looking exceedingly troubled. A pang went through my
heart. I felt alarmed, without knowing why. He sent my servant out
of the room, and said that he had something to tell me.
“What is it?” I asked with uneasiness.
“Something rather disagreeable,” replied he, giving me the paper.
“Read what I have just received.”
I read it: it was a secret order to all the commanders of
detachments to arrest me wherever I might be found, and to send
me without delay under a strong guard to Kazan, to appear before
the Commission instituted for the trial of Pougatcheff.
The paper nearly fell from my hands.
“There is no help for it,” said Zourin, “my duty is to obey orders.
Probably the report of your intimacy with Pougatcheff has in some
way reached the ears of the authorities. I hope that the affair will
have no serious consequences, and that you will be able to justify
yourself before the Commission. Keep up your spirits and set out at
once.”
My conscience was clear, and I did not fear having to appear before
the tribunal; but the thought that the hour of my meeting with Maria
might be deferred for several months, filled me with misgivings.
The telega[3] was ready. Zourin took a friendly leave of me, and I
took my place in the vehicle. Two hussars with drawn swords seated
themselves, one on each side of me, and we set out for our
destination.

[1] Diminutive of Emelian.


[2] After having advanced to the gates of Moscow, Pougatcheff
was defeated, and being afterwards sold by his accomplices for
100,000 roubles, he was imprisoned in an iron cage and carried to
Moscow, where he was executed in the year 1775.
[3] An open vehicle without springs.

CHAPTER XIV.

THE SENTENCE.

I felt convinced that the cause of my arrest was my absenting myself


from Orenburg without leave. I could easily justify myself on that
score: for sallying out against the enemy had not only not been
prohibited, but had even been encouraged. I might be accused of
undue rashness instead of disobedience of orders. But my friendly
intercourse with Pougatcheff could be proved by several witnesses,
and could not but at least appear very suspicious. During the whole
of the journey I thought of the examination that awaited me, and
mentally prepared the answers that I should make. I resolved to tell
the plain unvarnished truth before the court, feeling convinced that
this was the simplest and, at the same time, the surest way of
justifying myself.
I arrived at Kazan—the town had been plundered and set on fire. In
the streets, instead of houses, there were to be seen heaps of burnt
stones, and blackened walls without roofs or windows. Such were
the traces left by Pougatcheff! I was conducted to the fortress which
had escaped the ravages of the fire. The hussars delivered me over
to the officer of the guard. The latter ordered a blacksmith to be
sent for. Chains were placed round my feet and fastened together.
Then I was taken to the prison and left alone in a dark and narrow
dungeon, with four blank walls and a small window protected by iron
gratings.
Such a beginning boded no good to me. For all that, I did not lose
hope nor courage. I had recourse to the consolation of all those in
affliction, and after having tasted for the first time the sweet
comforting of prayer poured out from a pure but sorrow-stricken
heart, I went off into a calm sleep, without thinking of what might
happen to me.
The next morning the gaoler awoke me with the announcement that
I was to appear before the Commission. Two soldiers conducted me
through a courtyard to the Commandant’s house: they stopped in
the ante-room and allowed me to enter the inner room by myself.
I found myself in a good-sized apartment At the table, which was
covered with papers, sat two men: an elderly general, of a cold and
stem aspect, and a young captain of the Guards, of about twenty-
eight years of age, and of very agreeable and affable appearance.
Near the window, at a separate table, sat the secretary, with a pen
behind his ear, and bending over his paper, ready to write down my
depositions.
The examination began. I was asked my name and profession. The
General inquired if I was the son of Andrei Petrovitch Grineff, and on
my replying in the affirmative, he exclaimed in a stem tone:
“It is a pity that such an honourable man should have such an
unworthy son!”
I calmly replied that whatever were the accusations against me, I
hoped to be able to refute them by the candid avowal of the truth.
My assurance did not please him.
“You are very audacious, my friend,” said he, frowning: “but we have
dealt with others like you.”
Then the young officer asked me under what circumstances and at
what time I had entered Pougatcheff’s service, and in what affairs I
had been employed by him.
I replied indignantly, that, as an officer and a nobleman, I could
never have entered Pougatcheff’s service, and could never have
received any commission from him whatever.
“How comes it then,” continued the interrogator, “that the nobleman
and officer was the only one spared by the impostor, while all his
comrades were cruelly murdered? How comes it that this same
officer and nobleman could revel with the rebellious scoundrels, and
receive from the leader of the villains presents, consisting of a
pelisse, a horse, and half a rouble? Whence came such strange
friendship, and upon what does it rest, if not upon treason, or at
least upon abominable and unpardonable cowardice?”
I was deeply offended by the words of the officer of the Guards, and
I began to defend myself with great warmth. I related how my
acquaintance with Pougatcheff began upon the steppe during a
snow-storm, how he had recognized me at the capture of the
fortress of Bailogorsk and spared my life. I admitted that I had
received a pelisse and a horse from the impostor, but that I had
defended the fortress of Bailogorsk against the rebels to the last
extremity. In conclusion I appealed to my General, who could bear
witness to my zeal during the disastrous siege of Orenburg.
The stern old man took up from the table an open letter and began
to read it aloud:
“In reply to your Excellency’s inquiry respecting Ensign Grineff, who
is charged with being implicated in the present insurrection and with
entering into communication with the leader of the robbers, contrary
to the rules of the service and the oath of allegiance, I have the
honour to report that the said Ensign Grineff formed part of the
garrison in Orenburg from the beginning of October 1773 to the
twenty-fourth of February of the present year, on which date he
quitted the town, and since that time he has not made his
appearance again. We have heard from some deserters that he was
in Pougatcheff’s camp, and that he accompanied him to the fortress
of Bailogorsk, where he had formerly been garrisoned. With respect
to his conduct, I can only....”
Here the General interrupted his reading and said to me harshly:
“What do you say now by way of justification?”
I was about to continue as I began and explain the state of affairs
between myself and Maria Ivanovna as frankly as all the rest, but
suddenly I felt an invincible disgust at the thought of doing so. It
occurred to my mind, that if I mentioned her name, the Commission
would summon her to appear, and the thought of connecting her
name with the vile doings of hardened villains, and of herself being
confronted with them—this terrible idea produced such an
impression upon me, that I became confused and maintained
silence.
My judges, who seemed at first to have listened to my answers with
a certain amount of good-will, were once more prejudiced against
me on perceiving my confusion. The officer of the Guards demanded
that I should be confronted with my principal accuser. The General
ordered that the “rascal of yesterday” should be summoned. I
turned round quickly towards the door, to await the appearance of
my accuser. After a few moments I heard the clanking of chains, the
door opened, and—Shvabrin entered the room. I was astonished at
the change in his appearance. He was terribly thin and pale. His hair,
but a short time ago as black as pitch, was now quite grey; his long
beard was unkempt. He repeated all his accusations in a weak but
determined voice. According to his account, I had been sent by
Pougatcheff to Orenburg as a spy; every day I used to ride out to
the advanced posts, in order to transmit written information of all
that took place within the town; that at last I had gone quite over to
the side of the usurper and had accompanied him from fortress to
fortress, endeavouring in every way to injure my companions in
crime, in order to occupy their places and profit the better by the
rewards of the impostor.
I listened to him in silence, and I rejoiced on account of one thing:
the name of Maria was not mentioned by the scoundrel, whether it
was that his self-love could not bear the thought of one who had
rejected him with contempt, or that within his heart there was a
spark of that self-same feeling which had induced me to remain
silent. Whatever it was, the name of the daughter of the
Commandant of Bailogorsk was not pronounced in the presence of
the Commission. I became still more confirmed in my resolution, and
when the judges asked me what I had to say in answer to Shvabrin’s
evidence, I replied that I still stood by my first statement and that I
had nothing else to add in justification of myself.
The General ordered us to be led away. We quitted the room
together. I looked calmly at Shvabrin, but did not say a word to him.
He looked at me with a malicious smile, lifted up his fetters and
passed out quickly in front of me. I was conducted back to prison,
and was not compelled to undergo a-second examination.
I was not a witness of all that now remains for me to impart to the
reader; but I have heard it related so often, that the most minute
details are indelibly engraven upon my memory, and it seems to me
as if I had taken a part in them unseen.
Maria Ivanovna was received by my parents with that sincere
kindness which distinguished people in the olden time. They
regarded it as a favour from God that the opportunity was afforded
them of sheltering and consoling the poor orphan. They soon
became sincerely attached to her, because it was impossible to know
her and not to love her. My love for her no longer appeared mere
folly to my father, and my mother had one wish only, that her Peter
should marry the pretty Captain’s daughter.
The news of my arrest filled all my family with consternation. Maria
Ivanovna had related so simply to my parents my strange
acquaintance with Pougatcheff, that not only had they felt quite easy
about the matter, but had often been obliged to laugh heartily at the
whole story. My father would not believe that I could be implicated
in an infamous rebellion, the aim of which was the destruction of the
throne and the extermination of the nobles. He questioned Savelitch
severely. My retainer did not deny that I had been the guest of
Pougatcheff, and that the villain had acted very generously towards
me, but he affirmed with a solemn oath that he had never heard a
word about treason. My old parents became easier in mind, and
waited impatiently for more favourable news. Maria Ivanovna,
however, was in a state of great agitation, but she kept silent, as she
was modest and prudent in the highest degree.
Several weeks passed.... Then my father unexpectedly received from
St. Petersburg a letter from our relative, Prince B——. The letter was
about me. After the usual compliments, he informed him that the
suspicions which had been raised concerning my participation in the
plots of the rebels, had unfortunately been shown to be only too
well founded; that capital punishment would have been meted out
to me, but that the Empress, in consideration of the faithful services
and the grey hairs of my father, had resolved to be gracious towards
his criminal son, and, instead of condemning him to suffer an
ignominious death, had ordered that he should be sent to the most
remote part of Siberia for the rest of his life.
This unexpected blow nearly killed my father. He lost his usual
firmness, and his grief, usually silent, found vent in bitter complaints.
“What!” he cried, as if beside himself: “my son has taken part in
Pougatcheff’s plots! God of Justice, that I should live to see this! The
Empress spares his life! Does that make it any better for me? It is
not death at the hands of the executioner that is so terrible: my
great-grandfather died upon the scaffold for the defence of that
which his conscience regarded as sacred;[1] my father suffered with
Volinsky and Khrouschtcheff.[2] But that a nobleman should be false
to his oath, should associate with robbers, with murderers and with
runaway slaves!... Shame and disgrace upon our race!”
Frightened by his despair, my mother dared not weep in his
presence; she endeavoured to console him by speaking of the
uncertainty of reports, and the little dependency to be placed upon
the opinions of other people. But my father was inconsolable.
Maria Ivanovna suffered more than anybody. Being firmly convinced
that I could have justified myself if I had only wished to do so, she
guessed the reason of my silence, and considered herself the cause
of my misfortune. She hid from everyone her tears and sufferings,
and was incessantly thinking of the means by which I might be
saved.
One evening my father was seated upon the sofa turning over the
leaves’ of the “Court Calendar,” but his thoughts were far away, and
the reading of the book failed to produce upon him its usual effect.
He was whistling an old march. My mother was silently knitting a
woollen waistcoat, and from time to time her tears ran down upon
her work. All at once, Maria Ivanovna, who was also at work in the
same room, declared that it was absolutely necessary that she
should go to St. Petersburg, and she begged of my parents to
furnish her with the means of doing so. My mother was very much
hurt at this resolution.
“Why do you wish to go to St. Petersburg?” said she. “Is it possible,
Maria Ivanovna, that you want to forsake us also?”
Maria replied that her fate depended upon this journey, that she was
going to seek help and protection from powerful persons, as the
daughter of a man who had fallen a victim to his fidelity.
My father lowered his head; every word that recalled to mind the
supposed crime of his son, was painful to him, and seemed like a
bitter reproach.
“Go, my child,” he said to her at last with a sigh; “we do not wish to
stand in the way of your happiness. May God give you an honest
man for a husband, and not an infamous traitor.”
He rose and left the room.
Maria Ivanovna, left alone with my mother, confided to her a part of
her plan. My mother, with tears in her eyes, embraced her and
prayed to God that her undertaking might be crowned with success.
Maria Ivanovna made all her preparations, and a few days
afterwards she set out on her road with the faithful Palasha and the
equally faithful Savelitch, who, forcibly separated from me, consoled
himself at least with the thought that he was serving my betrothed.
Maria Ivanovna arrived safely at Sofia, and learning that the Court
was at that time at Tsarskoe Selo, she resolved to stop there. At the
post-house, a small recess behind a. partition was assigned to her.
The postmaster’s wife came immediately to chat with her, and she
informed Maria that she was niece to one of the stove-lighters of the
Court, and she initiated her into all the mysteries of Court life. She
told her at what hour the Empress usually got up, when she took
coffee, and when she went out for a walk; what great lords were
then with her; what she had deigned to say the day before at table,
and whom she had received in the evening. In a word, the
conversation of Anna Vlassievna was as good as a volume of
historical memoirs, and would be very precious to the present
generation.
Maria Ivanovna listened to her with great attention. They went
together into the palace garden. Anna Vlassievna related the history
of every alley and of every little bridge, and after seeing all that they
wished to see, they returned to the post-house, highly satisfied with
each other.

The next day, early in the morning, Maria Ivanovna awoke, dressed
herself, and quietly betook herself to the palace garden. It was a
lovely morning; the sun was gilding the tops of the linden trees,
already turning yellow beneath the cold breath of autumn. The
broad lake glittered in the light. The swans, just awake, came sailing
majestically out from under the bushes overhanging the banks.
Maria Ivanovna walked towards a delightful lawn, where a
monument had just been erected in honour of the recent victories
gained by Count Peter Alexandrovitch Roumyanzoff.[3] Suddenly a
little white dog of English breed ran barking towards her. Maria grew
frightened and stood still. At the same moment she heard an
agreeable female voice call out:
“Do not be afraid, it will not bite.”
Maria saw a lady seated on the bench opposite the monument.
Maria sat down on the other end of the bench. The lady looked at
her attentively; Maria on her side, by a succession of stolen glances,
contrived to examine the stranger from head to foot. She was attired
in a white morning gown, a light cap, and a short mantle. She
seemed to be about forty years of age. Her face, which was full; and
red, wore an expression of calmness and dignity, and her blue eyes
and smiling lips had an indescribable charm about them. The lady
was the first to break silence.
“You are doubtless a stranger here?” said she.
“Yes, I only arrived yesterday from the country.”
“Did you come with your parents?”
“No, I came alone.”
“Alone! But you are very young to travel alone.”
“I have neither father nor mother.”
“Perhaps you have come here on some business?”
“Yes, I have come to present a petition to the Empress.”
“You are an orphan: probably you have come to complain of some
injustice.”
“No, I have come to ask for mercy, not justice.”
“May I ask you who you are?”
“I am the daughter of Captain Mironoff.”
“Of Captain Mironoff! the same who was Commandant of one of the
Orenburg fortresses?”
“The same, Madam.”
The lady appeared moved.
“Forgive me,” said she, in a still kinder voice, “for interesting myself
in your business; but I am frequently at Court; explain to me the
nature of your request, and perhaps I may be able to help you.”
Maria Ivanovna arose and thanked her respectfully. Everything about
this unknown lady drew her towards her and inspired her with
confidence. Maria drew from her pocket a folded paper and gave it
to her unknown protectress, who read it to herself.
At first she began reading with an attentive and benevolent
expression; but suddenly her countenance changed, and Maria,
whose eyes followed all her movements, became frightened by the
severe expression of that face, which a moment before had been so
calm and gracious.
“You are supplicating for Grineff?” said the lady in a cold tone. “The
Empress cannot pardon him. He went over to the usurper, not out of
ignorance and credulity, but as a depraved and dangerous
scoundrel.”
“Oh! it is not true!” exclaimed Maria.
“How, not true?” replied the lady, her face flushing.
“It is not true; as God is above us, it is not true! I know all, I will tell
you everything. It was for my sake alone that he exposed himself to
all the misfortunes that have overtaken him. And if he did not justify
himself before the Commission, it was only because he did not wish
to implicate me.”
She then related with great warmth all that is already known to the
reader.
The lady listened to her attentively.
“Where are you staying?” she asked, when Maria had finished her
story; and hearing that it was with Anna Vlassievna, she added with
a smile:
“Ah, I know. Farewell; do not speak to anybody about our meeting. I
hope that you will not have to wait long for an answer to your letter.”
With these words she rose from her seat and proceeded down a
covered alley, while Maria Ivanovna returned to Anna Vlassievna,
filled with joyful hopes.
Her hostess scolded her for going out so early; the autumn air, she
said, was not good for a young girl’s health. She brought an urn, and
over a cup of tea she was about to begin her endless discourse
about the Court, when suddenly a carriage with armorial bearings
stopped before the door, and a lackey entered with the
announcement that the Empress summoned to her presence the
daughter of Captain Mironoff.
Anna Vlassievna was perfectly amazed.
“Good Lord!” she exclaimed: “the Empress summons you to Court.
How did she get to know anything about you? And how will you
present yourself before Her Majesty, my little mother? I do not think
that you even know how to walk according to Court manners....
Shall I conduct you? I could at any rate give you a little caution. And
how can you go in your travelling dress? Shall I send to the nurse for
her yellow gown?”
The lackey announced that it was the Empress’s pleasure that Maria
Ivanovna should go alone and in the dress that she had on. There
was nothing else to be done: Maria took her seat in the carriage and
was driven off, accompanied by the counsels and blessings of Anna
Vlassievna.
Maria felt that our fate was about to be decided; her heart beat
violently. In a few moments the carriage stopped at the gate of the
palace. Maria descended the steps with trembling feet. The doors
flew open before her. She traversed a large number of empty but
magnificent rooms, guided by the lackey. At last, coming to a closed
door, he informed her that she would be announced directly, and
then left her by herself.
The thought of meeting the Empress face to face so terrified her,
that she could scarcely stand upon her feet. In about a minute the
door was opened, and she was ushered into the Empress’s boudoir.
The Empress was seated at her toilette-table, surrounded by a
number of Court ladies, who respectfully made way for Maria
Ivanovna. The Empress turned round to her with an amiable smile,
and Maria recognized in her the lady with whom she had spoken so
freely a few minutes before. The Empress bade her approach, and
said with a smile:
“I am glad that I am able to keep my word and grant your petition.
Your business is arranged. I am convinced of the innocence of your
lover. Here is a letter which you will give to your future father-in-
law.”
Maria took the letter with trembling hands and, bursting into tears,
fell at the feet of the Empress, who raised her up and kissed her
upon the forehead.
“I know that you are not rich,” said she; “but I owe a debt to the
daughter of Captain Mironoff. Do not be uneasy about the future. I
will see to your welfare.”
After having consoled the poor orphan in this way, the Empress
allowed her to depart. Maria left the palace in the same carriage that
had brought her thither. Anna Vlassievna, who was impatiently
awaiting her return, overwhelmed her with questions, to which Maria
returned very vague answers. Although dissatisfied with the
weakness of her memory, Anna Vlassievna ascribed it to her
provincial bashfulness, and magnanimously excused her. The same
day Maria, without even desiring to glance at St. Petersburg, set out
on her return journey.

The memoirs of Peter Andreitch Grineff end here. But from a family
Tradition we learn that he was released from his imprisonment
towards the end of the year 1774 by order of the Empress, and that
he was present at the execution of Pougatcheff, who recognized him
in the crowd and nodded to him with his head, which, a few
moments afterwards, was shown lifeless and bleeding to the people.
[4] Shortly afterwards, Peter Andreitch and Maria Ivanovna were
married. Their descendants still flourish in the government of
Simbirsk. About thirty versts from ----, there is a village belonging to
ten landholders. In the house of one of them, there may still be
seen, framed and glazed, the autograph letter of Catherine II. It is
addressed to the father of Peter Andreitch, and contains the
justification of his son, and a tribute of praise to the heart and
intellect of Captain Mironoff’s daughter.

[1] One of Poushkin’s ancestors was condemned to death by


Peter the Great.
[2] Chiefs of the Russian party against Biren, the unscrupulous
German Favourite of the Empress Anne. They were put to death
under circumstances of great cruelty.
[3] A famous Russian general who distinguished himself in the
war against the Turks.
[4] It is said that even at the present day the peasants in the
south-east of Russia are firmly convinced that Pougatcheff was
really the Emperor Peter III., and not an impostor.

DOUBROVSKY.
CHAPTER I.

Some years ago, there lived on one of his estates a Russian


gentleman of the old school named Kirila Petrovitch Troekouroff. His
wealth, distinguished birth, and connections gave him great weight
in the government where his property was situated. Completely
spoilt by his surroundings, he was in the habit of giving way to every
impulse of his passionate nature, to every caprice of his sufficiently
narrow mind. The neighbours were ready to gratify his slightest
whim; the government officials trembled at his name. Kirila
Petrovitch accepted all these signs of servility as homage due to him.
His house was always full of guests, ready to amuse his lordship’s
leisure, and to join his noisy and sometimes boisterous mirth.
Nobody dared to refuse his invitations or, on certain days, omit to
put in an appearance at the village of Pokrovskoe. Kirila Petrovitch
was very hospitable, and in spite of the extraordinary vigour of his
constitution, he suffered two or three times a week from surfeit, and
became tipsy every evening.
Very few of the young women of his household escaped the
amorous attentions of this old man of fifty. Moreover, in one of the
wings of his house lived sixteen girls engaged in needlework. The
windows of this wing were protected by wooden bars, the doors
were kept locked, and the keys retained by Kirila Petrovitch. The
young recluses at an appointed hour went into the garden for a walk
under the surveillance of two old women. From time to time Kirila
Petrovitch married some of them off, and new comers took their
places. He treated his peasants and domestics in a severe and
arbitrary fashion, in spite of which they were very devoted to him:
they loved to boast of the wealth and influence of their master, and
in their turn took many a liberty with their neighbours, trusting to his
powerful protection.
The ordinary occupations of Troekouroff consisted in driving over his
vast domains, passing his nights in prolonged revels, and playing
practical jokes, specially invented from time to time, the victims
being generally new acquaintances, though his old friends did not
always escape, one only—Andrei Gavrilovitch Doubrovsky—excepted.
This Doubrovsky, a retired lieutenant of the Guards, was his nearest
neighbour, and possessed seventy serfs. Troekouroff, haughty in his
dealings with people of the highest rank, respected Doubrovsky, in
spite of his humble fortune. They had been friends in the service,
and Troekouroff knew from experience the impatience and decision
of his character. The celebrated events of the year 1762[1] separated
them for a long time. Troekouroff, a relative of the Princess Dashkoff,
[2] received rapid promotion; Doubrovsky with his reduced fortune,
was compelled to leave the service and settle down in the only
village that remained to him. Kirila Petrovitch, hearing of this,
offered him his protection but Doubrovsky thanked him and
remained poor and independent. Some years later, Troekouroff,
having obtained the rank of general, and retired to his estate, they
met again and were delighted with each other. After that they saw
each other every day, and Kirila Petrovitch, who had never deigned
to visit anybody in his life, came quite as a matter of course to the
little house of his old comrade. Being of the same age, born in the
same rank of society, and having received the same education, they
resembled each other somewhat in character and inclinations. In
some respects their fates had been similar: both had married for
love, both had soon become widowers, and both had been left with
an only child. The son of Doubrovsky was studying at St. Petersburg;
the daughter of Kirila Petrovitch grew up under the eyes of her
father, and Troekouroff often said to Doubrovsky:
“Listen, brother Andrei Gavrilovitch; if your Volodka[3] should be
successful, I will give him Masha[4] for his wife, in spite of his being
as naked as a goshawk.”
Andrei Gavrilovitch used to shake his head, and generally replied:
“No’, Kirila Petrovitch; my Volodka is no match for Maria Kirilovna. A
poor petty noble, such as he, would do better to marry a poor girl of
the petty nobility, and be the head of his house, rather than become
the bailiff of some spoilt little woman.”
Everybody envied the good understanding existing between the
haughty Troekouroff and his poor neighbour, and wondered at the
boldness of the latter when, at the table of Kirila Petrovitch, he
expressed his own opinion frankly, and did not hesitate to maintain
an opinion contrary to that of his host Some attempted to imitate
him and ventured to overstep the limits of the license accorded
them; but Kirila Petrovitch taught them such a lesson, that they
never afterwards felt any desire to repeat the experiment.
Doubrovsky alone remained beyond the range of this general law.
But an unexpected incident deranged and altered all this.
One day, in the beginning of autumn, Kirila Petrovitch prepared to go
out hunting. Orders had been given the evening before for the
huntsmen and gamekeepers to be ready at five o’clock in the
morning. The tent and kitchen had been sent on beforehand to the
place where Kirila Petrovitch was to dine. The host and his guests
went to the kennel, where more than five hundred harriers and
greyhounds lived in luxury and warmth, praising the generosity of
Kirila Petrovitch in their canine language. There was also a hospital
for the sick dogs, under the care of staff-surgeon Timoshka, and a
separate place where the bitches brought forth and suckled their
pups. Kirila Petrovitch was proud of this magnificent establishment,
and never missed an opportunity of boasting about it, before his
guests, each of whom had inspected it at least twenty times. He
walked through the kennel, surrounded by his guests and
accompanied by Timoshka and the head gamekeepers, pausing
before some of the compartments, either to ask, after the health of
some sick dog, to make some observation more or less just and
severe, or to call some dog to him; by name and speak caressingly
to it. The guests considered it their duty to go into raptures over
Kirila Petrovitch’s kennel; Doubrovsky alone remained silent and
frowned. He was an ardent sportsman; but his modest fortune only
permitted him to keep two harriers and one greyhound, and he
could not restrain a certain feeling of envy at the sight of this
magnificent establishment.
“Why do you frown, brother?” Kirila Petrovitch asked him. “Does not
my kennel please you?”
“No,” replied Doubrovsky abruptly: “the kennel, is marvellous, but I
doubt whether your people live as well as your dogs.”
One of the gamekeepers took offence.
“Thanks to God and our master, we have nothing to complain of,”
said he; “but if the truth must be told, there are certain nobles who
would not do badly if they exchanged their manor-house for one of
the compartments of this kennel: they would be better fed and feel
warmer.”
Kirila Petrovitch burst out laughing at this insolent remark from his
servant, and the guests followed his example, although they felt that
the gamekeeper’s joke I might apply to them also. Doubrovsky
turned pale and said not a word. At that moment a basket,
containing some new-born puppies, was brought to Kirila Petrovitch;
he chose two out of the litter and ordered the rest to be drowned. In
the meantime Andrei Gavrilovitch had disappeared without anybody
having observed it.
On returning with his guests from the kennel, Kirila Petrovitch sat
down to supper, and it was only then that he noticed the absence of
Doubrovsky. His people informed him that Andrei Gavrilovitch had
gone home. Troekouroff immediately gave orders that he was to be
overtaken and brought back without fail. He had never gone hunting
without Doubrovsky, who was a fine and experienced connoisseur in
all matters relating to dogs, and an infallible umpire in all possible
disputes connected with sport. The servant who had galloped after
him, returned while they were still seated at table, and informed his
master that Andrei Gavrilovitch had refused to listen to him and
would not return. Kirila Petrovitch, as usual, was heated with liquor,
and becoming very angry, he sent the same servant a second time
to tell Andrei Gavrilovitch that if he did not return at once to spend
the night at Pokrovskoe, he, Troekouroff, would break off all friendly
intercourse with him for ever. The servant galloped off again. Kirila
Petrovitch rose from the table, dismissed his guests retired to bed.
The next day his first question was: “Is Andrei Gavrilovitch here?” A
triangular-shaped letter was handed to him. Kirila Petrovitch ordered
his secretary to read it aloud, and the following is what he heard:

“Gracious Sir!
“I do not intend to return to Pokrovskoe until you send the dog-
feeder Paramoshka to me with an apology: I shall retain the
liberty of punishing or for forgiving him. I cannot put up with
jokes from your servants, nor do I intend to put up with them
from you, as I am not a buffoon, but a gentleman of ancient
family. I remain your obedient servant,
“ANDREI DOUBROVSKY.”

According to present ideas of etiquette, such a letter would be very


unbecoming; it irritated Kirila Petrovitch, not by its strange style, but
by its substance.
“What!” exclaimed Troekouroff, springing barefooted out of bed;
“send my people to him with an apology! And he to be at liberty to
punish or pardon them! What can he be thinking of? Does he know
with whom he is dealing? I’ll teach him a lesson! He shall know what
it is to oppose Troekouroff!”
Kirila Petrovitch dressed himself and set out for the hunt with his
usual ostentation. But the chase was not successful; during the
whole of the day one hare only was seen, and that escaped. The
dinner in the field, under the tent, was also a failure, or at least it
was not to the taste of Kirila Petrovitch, who struck the cook, abused
the guests, and on the return journey rode intentionally, with all his
suite, through the fields of Doubrovsky.
[1] Alluding to the deposition and assassination of Peter III., and
the accession of his wife Catherine II.
[2] One of Catherine’s partisans in the revolution of 1762.
[3] Diminutive of Vladimir.
[4] Diminutive of Maria or Mary.

CHAPTER II.

Several days passed, and the animosity between the two neighbours
did not subside. Andrei Gavrilovitch returned no more to Pokrovskoe,
and Kirila Petrovitch, feeling dull without him, vented his spleen in
the most insulting expressions, which, thanks to the zeal of the
neighbouring nobles, reached Doubrovsky revised and augmented. A
fresh incident destroyed the last hope of a reconciliation.
One day, Doubrovsky was going the round of his little estate, when,
on approaching a grove of birch trees, he heard the blows of an axe,
and a minute afterwards the crash of a falling tree; he hastened to
the spot and found some of the Pokrovskoe peasants stealing his
wood. Seeing him, they took to flight; but Doubrovsky, with the
assistance of his coachman, caught two of them, whom he brought
home bound. Moreover, two horses, belonging to the enemy, fell into
the hands of the conqueror.
Doubrovsky was exceedingly angry. Before this, Troekouroff’s
people, who were well-known robbers, had never dared to play
tricks within the boundaries of his property, being aware of the
friendship which existed between him and their master. Doubrovsky
now perceived that they were taking advantage of the rupture which
had occurred between him and his neighbour, and he resolved,
contrary to all ideas of the rules of war, to teach his prisoners a
lesson with the rods which they themselves had collected in his
grove, and to send the horses to work and to incorporate them with
his own cattle.
The news of these proceedings reached the ears of Kirila Petrovitch
that very same day. He was almost beside himself with rage, and in
the first moment of his passion, he wanted to take all his domestics
and make an attack upon Kistenevka (for such was the name of his
neighbour’s village), raze it to the ground, and besiege the
landholder in his own residence. Such exploits were not rare with
him; but his thoughts soon took another direction. Pacing with heavy
steps up and down the hall, he glanced casually out of the window,
and saw a troika in the act of stopping at his, gate. A man in a
leather travelling-cap and a frieze cloak stepped out of the telega
and proceeded towards the wing occupied by the bailiff. Troekouroff
recognized the assessor Shabashkin, and gave orders for him to be
sent in to him. A minute afterwards Shabashkin stood before Kirila
Petrovitch, and bowing repeatedly, waited respectfully to hear what
he had to say to him.
“Good day—what is your name?” said Troekouroff: “Why have you
come?”
“I was going to the town, Your Excellency,” replied Shabashkin, “and
I called on Ivan Demyanoff to know if there; were any orders.”
“You have come at a very opportune moment—what is your name? I
have need of you. Take a glass of brandy and listen to me.”
Such a friendly welcome agreeably surprised the assessor: he
declined the brandy, and listened to Kirila Petrovitch with all possible
attention.
“I have a neighbour,” said Troekouroff, “a small proprietor, a rude
fellow, and I want to take his property from him.... What do you
think of that?”
“Your Excellency, are there any documents—?”
“Don’t talk nonsense, brother,[1] what documents are you talking
about? The business in this case is to take his property away from
him, with or without documents. But stop! This estate belonged to
us at one time. It was bought from a certain Spitsin, and then sold
to Doubrovsky’s father. Can’t you make a case out of that?”
“It would be difficult, Your Excellency: probably the sale was
effected in strict accordance with the law.”
“Think, brother; try your hardest.”
“If, for example, Your Excellency could in some way obtain from your
neighbour the contract, in virtue of which he holds possession of his
estate, then, without doubt—”
“I understand, but that is the misfortune: all his papers were burnt
at the time of the fire.”
“What! Your Excellency, his papers were burnt? What could be
better? In that case, take proceedings according to law; without the
slightest doubt you will receive complete satisfaction.”
“You think so? Well, see to it, I rely upon your zeal, and you can rest
assured of my gratitude.”
Shabashkin, bowing almost to the ground, took his departure; from
that day he began to devote all his energies to the business
intrusted to him and, thanks to his prompt action, exactly a fortnight
afterwards Doubrovsky received from the town a summons to
appear in court and to produce the documents, in virtue of which he
held possession of the village of Kistenevka.
Andrei Gavrilovitch, greatly astonished by this unexpected request,
wrote that very same day a somewhat rude reply, in which he
explained that the village of Kistenevka became his on the death of
his father, that he held it by right of inheritance, that Troekouroff
had nothing to do with the matter, and that all adventitious
pretensions to his property were nothing but the outcome of
chicanery and roguery. Doubrovsky had no experience in litigation.
He generally followed the dictates of common sense, a guide rarely
safe, and nearly always insufficient.
This letter produced a very agreeable impression on the mind of
Shabashkin; he saw, in the first place, that Doubrovsky knew very
little about legal matters; and, in the second, that it would not be
difficult to place such a passionate and indiscreet man in a very
disadvantageous position.
Andrei Gavrilovitch, after a more careful consideration of the
questions addressed to him, saw the necessity of replying more
circumstantially. He wrote a sufficiently pertinent paper, but in the
end this proved insufficient also.
The business dragged on. Confident in his own right, Andrei
Gavrilovitch troubled himself very little about the matter; he had
neither the inclination nor the means to scatter money about him,
and he began to deride the mercenary consciences of the scribbling
fraternity. The idea of being made the victim of treachery never
entered his head. Troekouroff, on his side, thought as little of
winning the case he had devised. Shabashkin took the matter in
hand for him, acting in his name, threatening and bribing the judges
and quoting and interpreting the ordinances in the most distorted
manner possible.
At last, on the 9th day of February, in the year 18—, Doubrovsky
received, through the town police, an invitation to appear at the
district court to hear the decision in the matter of the disputed
property between himself—Lieutenant Doubrovsky, and General-in-
Chief Troekouroff, and to sign his approval or disapproval of the
verdict. That same day Doubrovsky set out for the town. On the
road he was overtaken by Troekouroff. They glared haughtily at each
other, and Doubrovsky observed a malicious smile upon the face of
his adversary.
Arriving in town, Andrei Gavrilovitch stopped at the house of an
acquaintance, a merchant, with whom he spent the night, and the
next morning he appeared before the Court. Nobody paid any
attention, to him. After him arrived Kirila Petrovitch. The members of
the Court received him with every manifestation of the deepest
submission, and an armchair was brought to him out of
consideration for his rank, years and corpulence. He sat down;
Andrei Gavrilovitch stood leaning against the wall. A deep silence
ensued, and the secretary began in a sonorous voice to read the
decree of the Court.
When the secretary had ceased reading, the assessor arose and,
with a low bow, turned to Troekouroff, inviting him to sign the paper
which he held out to him. Troekouroff, quite triumphant, took the
pen and wrote beneath the decision of the Court his complete
satisfaction.
It was now Doubrovsky’s turn. The secretary handed the paper to
him, but Doubrovsky stood immovable, with his head bent down.
The secretary repeated his invitation: “To subscribe his full and
complete satisfaction, or his manifest dissatisfaction, if he felt in his
conscience that his case was just, and intended to appeal against
the decision of the Court.”
Doubrovsky remained silent ... Suddenly he raised his head, his eyes
sparkled, he stamped his foot, pushed back the secretary, with such
force, that he fell, seized the inkstand, hurled it at the assessor, and
cried in a wild voice:
“What! you don’t respect the Church of God! Away, you race of
Shem!”
Then turning to Kirila Petrovitch:
“Has such a thing ever been heard of, Your Excellency?” he
continued. “The huntsmen lead greyhounds into the Church of God!
The dogs are running about the church! I will teach them a lesson
presently!”
Everybody was terrified. The guards rushed in on hearing the noise,
and with difficulty overpowered him. They led him out and placed
him in a sledge. Troekouroff went out after him, accompanied by the
whole Court Doubrovsky’s sudden madness had produced a deep
impression upon his imagination; the judges, who had counted upon
his gratitude, were not honoured by receiving a single affable word
from him. He returned immediately to Pokrovskoe, secretly tortured
by his conscience, and not at all satisfied with the triumph of his
hatred. Doubrovsky, in the meantime, lay in bed. The district doctor
—not altogether a blockhead—bled him and applied leeches and
mustard-plasters to him. Towards evening he began to feel better,
and the next day he was taken to Kistenevka, which scarcely
belonged to him any longer.

[1] Superiors in Russia frequently make use of this term in


addressing their inferiors.

CHAPTER III.

Some time elapsed, but the health of the stricken Doubrovsky


showed no signs of improvement. It is true that the fits of madness
did not recur, but his strength became visibly less. He forgot his
former occupations, rarely left his room, and for days together
remained absorbed in his own reflections. Egorovna, a kind-hearted
old woman who had once tended his son, now became his nurse.
She waited upon him like a child, reminded him when it was time to
eat and sleep, fed him and even put him to bed. Andrei Gavrilovitch
obeyed her, and had no intercourse with anybody else. He was not
in a condition to think about his affairs or to look after his property,
and Egorovna saw the necessity of informing young Doubrovsky,
who was then serving in one of the regiments of Foot Guards
stationed in St. Petersburg, of everything that had happened. And
so, tearing a leaf from the account-book, she dictated to Khariton
the cook, the only literate person in Kistenevka, a letter, which she
sent off that same day to the town post.
But it is time for the reader to become acquainted with the real hero
of this story.
Vladimir Doubrovsky had been educated at the cadet school and, on
leaving it, had entered the Guards as sub-lieutenant. His father
spared nothing that was necessary to enable him to live in a
becoming manner, and the young man received from home a great
deal more than he had any right to expect. Being imprudent and
ambitious, he indulged in extravagant habits, ran into debt, and
troubled himself very little about the future. Occasionally the thought
crossed his mind that sooner or later he would be obliged to take to
himself a rich bride.
One evening, when several officers were spending a few hours with
him, lolling on the couches and smoking pipes with amber mouth-
pieces, Grisha,[1] his valet, handed him a letter, the address and seal
of which immediately attracted the young man’s attention. He hastily
opened it and read the following:

“Our Lord Vladimir Andreivitch, I, your old nurse, venture to


inform you of the health of your papa. He is very poorly,
sometimes he wanders in his talk, and the whole day long he
sits like a stupid child—but life and death are in the hands of
God. Come to us, my bright little falcon, and, we will send
horses to meet you at Pesotchnoe. We hear that the Court is
going to hand us over to Kirila Petrovitch Troekouroff, because it
is said that we belong to him, although we have always
belonged to you, and have always heard so ever since we can
remember. You might, living in St. Petersburg, inform our Father
the Czar of this, and he will not allow us to be wronged. It has
been raining here for the last fortnight, and the shepherd Rodia
died about Michaelmas Day. I send my maternal blessing to
Grisha. Does he serve you well? I remain your faithful nurse,
“ARINA EGOROVNA BOUZIREVA.”

Vladimir Doubrovsky read these somewhat unintelligible lines several


times with great agitation. He had lost his mother during his
childhood, and, hardly knowing his father, had been taken to St.
Petersburg when he was eight years of age. In spite of that, he was
romantically attached to his father, and having had but little
opportunity of enjoying the pleasures of family life, he loved it all the
more in consequence.
The thought of losing his father pained him exceedingly, and the
condition of the poor invalid, which he guessed from his nurse’s
letter, horrified him. He imagined his father, left in an out-of-the-way
village, in the hands of a stupid old woman and her fellow servants,
threatened by some misfortune, and expiring without help in the
midst of tortures both mental and physical. Vladimir Andreivitch
reproached himself with criminal neglect. Not having received any
news of his father for a long time, he had not even thought of
making inquiries about him, supposing him to be travelling about or
engaged in the management of his estate. That same evening he
began to take the necessary steps for obtaining leave of absence,
and two days afterwards he set out in the stage coach, accompanied
by his faithful Grisha.
Vladimir Andreivitch neared the post station at which he was to take
the turning for Kistenevka. His heart was filled with sad forebodings;
he feared that he would no longer find his father alive. He pictured
to himself the dreary kind of life that “awaited him in the village: the
loneliness, solitude, poverty and cares of business of which he knew
nothing. Arriving at the station, he went to the postmaster and
asked for fresh horses. The postmaster, having inquired where he
was going, informed him that horses sent from Kistenevka had been
waiting for him for the last four days. Soon appeared before Vladimir
Andreivitch the old coachman Anton, who used formerly to take him
over the stables and look after his pony. Anton’s eyes filled with
tears on seeing his young master, and bowing to the ground, he told
him that his old master was still alive, and then hastened to harness
the horses. Vladimir Andreivitch declined the proffered breakfast,
and hastened to depart. Anton drove him along the cross country
roads, and conversation began between them.
“Tell me, if you please, Anton, what is this business between my
father and Troekouroff?”
“God knows, my little father Vladimir Andreivitch; our master, they
say, had a dispute with Kirila Petrovitch, and the latter summoned
him before the judge, though very often he himself is the judge. It is
not the business of servants to discuss the affairs of their masters,
but it was useless of your father to contend against Kirila Petrovitch:
better had it been if he had not opposed him.”
“It seems, then, that this Kirila Petrovitch does just what he pleases
among you?”
“He certainly does, master: he does not care a rap for the assessor,
and the chief of police runs on errands for him. The nobles repair to
his house to do homage to him, for as the proverb says: ‘Where
there is a trough, there will the pigs be also.’”
“Is it true that he wants to take our estate from us?”
“Oh, master, that is what we have heard. A few days ago, the sexton
from Pokrovskoe said at the christening held at the house of our
overseer: ‘You do well to enjoy yourselves while you are able, for
you’ll not have much chance of doing so when Kirila Petrovitch takes
you in hand;’ and Nikita the blacksmith said to him: ‘Savelitch, don’t
distress your fellow sponsor, don’t disturb the guests. Kirila
Petrovitch is what he is, and Andrei Gavrilovitch is the same—and we
are all God’s and the Czar’s.’ But you cannot sew a button upon
another person’s mouth.”
“Then you do not wish to pass into the possession of Troekouroff?”
“Into the possession of Kirila Petrovitch! The Lord save and preserve
us! His own people fare badly enough, and if he got possession of
strangers, he would strip off, not only their skin, but their flesh also.
No, may God grant long life to Andrei Gavrilovitch; and if God should
take him to Himself, we want nobody but you, our benefactor. Do
not give us up, and we will stand by you.”
With these words, Anton flourished his whip, shook the reins, and
the horses broke into a brisk trot.
Touched by the devotion of the old coachman, Doubrovsky became
silent and gave himself up to his own reflections. More than an hour
passed; suddenly Grisha roused him by exclaiming: “There is
Pokrovskoe!” Doubrovsky raised his head. They were just then
driving along the bank of a broad lake, out of which flowed a small
stream winding among the hills. On one of these, above a thick
green wood, rose the green roof and belvedere of a huge stone
house, together with a five-domed church with an ancient belfry;
round about were scattered the village huts with their gardens and
wells. Doubrovsky recognized these places; he remembered that on
that very hill he had played with little Masha Troekouroff, who was
two years younger than he, and who even then gave promise of
being very beautiful. He wanted to make inquiries of Anton about
her, but a certain bashfulness restrained him.
On approaching the castle, he perceived a white dress flitting among
the trees in the garden. At that moment Anton whipped the horses,
and impelled by that vanity, common to village coachmen as to
drivers in general, he drove at full speed over the bridge and past
the garden. On emerging from the village, they ascended the hill,
and Vladimir perceived the little wood of birch trees, and to the left,
in an open place, a small grey house with a red roof. His heart
began to beat—before him was Kistenevka, the humble abode of his
father.
About ten minutes afterwards he drove into the courtyard He looked
around him with indescribable emotion: twelve years had elapsed
since he last saw ’his native place. The little birches, which had just
then been planted near the wooden fence, had now become tall
trees with long branches. The courtyard, formerly ornamented with
three regular flower-beds, between which ran a broad path carefully
swept, had been converted into a meadow, in which was grazing a
tethered horse. The dogs began to bark, but recognizing Anton, they
became silent and commenced wagging their shaggy tails. The
servants came rushing out of the house and surrounded the young
master with loud manifestations of joy. It was with difficulty that he
was able to make his way through the enthusiastic crowd. He ran up
the well-worn steps; in the vestibule he was met by Egorovna, who
tearfully embraced him.
“How do you do, how do you do, nurse?” he repeated, pressing the
good old woman to his heart. “And my father? Where is he? How is
he?”
At that moment a tall old man, pale and thin, in a dressing-gown
and cap, entered the room, dragging one foot after the other with
difficulty.
“Where is Volodka?” said he in a weak voice, and Vladimir embraced
his father with affectionate emotion.
The joy proved too much for the sick man; he grew weak, his legs
gave way beneath him, and he would have fallen, if his son had not
held him up.
“Why did you get out of bed?” said Egorovna to him. “He cannot
stand upon his feet, and yet he wants to do the same as other
people.”
The old man was carried back to his bedroom. He tried to converse
with his son, but he could not collect his thoughts, and his words
had no connection with each other. He became silent and fell into a
kind of somnolence. Vladimir was struck by his condition. He
installed himself in the bedroom and requested to be left alone with
his father. The household obeyed, and then all turned towards
Grisha and led him away to the servants’ hall, where they gave him
a hearty welcome according to the rustic custom, the while they
wearied him with questions and compliments.

[1] Diminutive of Gregory.

CHAPTER IV.

A few days after his arrival, young Doubrovsky wished to turn his
attention to business, but his father was not in a condition to give

You might also like