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

Java 17 for Absolute Beginners 2nd Edition Iuliana Cosmina download

Java 17 for Absolute Beginners, 2nd Edition by Iuliana Cosmina is a comprehensive guide aimed at teaching the fundamentals of Java programming to newcomers. The book covers various topics including Java history, syntax, data types, operators, and application development, while providing practical examples and exercises. It also includes supplementary materials available on GitHub to aid in the learning process.

Uploaded by

sevnurlijane
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
0% found this document useful (0 votes)
30 views

Java 17 for Absolute Beginners 2nd Edition Iuliana Cosmina download

Java 17 for Absolute Beginners, 2nd Edition by Iuliana Cosmina is a comprehensive guide aimed at teaching the fundamentals of Java programming to newcomers. The book covers various topics including Java history, syntax, data types, operators, and application development, while providing practical examples and exercises. It also includes supplementary materials available on GitHub to aid in the learning process.

Uploaded by

sevnurlijane
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/ 42

Java 17 for Absolute Beginners 2nd Edition

Iuliana Cosmina pdf download

https://ebookmeta.com/product/java-17-for-absolute-beginners-2nd-
edition-iuliana-cosmina-2/

Download more ebook from https://ebookmeta.com


Iuliana Cosmina

Java 17 for Absolute Beginners


Learn the Fundamentals of Java Programming
2nd ed.
Iuliana Cosmina
Edinburgh, UK

ISBN 978-1-4842-7079-0 e-ISBN 978-1-4842-7080-6


https://doi.org/10.1007/978-1-4842-7080-6

© Iuliana Cosmina 2022

This work is subject to copyright. All rights are reserved by the


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

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 first teacher, Moţa Dumitra.
You’ve instilled in me the hunger to learn.
Thank you!
Any source code or other supplementary material referenced by the
author in this book is available to readers on GitHub. For more detailed
information, please visit http://​www.​apress.​com/​source-code.
Any source code or other supplementary material referenced by the
author in this book is available to readers on GitHub via the book’s
product page, located at www.apress.com/9781484270790. For
more detailed information, please visit
http://www.apress.com/source-code.
Acknowledgments
Writing books for beginners is tricky, because as an experienced
developer, it might be difficult to find the right examples and explain
them in such a way that even a nontechnical person would easily
understand them. That is why I am profoundly grateful to the great
people at Apress who have been with me for the full journey of writing
this book for all the support and advice they provided to keep this book
at beginner level. A special thank you to the tech reviewer of this book,
Manuel Jordan; his recommendations and corrections were crucial for
the final form of the book.
Apress has published many of the books that I have read and used
to improve myself professionally. It is a great honor to publish my
seventh book with Apress, and it gives me enormous satisfaction to be
able to contribute to the making of a new generation of Java developers.
A special thank you to my Cloudsoft team, for being so supportive
with my passion for writing technical books. Thank you all for being
supportive and making sure I still had some fun while writing this book.
You have no idea how dear you are to me.
A very grateful thank you to Vesa Kauranen, Ivan Duka, Sü leyman
Onur Otlu, and all developers who have identified bugs in the text and
the code and helped me make this edition of the book better than the
previous one.
And a very special thank you in advance to all the passionate Java
developers who will find mistakes in the book and be so kind to write
me about them, so that I can provide an erratum and make this book
even better.
Finally, I want to thank the Bogza-Vlad family: Monica, Tinel,
Cristina, and Stefan. You are all close to my heart and I miss you often.
Table of Contents
Chapter 1:​An Introduction to Java and Its History
Who This Book Is For
How This Book Is Structured
Conventions
When Java Was Owned By Sun Microsystems
How Is Java Portable?​
Sun Microsystem’s Java Versions
Oracle Takes Over
Java 7
Java 8
Java 9
Java 10
Java 11
Java 12
Java 13
Java 14
Java 15
Java 16
Java 17
Prerequisites
Summary
Chapter 2:​Preparing Your Development Environment
Installing Java
The JAVA_​HOME Environment Variable
JAVA_​HOME on Windows
JAVA_​HOME on macOS
JAVA_​HOME on Linux
Installing Maven
Installing Git
Installing a Java IDE
Summary
Chapter 3:​Getting Your Feet Wet
Core Syntax Parts
Using JShell
Java Fundamental Building Blocks
Packages
Access Modifiers
Modules
How to Determine the Structure of a Java Project
Summary
Chapter 4:​Java Syntax
Base Rules of Writing Java Code
Package Declaration
Import Section
Java Grammar
Java Identifiers and Variables
Java Comments
Java Types
Summary
Java Keywords
Chapter 5:​Data Types
Stack and Heap Memory
Introduction to Java Data Types
Primitive Data Types
Reference Data Types
Java Primitive Types
Date Time API
Collections
Concurrency Specific Types
Summary
Chapter 6:​Operators
The Assignment Operator
Explicit Type Conversion (type) and instanceof
Numerical Operators
Unary Operators
Binary Operators
Relational Operations
Bitwise Operators
Bitwise NOT
Bitwise AND
Bitwise Inclusive OR
Bitwise Exclusive OR
Logical Operators
Shift Operators
The << Shift Left Operator
The >> Signed Shift Right Operator
The >>> Unsigned Shift Right Operator
The Elvis Operator
Summary
Chapter 7:​Controlling the Flow
if-else Statement
switch Statement
Looping Statements
for Statement
while Statement
do-while Statement
Breaking Loops and Skipping Steps
break Statement
continue Statement
return Statement
Controlling the Flow Using try-catch Constructions
Summary
Chapter 8:​The Stream API
Introduction to Streams
Creating Streams
Creating Streams from Collections
Creating Streams from Arrays
Creating Empty Streams
Creating Finite Streams
Streams of Primitives and Streams of Strings
Short Introduction to Optional<T>
How to Use Streams Like a Pro
Terminal Functions: forEach and forEachOrdered
Intermediate Operation: filter and Terminal Operation:
toArray
Intermediate Operation: map, flatMap and Terminal
Operation: collect
Intermediate Operation: sorted and Terminal Operation:
findFirst
Intermediate Operation: distinct() and Terminal
Operation: count()
Intermediate Operation: limit(..) and Terminal
Operations: min(..), max(..)
Terminal Operations: sum() and reduce(..)
Intermediate Operation: peek(..)
Intermediate Operation: skip(..) and Terminal
Operations: findAny(), anyMatch(..), allMatch(..)
and noneMatch(..)
Debugging Stream Code
Summary
Chapter 9:​Debugging, Testing, and Documenting
Debugging
Logging
Logging with System.out.print
Debug Using Assertions
Step-By-Step Debugging
Inspecting Running Application Using Java Tools
Accessing the Java Process API
Testing
Testing Code Location
Documenting
Summary
Chapter 10:​Making Your Application Interactive
Reading Data from the Command Line
Reading User Data Using System.in
Using java.util.Scanner
Using java.io.Console
Build Applications Using Swing
Introducing JavaFX
Internationaliza​tion
Building a Web Application
Java Web Application with an Embedded Server
Java Web Application on a Standalone Server
Summary
Chapter 11:​Working With Files
Java IO and NIO APIs
File Handlers
Path Handlers
Reading Files
Using Scanner to Read Files
Using Files Utility Methods to Read Files
Using Readers to Read Files
Using InputStream to Read Files
Writing Files
Writing Files Using Files Utility Methods
Using Writer to Write Files
Using OutputStream to Write Files
Using NIO to Manage Files
Serialization and Deserialization
Byte Serialization
XML Serialization
JSON Serialization
The Media API
Using JavaFX Image Classes
Summary
Chapter 12:​The Publish-Subscribe Framework
Reactive Programming and the Reactive Manifesto
Using the JDK Reactive Streams API
Reactive Streams Technology Compatibility Kit
Using Project Reactor
Summary
Chapter 13:​Garbage Collection
Garbage Collection Basics
Oracle Hotspot JVM Architecture
How Many Garbage Collectors Are There?​
Working with GC from the Code
Using the finalize() Method
Heap Memory Statistics
Using Cleaner
Preventing GC from Deleting an Object
Using Weak References
Garbage Collections Exceptions and Causes
Summary
Appendices
Appendix A
Modules
Advanced Module Configurations
Appendix B
Index
Other documents randomly have
different content
breeches, and wasted, purple-looking legs, he used to go about the
roofs, looking like a stork, and I used to hear him, as he plied his
brush, breathing heavily and saying: "Woe, woe to us sinners!"
He walked about the roofs as freely as though he were upon the
ground. In spite of his being ill and pale as a corpse, his agility was
extraordinary: he used to paint the domes and cupolas of the
churches without scaffolding, like a young man, with only the help of
a ladder and a rope, and it was rather horrible when standing on a
height far from the earth; he would draw himself up erect, and for
some unknown reason pronounce:
"Lice consume grass, rust consumes iron, and lying the soul!"
Or, thinking about something, would answer his thoughts aloud:
"Anything may happen! Anything may happen!"
When I went home from my work, all the people who were sitting
on benches by the gates, all the shopmen and boys and their
employers, made sneering and spiteful remarks after me, and this
upset me at first and seemed to be simply monstrous.
"Better-than-nothing!" I heard on all sides. "House painter! Yellow
ochre!"
And none behaved so ungraciously to me as those who had only
lately been humble people themselves, and had earned their bread
by hard manual labour. In the streets full of shops I was once
passing an ironmonger's when water was thrown over me as though
by accident, and on one occasion someone darted out with a stick at
me, while a fishmonger, a grey-headed old man, barred my way and
said, looking at me angrily:
"I am not sorry for you, you fool! It's your father I am sorry for."
And my acquaintances were for some reason overcome with
embarrassment when they met me. Some of them looked upon me
as a queer fish and a comic fool; others were sorry for me; others
did not know what attitude to take up to me, and it was difficult to
make them out. One day I met Anyuta Blagovo in a side street near
Great Dvoryansky Street. I was going to work, and was carrying two
long brushes and a pail of paint. Recognizing me Anyuta flushed
crimson.
"Please do not bow to me in the street," she said nervously,
harshly, and in a shaking voice, without offering me her hand, and
tears suddenly gleamed in her eyes. "If to your mind all this is
necessary, so be it . . . so be it, but I beg you not to meet me!"
I no longer lived in Great Dvoryansky Street, but in the suburb
with my old nurse Karpovna, a good-natured but gloomy old woman,
who always foreboded some harm, was afraid of all dreams, and
even in the bees and wasps that flew into her room saw omens of
evil, and the fact that I had become a workman, to her thinking,
boded nothing good.
"Your life is ruined," she would say, mournfully shaking her head,
"ruined."
Her adopted son Prokofy, a huge, uncouth, red-headed fellow of
thirty, with bristling moustaches, a butcher by trade, lived in the little
house with her. When he met me in the passage he would make way
for me in respectful silence, and if he was drunk he would salute me
with all five fingers at once. He used to have supper in the evening,
and through the partition wall of boards I could hear him clear his
throat and sigh as he drank off glass after glass.
"Mamma," he would call in an undertone.
"Well," Karpovna, who was passionately devoted to her adopted
son, would respond: "What is it, sonny?"
"I can show you a testimony of my affection, mamma. All this
earthly life I will cherish you in your declining years in this vale of
tears, and when you die I will bury you at my expense; I have said
it, and you can believe it."
I got up every morning before sunrise, and went to bed early. We
house painters ate a great deal and slept soundly; the only thing
amiss was that my heart used to beat violently at night. I did not
quarrel with my mates. Violent abuse, desperate oaths, and wishes
such as, "Blast your eyes," or "Cholera take you," never ceased all
day, but, nevertheless, we lived on very friendly terms. The other
fellows suspected me of being some sort of religious sectary, and
made good-natured jokes at my expense, saying that even my own
father had disowned me, and thereupon would add that they rarely
went into the temple of God themselves, and that many of them had
not been to confession for ten years. They justified this laxity on
their part by saying that a painter among men was like a jackdaw
among birds.
The men had a good opinion of me, and treated me with respect;
it was evident that my not drinking, not smoking, but leading a
quiet, steady life pleased them very much. It was only an unpleasant
shock to them that I took no hand in stealing oil and did not go with
them to ask for tips from people on whose property we were
working. Stealing oil and paints from those who employed them was
a house painter's custom, and was not regarded as theft, and it was
remarkable that even so upright a man as Radish would always carry
away a little white lead and oil as he went home from work. And
even the most respectable old fellows, who owned the houses in
which they lived in the suburb, were not ashamed to ask for a tip,
and it made me feel vexed and ashamed to see the men go in a
body to congratulate some nonentity on the commencement or the
completion of the job, and thank him with degrading servility when
they had received a few coppers.
With people on whose work they were engaged they behaved like
wily courtiers, and almost every day I was reminded of
Shakespeare's Polonius.
"I fancy it is going to rain," the man whose house was being
painted would say, looking at the sky.
"It is, there is not a doubt it is," the painters would agree.
"I don't think it is a rain-cloud, though. Perhaps it won't rain after
all."
"No, it won't, your honour! I am sure it won't."
But their attitude to their patrons behind their backs was usually
one of irony, and when they saw, for instance, a gentleman sitting in
the verandah reading a newspaper, they would observe:
"He reads the paper, but I daresay he has nothing to eat."
I never went home to see my own people. When I came back
from work I often found waiting for me little notes, brief and
anxious, in which my sister wrote to me about my father; that he
had been particularly preoccupied at dinner and had eaten nothing,
or that he had been giddy and staggering, or that he had locked
himself in his room and had not come out for a long time. Such
items of news troubled me; I could not sleep, and at times even
walked up and down Great Dvoryansky Street at night by our house,
looking in at the dark windows and trying to guess whether
everything was well at home. On Sundays my sister came to see me,
but came in secret, as though it were not to see me but our nurse.
And if she came in to see me she was very pale, with tear-stained
eyes, and she began crying at once.
"Our father will never live through this," she would say. "If
anything should happen to him-God grant it may not-your
conscience will torment you all your life. It's awful, Misail; for our
mother's sake I beseech you: reform your ways."
"My darling sister," I would say, "how can I reform my ways if I
am convinced that I am acting in accordance with my conscience?
Do understand!"
"I know you are acting on your conscience, but perhaps it could
be done differently, somehow, so as not to wound anybody."
"Ah, holy Saints!" the old woman sighed through the door. "Your
life is ruined! There will be trouble, my dears, there will be trouble!"

VI

One Sunday Dr. Blagovo turned up unexpectedly. He was wearing


a military tunic over a silk shirt and high boots of patent leather.
"I have come to see you," he began, shaking my hand heartily like
a student. "I am hearing about you every day, and I have been
meaning to come and have a heart-to-heart talk, as they say. The
boredom in the town is awful, there is not a living soul, no one to
say a word to. It's hot, Holy Mother," he went on, taking off his tunic
and sitting in his silk shirt. "My dear fellow, let me talk to you."
I was dull myself, and had for a long time been craving for the
society of someone not a house painter. I was genuinely glad to see
him.
"I'll begin by saying," he said, sitting down on my bed, "that I
sympathize with you from the bottom of my heart, and deeply
respect the life you are leading. They don't understand you here in
the town, and, indeed, there is no one to understand, seeing that,
as you know, they are all, with very few exceptions, regular
Gogolesque pig faces here. But I saw what you were at once that
time at the picnic. You are a noble soul, an honest, high-minded
man! I respect you, and feel it a great honour to shake hands with
you!" he went on enthusiastically. "To have made such a complete
and violent change of life as you have done, you must have passed
through a complicated spiritual crisis, and to continue this manner of
life now, and to keep up to the high standard of your convictions
continually, must be a strain on your mind and heart from day to
day. Now to begin our talk, tell me, don't you consider that if you
had spent your strength of will, this strained activity, all these
powers on something else, for instance, on gradually becoming a
great scientist, or artist, your life would have been broader and
deeper and would have been more productive?"
We talked, and when we got upon manual labour I expressed this
idea: that what is wanted is that the strong should not enslave the
weak, that the minority should not be a parasite on the majority, nor
a vampire for ever sucking its vital sap; that is, all, without
exception, strong and weak, rich and poor, should take part equally
in the struggle for existence, each one on his own account, and that
there was no better means for equalizing things in that way than
manual labour, in the form of universal service, compulsory for all.
"Then do you think everyone without exception ought to engage
in manual labour?" asked the doctor.
"Yes."
"And don't you think that if everyone, including the best men, the
thinkers and great scientists, taking part in the struggle for
existence, each on his own account, are going to waste their time
breaking stones and painting roofs, may not that threaten a grave
danger to progress?"
"Where is the danger?" I asked. "Why, progress is in deeds of
love, in fulfilling the moral law; if you don't enslave anyone, if you
don't oppress anyone, what further progress do you want?"
"But, excuse me," Blagovo suddenly fired up, rising to his feet.
"But, excuse me! If a snail in its shell busies itself over perfecting its
own personality and muddles about with the moral law, do you call
that progress?"
"Why muddles?" I said, offended. "If you don't force your
neighbour to feed and clothe you, to transport you from place to
place and defend you from your enemies, surely in the midst of a life
entirely resting on slavery, that is progress, isn't it? To my mind it is
the most important progress, and perhaps the only one possible and
necessary for man."
"The limits of universal world progress are in infinity, and to talk of
some 'possible' progress limited by our needs and temporary
theories is, excuse my saying so, positively strange."
"If the limits of progress are in infinity as you say, it follows that
its aims are not definite," I said. "To live without knowing definitely
what you are living for!"
"So be it! But that 'not knowing' is not so dull as your 'knowing.' I
am going up a ladder which is called progress, civilization, culture; I
go on and up without knowing definitely where I am going, but
really it is worth living for the sake of that delightful ladder; while
you know what you are living for, you live for the sake of some
people's not enslaving others, that the artist and the man who rubs
his paints may dine equally well. But you know that's the petty,
bourgeois, kitchen, grey side of life, and surely it is revolting to live
for that alone? If some insects do enslave others, bother them, let
them devour each other! We need not think about them. You know
they will die and decay just the same, however zealously you rescue
them from slavery. We must think of that great millennium which
awaits humanity in the remote future."
Blagovo argued warmly with me, but at the same time one could
see he was troubled by some irrelevant idea.
"I suppose your sister is not coming?" he said, looking at his
watch. "She was at our house yesterday, and said she would be
seeing you to-day. You keep saying slavery, slavery . . ." he went on.
"But you know that is a special question, and all such questions are
solved by humanity gradually."
We began talking of doing things gradually. I said that "the
question of doing good or evil every one settles for himself, without
waiting till humanity settles it by the way of gradual development.
Moreover, this gradual process has more than one aspect. Side by
side with the gradual development of human ideas the gradual
growth of ideas of another order is observed. Serfdom is no more,
but the capitalist system is growing. And in the very heyday of
emancipating ideas, just as in the days of Baty, the majority feeds,
clothes, and defends the minority while remaining hungry,
inadequately clad, and defenceless. Such an order of things can be
made to fit in finely with any tendencies and currents of thought you
like, because the art of enslaving is also gradually being cultivated.
We no longer flog our servants in the stable, but we give to slavery
refined forms, at least, we succeed in finding a justification for it in
each particular case. Ideas are ideas with us, but if now, at the end
of the nineteenth century, it were possible to lay the burden of the
most unpleasant of our physiological functions upon the working
class, we should certainly do so, and afterwards, of course, justify
ourselves by saying that if the best people, the thinkers and great
scientists, were to waste their precious time on these functions,
progress might be menaced with great danger."
But at this point my sister arrived. Seeing the doctor she was
fluttered and troubled, and began saying immediately that it was
time for her to go home to her father.
"Kleopatra Alexyevna," said Blagovo earnestly, pressing both
hands to his heart, "what will happen to your father if you spend half
an hour or so with your brother and me?"
He was frank, and knew how to communicate his liveliness to
others. After a moment's thought, my sister laughed, and all at once
became suddenly gay as she had been at the picnic. We went out
into the country, and lying in the grass went on with our talk, and
looked towards the town where all the windows facing west were
like glittering gold because the sun was setting.
After that, whenever my sister was coming to see me Blagovo
turned up too, and they always greeted each other as though their
meeting in my room was accidental. My sister listened while the
doctor and I argued, and at such times her expression was joyfully
enthusiastic, full of tenderness and curiosity, and it seemed to me
that a new world she had never dreamed of before, and which she
was now striving to fathom, was gradually opening before her eyes.
When the doctor was not there she was quiet and sad, and now if
she sometimes shed tears as she sat on my bed it was for reasons of
which she did not speak.
In August Radish ordered us to be ready to go to the railway-line.
Two days before we were "banished" from the town my father came
to see me. He sat down and in a leisurely way, without looking at
me, wiped his red face, then took out of his pocket our town
Messenger, and deliberately, with emphasis on each word, read out
the news that the son of the branch manager of the State Bank, a
young man of my age, had been appointed head of a Department in
the Exchequer.
"And now look at you," he said, folding up the newspaper, "a
beggar, in rags, good for nothing! Even working-class people and
peasants obtain education in order to become men, while you, a
Poloznev, with ancestors of rank and distinction, aspire to the gutter!
But I have not come here to talk to you; I have washed my hands of
you-" he added in a stifled voice, getting up. "I have come to find
out where your sister is, you worthless fellow. She left home after
dinner, and here it is nearly eight and she is not back. She has taken
to going out frequently without telling me; she is less dutiful-and I
see in it your evil and degrading influence. Where is she?"
In his hand he had the umbrella I knew so well, and I was already
flustered and drew myself up like a schoolboy, expecting my father
to begin hitting me with it, but he noticed my glance at the umbrella
and most likely that restrained him.
"Live as you please!" he said. "I shall not give you my blessing!"
"Holy Saints!" my nurse muttered behind the door. "You poor,
unlucky child! Ah, my heart bodes ill!"
I worked on the railway-line. It rained without stopping all August;
it was damp and cold; they had not carried the corn in the fields,
and on big farms where the wheat had been cut by machines it lay
not in sheaves but in heaps, and I remember how those luckless
heaps of wheat turned blacker every day and the grain was
sprouting in them. It was hard to work; the pouring rain spoiled
everything we managed to do. We were not allowed to live or to
sleep in the railway buildings, and we took refuge in the damp and
filthy mud huts in which the navvies had lived during the summer,
and I could not sleep at night for the cold and the woodlice crawling
on my face and hands. And when we worked near the bridges the
navvies used to come in the evenings in a gang, simply in order to
beat the painters-it was a form of sport to them. They used to beat
us, to steal our brushes. And to annoy us and rouse us to fight they
used to spoil our work; they would, for instance, smear over the
signal boxes with green paint. To complete our troubles, Radish took
to paying us very irregularly. All the painting work on the line was
given out to a contractor; he gave it out to another; and this
subcontractor gave it to Radish after subtracting twenty per cent. for
himself. The job was not a profitable one in itself, and the rain made
it worse; time was wasted; we could not work while Radish was
obliged to pay the fellows by the day. The hungry painters almost
came to beating him, called him a cheat, a blood-sucker, a Judas,
while he, poor fellow, sighed, lifted up his hand to Heaven in despair,
and was continually going to Madame Tcheprakov for money.

VII

Autumn came on, rainy, dark, and muddy. The season of


unemployment set in, and I used to sit at home out of work for
three days at a stretch, or did various little jobs, not in the painting
line. For instance, I wheeled earth, earning about fourpence a day
by it. Dr. Blagovo had gone away to Petersburg. My sister had given
up coming to see me. Radish was laid up at home ill, expecting
death from day to day.
And my mood was autumnal too. Perhaps because, having
become a workman, I saw our town life only from the seamy side, it
was my lot almost every day to make discoveries which reduced me
almost to despair. Those of my fellow-citizens, about whom I had no
opinion before, or who had externally appeared perfectly decent,
turned out now to be base, cruel people, capable of any dirty action.
We common people were deceived, cheated, and kept waiting for
hours together in the cold entry or the kitchen; we were insulted
and treated with the utmost rudeness. In the autumn I papered the
reading-room and two other rooms at the club; I was paid a penny
three-farthings the piece, but had to sign a receipt at the rate of
twopence halfpenny, and when I refused to do so, a gentleman of
benevolent appearance in gold-rimmed spectacles, who must have
been one of the club committee, said to me:
"If you say much more, you blackguard, I'll pound your face into a
jelly!"
And when the flunkey whispered to him what I was, the son of
Poloznev the architect, he became embarrassed, turned crimson, but
immediately recovered himself and said: "Devil take him."
In the shops they palmed off on us workmen putrid meat, musty
flour, and tea that had been used and dried again; the police hustled
us in church, the assistants and nurses in the hospital plundered us,
and if we were too poor to give them a bribe they revenged
themselves by bringing us food in dirty vessels. In the post-office the
pettiest official considered he had a right to treat us like animals,
and to shout with coarse insolence: "You wait!" "Where are you
shoving to?" Even the housedogs were unfriendly to us, and fell
upon us with peculiar viciousness. But the thing that struck me most
of all in my new position was the complete lack of justice, what is
defined by the peasants in the words: "They have forgotten God."
Rarely did a day pass without swindling. We were swindled by the
merchants who sold us oil, by the contractors and the workmen and
the people who employed us. I need not say that there could never
be a question of our rights, and we always had to ask for the money
we earned as though it were a charity, and to stand waiting for it at
the back door, cap in hand.
I was papering a room at the club next to the reading-room; in
the evening, when I was just getting ready to go, the daughter of
Dolzhikov, the engineer, walked into the room with a bundle of books
under her arm.
I bowed to her.
"Oh, how do you do!" she said, recognizing me at once, and
holding out her hand. "I'm very glad to see you."
She smiled and looked with curiosity and wonder at my smock, my
pail of paste, the paper stretched on the floor; I was embarrassed,
and she, too, felt awkward.
"You must excuse my looking at you like this," she said. "I have
been told so much about you. Especially by Dr. Blagovo; he is simply
in love with you. And I have made the acquaintance of your sister
too; a sweet, dear girl, but I can never persuade her that there is
nothing awful about your adopting the simple life. On the contrary,
you have become the most interesting man in the town."
She looked again at the pail of paste and the wallpaper, and went
on:
"I asked Dr. Blagovo to make me better acquainted with you, but
apparently he forgot, or had not time. Anyway, we are acquainted all
the same, and if you would come and see me quite simply I should
be extremely indebted to you. I so long to have a talk. I am a simple
person," she added, holding out her hand to me, "and I hope that
you will feel no constraint with me. My father is not here, he is in
Petersburg."
She went off into the reading-room, rustling her skirts, while I
went home, and for a long time could not get to sleep.
That cheerless autumn some kind soul, evidently wishing to
alleviate my existence, sent me from time to time tea and lemons, or
biscuits, or roast game. Karpovna told me that they were always
brought by a soldier, and from whom they came she did not know;
and the soldier used to enquire whether I was well, and whether I
dined every day, and whether I had warm clothing. When the frosts
began I was presented in the same way in my absence with a soft
knitted scarf brought by the soldier. There was a faint elusive smell
of scent about it, and I guessed who my good fairy was. The scarf
smelt of lilies-of-the-valley, the favourite scent of Anyuta Blagovo.
Towards winter there was more work and it was more cheerful.
Radish recovered, and we worked together in the cemetery church,
where we were putting the ground-work on the ikon-stand before
gilding. It was a clean, quiet job, and, as our fellows used to say,
profitable. One could get through a lot of work in a day, and the
time passed quickly, imperceptibly. There was no swearing, no
laughter, no loud talk. The place itself compelled one to quietness
and decent behaviour, and disposed one to quiet, serious thoughts.
Absorbed in our work we stood or sat motionless like statues; there
was a deathly silence in keeping with the cemetery, so that if a tool
fell, or a flame spluttered in the lamp, the noise of such sounds rang
out abrupt and resonant, and made us look round. After a long
silence we would hear a buzzing like the swarming of bees: it was
the requiem of a baby being chanted slowly in subdued voices in the
porch; or an artist, painting a dove with stars round it on a cupola
would begin softly whistling, and recollecting himself with a start
would at once relapse into silence; or Radish, answering his
thoughts, would say with a sigh: "Anything is possible! Anything is
possible!" or a slow disconsolate bell would begin ringing over our
heads, and the painters would observe that it must be for the
funeral of some wealthy person. . . .
My days I spent in this stillness in the twilight of the church, and
in the long evenings I played billiards or went to the theatre in the
gallery wearing the new trousers I had bought out of my own
earnings. Concerts and performances had already begun at the
Azhogins'; Radish used to paint the scenes alone now. He used to
tell me the plot of the plays and describe the tableaux vivants which
he witnessed. I listened to him with envy. I felt greatly drawn to the
rehearsals, but I could not bring myself to go to the Azhogins'.
A week before Christmas Dr. Blagovo arrived. And again we
argued and played billiards in the evenings. When he played he used
to take off his coat and unbutton his shirt over his chest, and for
some reason tried altogether to assume the air of a desperate rake.
He did not drink much, but made a great uproar about it, and had a
special faculty for getting through twenty roubles in an evening at
such a poor cheap tavern as the Volga.
My sister began coming to see me again; they both expressed
surprise every time on seeing each other, but from her joyful, guilty
face it was evident that these meetings were not accidental. One
evening, when we were playing billiards, the doctor said to me:
"I say, why don't you go and see Miss Dolzhikov? You don't know
Mariya Viktorovna; she is a clever creature, a charmer, a simple,
good-natured soul."
I described how her father had received me in the spring.
"Nonsense!" laughed the doctor, "the engineer's one thing and
she's another. Really, my dear fellow, you mustn't be nasty to her;
go and see her sometimes. For instance, let's go and see her
tomorrow evening. What do you say?"
He persuaded me. The next evening I put on my new serge
trousers, and in some agitation I set off to Miss Dolzhikov's. The
footman did not seem so haughty and terrible, nor the furniture so
gorgeous, as on that morning when I had come to ask a favour.
Mariya Viktorovna was expecting me, and she received me like an
old acquaintance, shaking hands with me in a friendly way. She was
wearing a grey cloth dress with full sleeves, and had her hair done in
the style which we used to call "dogs' ears," when it came into
fashion in the town a year before. The hair was combed down over
the ears, and this made Mariya Viktorovna's face look broader, and
she seemed to me this time very much like her father, whose face
was broad and red, with something in its expression like a sledge-
driver. She was handsome and elegant, but not youthful looking; she
looked thirty, though in reality she was not more than twenty-five.
"Dear Doctor, how grateful I am to you," she said, making me sit
down. "If it hadn't been for him you wouldn't have come to see me.
I am bored to death! My father has gone away and left me alone,
and I don't know what to do with myself in this town."
Then she began asking me where I was working now, how much I
earned, where I lived.
"Do you spend on yourself nothing but what you earn?" she
asked.
"No."
"Happy man!" she sighed. "All the evil in life, it seems to me,
comes from idleness, boredom, and spiritual emptiness, and all this
is inevitable when one is accustomed to living at other people's
expense. Don't think I am showing off, I tell you truthfully: it is not
interesting or pleasant to be rich. 'Make to yourselves friends of the
mammon of unrighteousness' is said, because there is not and
cannot be a mammon that's righteous."
She looked round at the furniture with a grave, cold expression, as
though she wanted to count it over, and went on:
"Comfort and luxury have a magical power; little by little they
draw into their clutches even strong-willed people. At one time
father and I lived simply, not in a rich style, but now you see how! It
is something monstrous," she said, shrugging her shoulders; "we
spend up to twenty thousand a year! In the provinces!"
"One comes to look at comfort and luxury as the invariable
privilege of capital and education," I said, "and it seems to me that
the comforts of life may be combined with any sort of labour, even
the hardest and dirtiest. Your father is rich, and yet he says himself
that it has been his lot to be a mechanic and an oiler."
She smiled and shook her head doubtfully: "My father sometimes
eats bread dipped in kvass," she said. "It's a fancy, a whim!"
At that moment there was a ring and she got up.
"The rich and well-educated ought to work like everyone else,"
she said, "and if there is comfort it ought to be equal for all. There
ought not to be any privileges. But that's enough philosophizing. Tell
me something amusing. Tell me about the painters. What are they
like? Funny?"
The doctor came in; I began telling them about the painters, but,
being unaccustomed to talking, I was constrained, and described
them like an ethnologist, gravely and tediously. The doctor, too, told
us some anecdotes of working men: he staggered about, shed tears,
dropped on his knees, and, even, mimicking a drunkard, lay on the
floor; it was as good as a play, and Mariya Viktorovna laughed till
she cried as she looked at him. Then he played on the piano and
sang in his thin, pleasant tenor, while Mariya Viktorovna stood by
and picked out what he was to sing, and corrected him when he
made a mistake.
"I've heard that you sing, too?" I enquired.
"Sing, too!" cried the doctor in horror. "She sings exquisitely, a
perfect artist, and you talk of her 'singing too'! What an idea!"
"I did study in earnest at one time," she said, answering my
question, "but now I have given it up."
Sitting on a low stool she told us of her life in Petersburg, and
mimicked some celebrated singers, imitating their voice and manner
of singing. She made a sketch of the doctor in her album, then of
me; she did not draw well, but both the portraits were like us. She
laughed, and was full of mischief and charming grimaces, and this
suited her better than talking about the mammon of
unrighteousness, and it seemed to me that she had been talking just
before about wealth and luxury, not in earnest, but in imitation of
someone. She was a superb comic actress. I mentally compared her
with our young ladies, and even the handsome, dignified Anyuta
Blagovo could not stand comparison with her; the difference was
immense, like the difference between a beautiful, cultivated rose and
a wild briar.
We had supper together, the three of us. The doctor and Mariya
Viktorovna drank red wine, champagne, and coffee with brandy in it;
they clinked glasses and drank to friendship, to enlightenment, to
progress, to liberty, and they did not get drunk but only flushed, and
were continually, for no reason, laughing till they cried. So as not to
be tiresome I drank claret too.
"Talented, richly endowed natures," said Miss Dolzhikov, "know
how to live, and go their own way; mediocre people, like myself for
instance, know nothing and can do nothing of themselves; there is
nothing left for them but to discern some deep social movement,
and to float where they are carried by it."
"How can one discern what doesn't exist?" asked the doctor.
"We think so because we don't see it."
"Is that so? The social movements are the invention of the new
literature. There are none among us."
An argument began.
"There are no deep social movements among us and never have
been," the doctor declared loudly. "There is no end to what the new
literature has invented! It has invented intellectual workers in the
country, and you may search through all our villages and find at the
most some lout in a reefer jacket or a black frock-coat who will make
four mistakes in spelling a word of three letters. Cultured life has not
yet begun among us. There's the same savagery, the same uniform
boorishness, the same triviality, as five hundred years ago.
Movements, currents there have been, but it has all been petty,
paltry, bent upon vulgar and mercenary interests-and one cannot
see anything important in them. If you think you have discerned a
deep social movement, and in following it you devote yourself to
tasks in the modern taste, such as the emancipation of insects from
slavery or abstinence from beef rissoles, I congratulate you, Madam.
We must study, and study, and study and we must wait a bit with
our deep social movements; we are not mature enough for them
yet; and to tell the truth, we don't know anything about them."
"You don't know anything about them, but I do," said Mariya
Viktorovna. "Goodness, how tiresome you are to-day!"
"Our duty is to study and to study, to try to accumulate as much
knowledge as possible, for genuine social movements arise where
there is knowledge; and the happiness of mankind in the future lies
only in knowledge. I drink to science!"
"There is no doubt about one thing: one must organize one's life
somehow differently," said Mariya Viktorovna, after a moment's
silence and thought. "Life, such as it has been hitherto, is not worth
having. Don't let us talk about it."
As we came away from her the cathedral clock struck two.
"Did you like her?" asked the doctor; "she's nice, isn't she?"
On Christmas day we dined with Mariya Viktorovna, and all
through the holidays we went to see her almost every day. There
was never anyone there but ourselves, and she was right when she
said that she had no friends in the town but the doctor and me. We
spent our time for the most part in conversation; sometimes the
doctor brought some book or magazine and read aloud to us. In
reality he was the first well-educated man I had met in my life: I
cannot judge whether he knew a great deal, but he always displayed
his knowledge as though he wanted other people to share it. When
he talked about anything relating to medicine he was not like any
one of the doctors in our town, but made a fresh, peculiar
impression upon me, and I fancied that if he liked he might have
become a real man of science. And he was perhaps the only person
who had a real influence upon me at that time. Seeing him, and
reading the books he gave me, I began little by little to feel a thirst
for the knowledge which would have given significance to my
cheerless labour. It seemed strange to me, for instance, that I had
not known till then that the whole world was made up of sixty
elements, I had not known what oil was, what paints were, and that
I could have got on without knowing these things. My acquaintance
with the doctor elevated me morally too. I was continually arguing
with him and, though I usually remained of my own opinion, yet,
thanks to him, I began to perceive that everything was not clear to
me, and I began trying to work out as far as I could definite
convictions in myself, that the dictates of conscience might be
definite, and that there might be nothing vague in my mind. Yet,
though he was the most cultivated and best man in the town, he
was nevertheless far from perfection. In his manners, in his habit of
turning every conversation into an argument, in his pleasant tenor,
even in his friendliness, there was something coarse, like a divinity
student, and when he took off his coat and sat in his silk shirt, or
flung a tip to a waiter in the restaurant, I always fancied that culture
might be all very well, but the Tatar was fermenting in him still.
At Epiphany he went back to Petersburg. He went off in the
morning, and after dinner my sister came in. Without taking off her
fur coat and her cap she sat down in silence, very pale, and kept her
eyes fixed on the same spot. She was chilled by the frost and one
could see that she was upset by it.
"You must have caught cold," I said.
Her eyes filled with tears; she got up and went out to Karpovna
without saying a word to me, as though I had hurt her feelings. And
a little later I heard her saying, in a tone of bitter reproach:
"Nurse, what have I been living for till now? What? Tell me,
haven't I wasted my youth? All the best years of my life to know
nothing but keeping accounts, pouring out tea, counting the
halfpence, entertaining visitors, and thinking there was nothing
better in the world! Nurse, do understand, I have the cravings of a
human being, and I want to live, and they have turned me into
something like a housekeeper. It's horrible, horrible!"
She flung her keys towards the door, and they fell with a jingle
into my room. They were the keys of the sideboard, of the kitchen
cupboard, of the cellar, and of the tea-caddy, the keys which my
mother used to carry.
"Oh, merciful heavens!" cried the old woman in horror. "Holy
Saints above!"
Before going home my sister came into my room to pick up the
keys, and said:
"You must forgive me. Something queer has happened to me
lately."

VIII

On returning home late one evening from Mariya Viktorovna's I


found waiting in my room a young police inspector in a new uniform;
he was sitting at my table, looking through my books.
"At last," he said, getting up and stretching himself. "This is the
third time I have been to you. The Governor commands you to
present yourself before him at nine o'clock in the morning. Without
fail."
He took from me a signed statement that I would act upon his
Excellency's command, and went away. This late visit of the police
inspector and unexpected invitation to the Governor's had an
overwhelmingly oppressive effect upon me. From my earliest
childhood I have felt terror-stricken in the presence of gendarmes,
policemen, and law court officials, and now I was tormented by
uneasiness, as though I were really guilty in some way. And I could
not get to sleep. My nurse and Prokofy were also upset and could
not sleep. My nurse had earache too; she moaned, and several times
began crying with pain. Hearing that I was awake, Prokofy came into
my room with a lamp and sat down at the table.
"You ought to have a drink of pepper cordial," he said, after a
moment's thought. "If one does have a drink in this vale of tears it
does no harm. And if Mamma were to pour a little pepper cordial in
her ear it would do her a lot of good."
Between two and three he was going to the slaughter-house for
the meat. I knew I should not sleep till morning now, and to get
through the time till nine o'clock I went with him. We walked with a
lantern, while his boy Nikolka, aged thirteen, with blue patches on
his cheeks from frostbites, a regular young brigand to judge by his
expression, drove after us in the sledge, urging on the horse in a
husky voice.
"I suppose they will punish you at the Governor's," Prokofy said to
me on the way. "There are rules of the trade for governors, and
rules for the higher clergy, and rules for the officers, and rules for
the doctors, and every class has its rules. But you haven't kept to
your rules, and you can't be allowed."
The slaughter-house was behind the cemetery, and till then I had
only seen it in the distance. It consisted of three gloomy barns,
surrounded by a grey fence, and when the wind blew from that
quarter on hot days in summer, it brought a stifling stench from
them. Now going into the yard in the dark I did not see the barns; I
kept coming across horses and sledges, some empty, some loaded
up with meat. Men were walking about with lanterns, swearing in a
disgusting way. Prokofy and Nikolka swore just as revoltingly, and
the air was in a continual uproar with swearing, coughing, and the
neighing of horses.
There was a smell of dead bodies and of dung. It was thawing,
the snow was changing into mud; and in the darkness it seemed to
me that I was walking through pools of blood.
Having piled up the sledges full of meat we set off to the butcher's
shop in the market. It began to get light. Cooks with baskets and
elderly ladies in mantles came along one after another. Prokofy, with
a chopper in his hand, in a white apron spattered with blood, swore
fearful oaths, crossed himself at the church, shouted aloud for the
whole market to hear, that he was giving away the meat at cost
price and even at a loss to himself. He gave short weight and short
change, the cooks saw that, but, deafened by his shouts, did not
protest, and only called him a hangman. Brandishing and bringing
down his terrible chopper he threw himself into picturesque
attitudes, and each time uttered the sound "Geck" with a ferocious
expression, and I was afraid he really would chop off somebody's
head or hand.
I spent all the morning in the butcher's shop, and when at last I
went to the Governor's, my overcoat smelt of meat and blood. My
state of mind was as though I were being sent spear in hand to
meet a bear. I remember the tall staircase with a striped carpet on
it, and the young official, with shiny buttons, who mutely motioned
me to the door with both hands, and ran to announce me. I went
into a hall luxuriously but frigidly and tastelessly furnished, and the
high, narrow mirrors in the spaces between the walls, and the bright
yellow window curtains, struck the eye particularly unpleasantly. One
could see that the governors were changed, but the furniture
remained the same. Again the young official motioned me with both
hands to the door, and I went up to a big green table at which a
military general, with the Order of Vladimir on his breast, was
standing.
"Mr. Poloznev, I have asked you to come," he began, holding a
letter in his hand, and opening his mouth like a round "o," "I have
asked you to come here to inform you of this. Your highly respected
father has appealed by letter and by word of mouth to the Marshal
of the Nobility begging him to summon you, and to lay before you
the inconsistency of your behaviour with the rank of the nobility to
which you have the honour to belong. His Excellency Alexandr
Pavlovitch, justly supposing that your conduct might serve as a bad
example, and considering that mere persuasion on his part would
not be sufficient, but that official intervention in earnest was
essential, presents me here in this letter with his views in regard to
you, which I share."
He said this, quietly, respectfully, standing erect, as though I were
his superior officer and looking at me with no trace of severity. His
face looked worn and wizened, and was all wrinkles; there were
bags under his eyes; his hair was dyed; and it was impossible to tell
from his appearance how old he was-forty or sixty.
"I trust," he went on, "that you appreciate the delicacy of our
honoured Alexandr Pavlovitch, who has addressed himself to me not
officially, but privately. I, too, have asked you to come here
unofficially, and I am speaking to you, not as a Governor, but from a
sincere regard for your father. And so I beg you either to alter your
line of conduct and return to duties in keeping with your rank, or to
avoid setting a bad example, remove to another district where you
are not known, and where you can follow any occupation you
please. In the other case, I shall be forced to take extreme
measures."
He stood for half a minute in silence, looking at me with his mouth
open.
"Are you a vegetarian?" he asked.
"No, your Excellency, I eat meat."
He sat down and drew some papers towards him. I bowed and
went out.
It was not worth while now to go to work before dinner. I went
home to sleep, but could not sleep from an unpleasant, sickly
feeling, induced by the slaughter house and my conversation with
the Governor, and when the evening came I went, gloomy and out
of sorts, to Mariya Viktorovna. I told her how I had been at the
Governor's, while she stared at me in perplexity as though she did
not believe it, then suddenly began laughing gaily, loudly,
irrepressibly, as only good-natured laughter-loving people can.
"If only one could tell that in Petersburg!" she brought out, almost
falling over with laughter, and propping herself against the table. "If
one could tell that in Petersburg!"

IX

Now we used to see each other often, sometimes twice a day. She
used to come to the cemetery almost every day after dinner, and
read the epitaphs on the crosses and tombstones while she waited
for me. Sometimes she would come into the church, and, standing
by me, would look on while I worked. The stillness, the naïve work
of the painters and gilders, Radish's sage reflections, and the fact
that I did not differ externally from the other workmen, and worked
just as they did in my waistcoat with no socks on, and that I was
addressed familiarly by them-all this was new to her and touched
her. One day a workman, who was painting a dove on the ceiling,
called out to me in her presence:
"Misail, hand me up the white paint."
I took him the white paint, and afterwards, when I let myself
down by the frail scaffolding, she looked at me, touched to tears and
smiling.
"What a dear you are!" she said.
I remembered from my childhood how a green parrot, belonging
to one of the rich men of the town, had escaped from its cage, and
how for quite a month afterwards the beautiful bird had haunted the
town, flying from garden to garden, homeless and solitary. Mariya
Viktorovna reminded me of that bird.
"There is positively nowhere for me to go now but the cemetery,"
she said to me with a laugh. "The town has become disgustingly
dull. At the Azhogins' they are still reciting, singing, lisping. I have
grown to detest them of late; your sister is an unsociable creature;
Mademoiselle Blagovo hates me for some reason. I don't care for the
theatre. Tell me where am I to go?"
When I went to see her I smelt of paint and turpentine, and my
hands were stained-and she liked that; she wanted me to come to
her in my ordinary working clothes; but in her drawing-room those
clothes made me feel awkward. I felt embarrassed, as though I were
in uniform, so I always put on my new serge trousers when I went
to her. And she did not like that.
"You must own you are not quite at home in your new character,"
she said to me one day. "Your workman's dress does not feel natural
to you; you are awkward in it. Tell me, isn't that because you haven't
a firm conviction, and are not satisfied? The very kind of work you
have chosen-your painting-surely it does not satisfy you, does it?"
she asked, laughing. "I know paint makes things look nicer and last
longer, but those things belong to rich people who live in towns, and
after all they are luxuries. Besides, you have often said yourself that
everybody ought to get his bread by the work of his own hands, yet
you get money and not bread. Why shouldn't you keep to the literal
sense of your words? You ought to be getting bread, that is, you
ought to be ploughing, sowing, reaping, threshing, or doing
something which has a direct connection with agriculture, for
instance, looking after cows, digging, building huts of logs. . . ."
She opened a pretty cupboard that stood near her writing-table,
and said:
"I am saying all this to you because I want to let you into my
secret. Voilà! This is my agricultural library. Here I have fields,
kitchen garden and orchard, and cattleyard and beehives. I read
them greedily, and have already learnt all the theory to the tiniest
detail. My dream, my darling wish, is to go to our Dubetchnya as
soon as March is here. It's marvellous there, exquisite, isn't it? The
first year I shall have a look round and get into things, and the year

You might also like