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

100 Solutions In Java A Handson Introduction To Programming In Java Dhruti Shah download

The document is a promotional and informational piece about the book '100 Solutions in Java: A Hands-On Introduction to Programming in Java' by Dhruti Shah, which aims to teach beginners the fundamentals of Java programming. It covers various topics, including object-oriented programming, Java constructs, application components, and advanced features introduced in recent Java versions. Additionally, it provides links to download the book and related resources, as well as information about the author and publisher.

Uploaded by

ninvatioman
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)
7 views

100 Solutions In Java A Handson Introduction To Programming In Java Dhruti Shah download

The document is a promotional and informational piece about the book '100 Solutions in Java: A Hands-On Introduction to Programming in Java' by Dhruti Shah, which aims to teach beginners the fundamentals of Java programming. It covers various topics, including object-oriented programming, Java constructs, application components, and advanced features introduced in recent Java versions. Additionally, it provides links to download the book and related resources, as well as information about the author and publisher.

Uploaded by

ninvatioman
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/ 76

100 Solutions In Java A Handson Introduction To

Programming In Java Dhruti Shah download

https://ebookbell.com/product/100-solutions-in-java-a-handson-
introduction-to-programming-in-java-dhruti-shah-34692402

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

100 Solutions In Java 2nd Edition 2nd Edition Dhruti Shah

https://ebookbell.com/product/100-solutions-in-java-2nd-edition-2nd-
edition-dhruti-shah-53640426

Plugin Css 100 Power Solutions 1st Edition Robin Nixon

https://ebookbell.com/product/plugin-css-100-power-solutions-1st-
edition-robin-nixon-2260648

Plugin Javascript 100 Power Solutions Robin Nixon

https://ebookbell.com/product/plugin-javascript-100-power-solutions-
robin-nixon-4702434

Plugin Php 100 Power Solutions Simple Solutions To Practical Php


Problems Robin Nixon

https://ebookbell.com/product/plugin-php-100-power-solutions-simple-
solutions-to-practical-php-problems-robin-nixon-5473552
Sound Forge Pro 100 In Simple Steps Kogent Learning Solutions Inc

https://ebookbell.com/product/sound-forge-pro-100-in-simple-steps-
kogent-learning-solutions-inc-231815852

The Lowfodmap Ibs Solution Plan And Cookbook Heal Your Ibs With More
Than 100 Lowfodmap Recipes That Prep In 30 Minutes Or Less Rachel
Pauls

https://ebookbell.com/product/the-lowfodmap-ibs-solution-plan-and-
cookbook-heal-your-ibs-with-more-than-100-lowfodmap-recipes-that-prep-
in-30-minutes-or-less-rachel-pauls-34949568

The Lowfodmap Ibs Solution Plan And Cookbook Heal Your Ibs With More
Than 100 Lowfodmap Recipes That Prep In 30 Minutes Or Less Rachel
Pauls

https://ebookbell.com/product/the-lowfodmap-ibs-solution-plan-and-
cookbook-heal-your-ibs-with-more-than-100-lowfodmap-recipes-that-prep-
in-30-minutes-or-less-rachel-pauls-55012902

Vocabulary In A Snap 100 Lessons For Secondary Instruction Teaching


Vocabulary To Middle And High School Students With Quick And Easy
Vocabulary Exercises Angela B Peery

https://ebookbell.com/product/vocabulary-in-a-snap-100-lessons-for-
secondary-instruction-teaching-vocabulary-to-middle-and-high-school-
students-with-quick-and-easy-vocabulary-exercises-angela-b-
peery-46311712

Vocabulary In A Snap 100 Lessons For Elementary Instruction 1st


Edition Angela B Peery

https://ebookbell.com/product/vocabulary-in-a-snap-100-lessons-for-
elementary-instruction-1st-edition-angela-b-peery-51616236
100+
Solutions in
Java

A Hands-On Introduction to
Programming in Java

Dhruti Shah

www.bpbonline.com
FIRST EDITION 2021

Copyright © BPB Publications, India

ISBN: 978-93-89845-600

All Rights Reserved. No part of this publication may be


reproduced, distributed or transmitted in any form or by any
means or stored in a database or retrieval system, without the
prior written permission of the publisher with the exception to the
program listings which may be entered, stored and executed in a
computer system, but they can not be reproduced by the means
of publication, photocopy, recording, or by any electronic and
mechanical means.

LIMITS OF LIABILITY AND DISCLAIMER OF WARRANTY

The information contained in this book is true to correct and the


best of author’s and publisher’s knowledge. The author has made
every effort to ensure the accuracy of these publications, but
publisher cannot be held responsible for any loss or damage
arising from any information in this book.

All trademarks referred to in the book are acknowledged as


properties of their respective owners but BPB Publications cannot
guarantee the accuracy of this information.

Distributors:
BPB PUBLICATIONS

20, Ansari Road, Darya Ganj

New Delhi-110002

Ph: 23254990/23254991

MICRO MEDIA

Shop No. 5, Mahendra Chambers,

150 DN Rd. Next to Capital Cinema,

V.T. (C.S.T.) Station, MUMBAI-400 001

Ph: 22078296/22078297

DECCAN AGENCIES

4-3-329, Bank Street,

Hyderabad-500195

Ph: 24756967/24756400
BPB BOOK CENTRE

376 Old Lajpat Rai Market,

Delhi-110006

Ph: 23861747

Published by Manish Jain for BPB Publications, 20 Ansari Road,


Darya Ganj, New Delhi-110002 and Printed by him at Repro India
Ltd, Mumbai

www.bpbonline.com
Dedicated to

Swara and Aaria


My nieces who are the light of my life.
About the Author

Dhruti Shah is a multi-skilled, tech-savvy person with over 15 years


of experience as a software trainer, technical writer, and manager
in the IT education industry. She has been working extensively
with Java technology for the last 10 years. She is a Microsoft
Certified Training Specialist who has trained over 2000 candidates
worldwide on more than 10 technologies.

She has been appreciated as a model representative for India for


flawlessly managing two prestigious International projects to set
up and upgrade the Centre of Excellence in Information
Technology in Panama and Costa Rica, Central America (a
collaboration project of the Indian government with the
governments of Panama and Costa Rica).
Acknowledgement

Writing a book on a technology that I have been obsessed with


since I first learned about it years ago was a gratifying experience.
However, it could never have been possible without the support of
all my family members and friends. They always believed in me,
encouraged me to follow my dreams, and gave me the confidence
to face my struggles.

I would like to thank my mother, Mrs. Ushakiran Shah, who is my


friend, philosopher, and guide. Her belief in me and my
aspirations has given me the courage to face challenges head-on
and emerge a victor. Further, I would like to thank all my
colleagues who have given me valuable advice time and again
during the journey of writing this book.

Finally, I would like to extend my gratitude to the entire team of


BPB publications for their support and appreciation of my work.
Preface

Java is a programming language that has been around for decades


and has proved its potential as a versatile programming language.
Over the years, Java has advanced tremendously and has become
one of the most preferred programming languages for the
development of applications ranging from standalone to web
applications as well as mobile apps. It is no longer a simple
client-side language but is more dynamic and supports the
development for application servers, embedded devices, and much
more.

This book is a result of several years of application development


in Java and the experience gained by using different features
introduced with each new version of Java. The goal of this book
is to give a beginner enough knowledge to start application
development in Java. Java is an evolving technology, and this book
attempts to introduce the readers to the basic features of Java
and the new features of Java 8, 9, and 10. It aims to gradually
introduce the reader to a new programming approach called
modular programming.

The book presumes that the reader has a basic idea about
programming and aspires to begin development using Java. It has
been written after extensive research and provides ample examples
and demonstrations to help you take the first step to learn the
new technology. This book will prove to be a great reference for
beginners as well as professionals to begin development in Java.
Over the 12 chapters in this book, you will learn the following:
Chapter introduces the concept of object-oriented programming
and explains how Java has evolved as an object-oriented
programming (OOP) language. It explains the versions and
features of Java and steps to create an application by using JDK 8
and JDK 10.

Chapter discusses the different programming constructs of the


Java language such as comments, variables, data types, and
operators. It also shows you the use of decision-making
constructs, looping constructs, and branch statements.

Chapter introduces Java classes, objects, variables, methods, access


specifiers, and constructors. It explains the implementation of
polymorphism, the creation of packages, and the use of keywords
such as static, final, and this keyword.

Chapter discusses the different types of Arrays and String class. It


also shows you the use of StringBuilder and StringTokenizer
classes, command-line arguments, and wrapper classes.

Chapter discusses the concept of inheritance in Java in depth and


different ways of implementing inheritance by using abstract
classes, nested classes, and so on. It also explains the user
interfaces and lambda expressions.

Chapter describes exception handling with built-in exception classes


and custom exceptions. It further introduces the important classes
of the java.lang and java.util.regex packages.
Chapter introduces the more advanced features such as the
Collections framework with the different utility classes and
interfaces of the java.util package.

Chapter describes the use of generics in Java to create generic


classes, methods, and collections. It also introduces the Time API
that provides better support for date and time.

Chapter describes different types of streams of the java.io package


for file management. Further, it introduces the different classes of
the java.util.zip and java.nio packages.

Chapter explains how to create thread and multithreading to


improve the performance of applications. It also describes how to
connect to databases by using the JDBC API.

Chapter explains the use of design patterns as solutions to


common problems encountered during software development. It
also describes internationalization and localization of an
application.

Chapter describes some prominent new features of Java 8 to 10


such as the Java Platform Module System (JPMS), JShell, JLink
tool, local variable type Inference, and so on.
Downloading the code
bundle and coloured images:

Please follow the link to download the


Code Bundle and the Coloured Images of the book:

https://rebrand.ly/i6o42il

Errata

We take immense pride in our work at BPB Publications and


follow best practices to ensure the accuracy of our content to
provide with an indulging reading experience to our subscribers.
Our readers are our mirrors, and we use their inputs to reflect
and improve upon human errors, if any, that may have occurred
during the publishing processes involved. To let us maintain the
quality and help us reach out to any readers who might be
having difficulties due to any unforeseen errors, please write to us
at :

errata@bpbonline.com

Your support, suggestions and feedbacks are highly appreciated by


the BPB Publications’ Family.
Did you know that BPB offers eBook versions of every book
published, with PDF and ePub files available? You can upgrade to
the eBook version at www.bpbonline.com and as a print book
customer, you are entitled to a discount on the eBook copy. Get
in touch with us at business@bpbonline.com for more details.

At you can also read a collection of free technical articles, sign up


for a range of free newsletters, and receive exclusive discounts
and offers on BPB books and eBooks.
BPB is searching for authors like you

If you're interested in becoming an author for BPB, please visit


www.bpbonline.com and apply today. We have worked with
thousands of developers and tech professionals, just like you, to
help them share their insight with the global tech community. You
can make a general application, apply for a specific hot topic that
we are recruiting an author for, or submit your own idea.

The code bundle for the book is also hosted on GitHub at In


case there's an update to the code, it will be updated on the
existing GitHub repository.

We also have other code bundles from our rich catalog of books
and videos available at Check them out!

PIRACY

If you come across any illegal copies of our works in any form
on the internet, we would be grateful if you would provide us
with the location address or website name. Please contact us at
business@bpbonline.com with a link to the material.

If you are interested in becoming an author


If there is a topic that you have expertise in, and you are
interested in either writing or contributing to a book, please visit

REVIEWS

Please leave a review. Once you have read and used this book,
why not leave a review on the site that you purchased it from?
Potential readers can then see and use your unbiased opinion to
make purchase decisions, we at BPB can understand what you
think about our products, and our authors can see your feedback
on their book. Thank you!

For more information about BPB, please visit


Table of Contents

1. Introduction to Java
Structure
Objectives
1.1 Introduction to object-oriented programming
1.2 Java programming language
1.2.1 Features and advantages of Java
1.3 Java platform and editions
1.4 Java SE platform components
1.5 Java SE version history
1.6 Features of Java SE 9 and Java SE 10
Features of Java SE 10
1.7 Downloading and installing JDK 8 and JDK 10
1.8 Setting up the path for JDK
1.9 Java application development
1.10 Structure of a Java program
1.11 Java code compilation and execution
1.12 Creating and executing a Java program using JDK 8
1.13 Creating and executing a Java program using JDK 10
1.14 Creating and executing a Java 8 project in NetBeans
1.15 Creating and executing a Java 10 project in NetBeans
Summary
Multiple choice questions
Answers
Assignment

2. Java Programming Constructs


Structure
Objectives

2.1 Java comments


Single-line comments
Multi-line comments
Javadoc comments
2.2 Variables in Java
Types of variables
2.3 Data types in Java
Primitive data types
Non-primitive data types
2.4 Type casting
2.5 Literals and escape sequences
Escape sequences
2.6 Constants and enumerations
2.7 Operators in Java
Assignment
Arithmetic
Unary
Conditional/Relational
Logical
Short-circuit behavior
Bitwise
Ternary
2.8 Operator precedence and associativity
2.9 Formatting the output
2.10 Scanner class for input
2.11 Decision-making constructs
‘if ’ statement
Variations of ‘if ’ statement
switch-case statement
Variations of the switch-case statement
2.12 Looping constructs
while loop
Variations of the while loop
do-while statement
for statement
Variations of the for statement
Enhanced ‘for’ loop
2.13 Jump statements
Labeled Jump statements
Summary
Multiple choice questions
Answers
Assignment

3. Java Application Components


Structure
Objectives
3.1 Java classes and objects
3.2 Access specifiers
3.3 Instance variables and methods
3.4 Constructors
3.5 Initializer blocks
3.6 Pass-by-value and pass-by-reference
Passing arguments by value
Passing arguments by reference
3.7 Variable argument method (Varargs)
3.8 Method overloading
3.9 Constructor overloading
3.10 ‘this’ keyword

3.11 ‘final’ keyword


3.12 ‘static’ keyword
3.13 Packages
Summary
Multiple choice questions
Answers
Assignment

4. Java Reference Types


Structure
Objectives
4.1 Java Arrays
4.1.1 Single-dimensional array
4.1.2 Multi-dimensional array
4.1.3 Processing arrays with loops
4.2 String class in Java
4.3 String arrays
4.4 StringBuilder class in Java
4.5 StringTokenizer class in Java
4.6 Passing arguments to the main() method
4.7 Java wrapper classes
Summary
Multiple choice questions
Answers
Assignment

5. Subclasses and Interfaces


Structure
Objectives
5.1 Inheritance in Java

5.1.1 Creating a subclass


5.1.2 Method overriding
5.1.3 Static v/s dynamic binding
Differentiate between the type of reference and type of object
5.2 Abstract methods and classes
5.3 Nested classes
5.4 Interfaces
5.4.1 Implementing multiple interfaces
5.4.2 Default, static, and private methods of interfaces
5.4.3 Issues with default methods
5.5 Java functional interfaces
5.6 Lambda expressions
Lambda expression examples
Method and constructor references
Summary
Multiple choice questions
Answers
Assignment

6. Exceptions and Regular Expressions


Structure
Objectives
6.1 Exceptions in Java
6.1.1 Types of Exceptions
Checked exceptions
Unchecked exceptions
6.2 Exception class in Java
6.3 Exception handling in Java
6.3.1 ‘throw’ and ‘throws’ keywords
6.3.2 Single catch block for multiple exceptions

6.3.3 Best practices for handling exceptions


6.4 Using the try-with-resources statement
close() method
Try with resources exceptions
6.5 Custom exceptions
6.6 Wrapper exceptions
6.7 Assertions in Java
6.8 Classes of the java.lang package
6.8.1 Object class
6.8.2 Class class
6.8.3 Math class
6.8.4 ThreadGroup class
6.8.5 System class
6.8.6 Runtime class
6.9 Regular expressions
6.9.1 Pattern class
6.9.2 Matcher class
6.9.3 PatternSyntaxException
6.10 Character classes
Built-in Character classes
Summary
Multiple choice questions
Answers
Assignment

7. Collections and Stream API


Structure
Objectives
7.1 Collections framework
7.2 Iterable interface

7.3 Collection interface


7.3.1 Traversing collections
7.3.2 Collection factory methods
7.4 List interface
7.4.1 ArrayList class
7.4.2 Vector class
7.4.3 Stack class
7.4.4 LinkedList class
7.5 Queue interface
7.5.1 Deque interface
7.5.2 ArrayDeque class
7.5.3 PriorityQueue class
7.6 Set interface
7.6.1 HashSet class
7.6.2 LinkedHashSet class
7.6.3 SortedSet interface
7.6.4 NavigableSet interface
7.6.5 TreeSet class
7.6.6 ConcurrentSkipListSet
7.7 Map interface
7.7.1 Hashtable class
7.7.2 HashMap class
7.7.3 LinkedHashMap class
7.7.4 TreeMap class
7.7.5 ConcurrentSkipListMap
7.8 Arrays class
7.8 Sorting Collections
Comparable
Comparator

7.9 Java Stream API


7.9.1 Improvements of Stream API in Java 9
Summary
Multiple choice questions
Answers
Assignment

8. Generics and Time API


Structure
Objectives
8.1 Generics
8.2 Generic classes and methods
8.3 Type inference
8.4 Using generic constructors with generic and non-generic
classes
8.5 Using generics with collections
8.6 Using wildcards with generics
8.7 Using generics with exceptions
8.8 Implementing generis with inheritance
8.9 Type erasure
8.10 Time API
LocalDate and LocalTime
8.10.1 Zoned Date-Time API
8.10.2 Chrono Units Enum
8.10.3 Period and Duration
8.10.4 TemporalAdjusters class
8.10.5 Backward compatibility
Summary
Multiple choice questions
Answers

Assignment

9. File Manipulation in Java


Structure
Objectives
9.1 Files and streams
9.1.1 File class
9.1.2 FileDescriptor class
9.2 DataInput and DataOutput interfaces
9.3 FilenameFilter interface
9.4 ByteStreams
9.4.1 InputStream class hierarchy
9.4.1.1 FileInputStream class
9.4.1.2 ByteArrayInputStream class
9.4.1.3 FilterInputStream class
9.4.1.4 BufferedInputStream
9.4.1.5 Serialization
9.4.1.6 ObjectInputStream class
9.4.2 OutputStream class hierarchy
9.4.2.1 FileOutputStream
9.4.2.2 ByteArrayOutputStream class
9.4.2.3 FilterOutputStream class
9.4.2.4 BufferedOutputStream class
9.4.2.5 ObjectOutputStream class
9.6 Character Streams
9.6.1 Reader class hierarchy
9.6.1.1 CharArrayReader class
9.6.1.2 FileReader class
9.7 Writer class hierarchy
9.7.1 PrintWriter class

9.7.2 CharArrayWriter class


9.8 Console class
9.9 java.util.zip package
9.9.1 Deflater class
9.9.2 Inflater class
9.9.3 DeflaterInputStream class
9.9.4 DeflaterOutputStream class
9.9.5 InflaterInputStream class
9.9.6 InflaterOutputStream class
9.10 java.nio package
9.10.1 Path interface
9.10.2 Files class
List the contents of a directory
Create directories and files
Check the existence of a file or directory
Read and Write operation on files
Copy a file or directory
Move a file or directory
Delete a file or directory
Randomly access a file
9.10.3 FileSystem class
9.10.4 WatchService
9.10.5 PathMatcher interface
Summary
Multiple choice questions
Answers
Assignment

10. Threads and JDBC


Structure

Objectives
10.1 Threads
10.1.1 Java thread states and lifecycle
10.2 Thread class
10.2.1 Methods of the Thread class
10.2.2 Thread priority
10.2.3 Methods for thread priority
10.3 Runnable interface
10.4 Daemon Threads
10.5 Multithreading
10.5.1 isAlive() method
10.5.2 join() method
10.6 Thread synchronization
10.6.1 Synchronized block
10.6.2 Synchronized method
10.6.3 wait-notify mechanism
10.6.4 Deadlock
10.7 Concurrent collection APIs
10.8 Atomic variables
10.8.1 java.util.concurrent.atomic package
10.9 java.util.concurrent.locks package
10.10 Executors and Thread pools
10.10.1 Thread Pools
10.10.2 ForkJoinPool
10.11 Java Database Connectivity (JDBC)
10.11.1 JDBC API classes and interfaces
10.11.2 Connecting to a database from a Java program
Register the JDBC driver
Connect to the database

Execute an SQL statement


Retrieve and process the results
Close the database connection
10.11.3 Parameterized queries
10.11.4 Manage SQL exceptions
10.11.5 Connect to a database with Type 4 driver
10.11.6 Execute queries with the Statement object
10.11.7 Execute queries with the PreparedStatement object
10.12 DatabaseMetaData
10.13 ResultSetMetaData
10.14 Execute stored procedure with the CallableStatement object
10.14.1 CallableStatement interface
10.15 Scrollable ResultSet
10.15.1 Insert, update, delete operations on a ResultSet object
10.16 Batch updates
10.17 Transactions
10.18 RowSet interface
10.18.1 Types of RowSets
10.18.2 Connected RowSets
10.18.3 Disconnected RowSets
Summary
Multiple Choice Questions
Answers
Assignment

11. Design Patterns and Internationalization


Structure
Objectives
11.1 Design patterns and polymorphism

11.1.1 instanceOf operator


11.2 Design patterns
11.3 Creational patterns
11.3.1 Singleton pattern
11.3.2 Factory pattern
11.4 Structural patterns
11.4.1 Data Access Object (DAO) pattern
11.5 Behavioral patterns
11.5.1 Observer pattern
11.6 Other design concepts
11.6.1 Delegation
11.6.2 Composition and aggregation
11.7 Internationalization and localization
11.7.1 ISO codes
11.7.2 Unicode
11.8 Implementing internationalization and localization
11.9 Internationalization elements
11.9.1 Formatting number
11.9.2 Formatting percentage
11.9.3 Formatting currency
11.9.4 Formatting date
11.9.5 Formatting messages
Summary
Multiple choice questions
Answers
Assignment

12. More About JDK 8, 9, and 10


Structure
Objectives

12.1 Features of Java 8


forEach() method
StringJoiner class
StringJoiner vs StringBuilder
Parallel array sorting
12.2 Features of Java 9
Java Platform Module System (JPMS)
What is a module?
Java 9 Module Descriptor
Module Metadata
Readability and accessibility
Implied readability
Interactive Java REPL named JShell
JLink tool for linking
12.3 Features of Java 10
Local variable type inference
Understand the working of the local variable type inference
API changes
Fields
Summary
Multiple choice questions
Answers
Assignment

Index
CHAPTER 1

Introduction to Java

This chapter introduces the concept of object-oriented


programming and explains how Java has evolved as an object-
oriented programming (OOP) language. You will learn about the
various versions and features of Java and the steps to install a
Java Development Kit (JDK). You will also learn to create an
application by using JDK 8 and JDK 10.
Structure

Introduction to object-oriented programming

Java programming language

Java platform and editions

Java SE platform components

Java SE version history

Features of Java SE 9 and Java SE 10

Downloading and Installing JDK 8 and JDK 10

Setting up the path for JDK

Java application development

Structure of a Java program

Java code compilation and execution

Creating and executing a Java program using JDK 8


Creating and Installing a Java program using JDK 10

Creating and executing a Java 8 project in NetBeans

Creating and executing a Java 10 project in NetBeans


Objectives

Learn the concept of object-oriented programming

Learn to download and install JDK 8 and JDK 10

Understand the structure of a Java program

Learn to develop a Java project in NetBeans


1.1 Introduction to object-oriented programming

With the advancement in technology and the increasing complexity


of software, a requirement of new and flexible modes of
programming was observed. A need to make reliable software,
reduce the overall development and maintenance cost, and deliver
the software within timelines, resulted in the development of the
object-oriented programming model.

The primary focus of object-oriented programming is on objects.


Any real-world entity that has certain characteristics and behavior
that can be used to describe it is considered as an object. There
are several objects that have certain common characteristics. These
can be grouped into categories or classes. Thereby, every object of
a class will be considered as an instance of that class.
Programmatically, a class is a structure that contains the data
(characteristics) and methods (behavior) to work on that data.

For example, a class Vehicle can have characteristics such as color


and type, and behavior such as start, stop, accelerate, etc. The
following image shows a Unified Modeling Language (UML) class
diagram representation of the Vehicle class:
Figure 1.1: Class Diagram

Here, the Fields represent the characteristics and Methods


represent the behavior of the object. The Vehicle class can then
have instances of types of vehicles such as bike, bicycle, car, etc.
This is explained in detail in the following image:

Figure 1.2: Object of Vehicle Class

Here, the object bike has the characteristics color=blue and


type=motorcycle with the behavior, including start, stop, and
accelerate. Similarly, there can be other instances of the Vehicle
class such as car, bicycle, etc. with the same or different values
for characteristics and similar behavior.

An object-oriented programming language is based on the


following principles:

To encapsulate means to enclose. Hence, encapsulation allows you


to enclose the data members and methods into a closed structure
called a class. Encapsulation ensures data security through data
hiding so that a user cannot access the members of a class
directly.

Abstraction is a programming concept in which the non-essential


details of an entity are hidden from user view. For example, in the
case of a washing machine, the user only presses the button on
a digital panel to set up the process and start the machine.
However, the internal functioning of the washing machine is not
known to the user. This means that the non-essential aspect of
how the washing machine washes the clothes is abstracted from
the user. Similarly, abstraction can also be implemented in code to
hide the unnecessary details from the user.

To inherit means to acquire some feature or asset from an


ancestor. For example, a child acquires certain aspects of physical
appearance and certain behavior of his/her biological parents. In
programming also, inheritance plays a similar role. It allows us to
combine the common characteristics and behavior of objects into
a parent class also called a superclass. This class can then be
inherited by other classes that allow a developer to extend and
reuse the feature of existing classes. The new/inherited classes are
called child classes, derived classes, or subclasses.

Polymorph is a combination of words poly which means many and


morph which means forms. This polymorph is an object that can
have multiple forms/behaviors? For example, a chameleon can
change its color as per the environment to protect itself from
predators. In programming, polymorphism is the ability of an
object to behave in different ways based on requirements.
Polymorphism can be implemented in several ways in
programming based on the programming language used.
1.2 Java programming language

Java is a popular object-oriented, platform-independent


programming language. It allows you to develop a variety of
applications that can run on different hardware and operating
systems. Java also provides a runtime environment for executing
Java applications on different devices.

Java was originally developed in 1991 by James Gosling and a team


of engineers at Sun Microsystems which was later acquired by
Oracle Corporation. It was initially designed for consumer devices
such as washing machines, televisions, etc. For such devices, it
was necessary to have a language that was small, efficient, fast,
and platform-independent. Languages such as C and C++ were not
preferred due to the compiler’s dependence on specific CPUs and
also high development time and cost. Thus, Java was developed
as a portable and platform-independent language that could
execute code on any platform. Initially, it was named Oak but
later renamed to Java.

Even though Java was developed to cater to the programming


needs for smaller devices, it was found to be able to address
larger problems, including check casing of Web and mobile
applications. It gained instant popularity and was adopted all over
the world for the development of applications, ranging from
embedded, desktop, Web, and mobile applications. Java can be
used to create applications for small to large businesses and even
for supercomputers.
1.2.1 Features and advantages of Java

Following are some features and advantages of the Java


programming language:

Simple and robust: The Java syntax is derived from its predecessor
programming languages like C, C++. This makes it easy for
developers to learn Java quickly. Further, the complexity of
pointers, operator overloading, multiple inheritances and other
such features has been removed in Java. Instead, it has been
made more robust through efficient memory management and
exception handling features.

Java is based on the object-oriented programming paradigm.


Thereby, it is well suited for the development of real-world
applications.

Platform independent: Java provides a solution to a major problem


faced by earlier languages, that is, code portability. During
compilation, it converts the source code into an intermediate,
architecture-neutral format called bytecode. This bytecode can be
executed on any platform which has a Java Virtual Machine (JVM)
installed. Further, even the language specifications, such as the
size of primitive data types and operators, have been defined to
be independent of the hardware. This ensures that the code will
function properly in case of a change in the operating system,
processor, or system resources.
Security is an important issue in Java applications since they are
designed for multiple and distributed platforms. Java provides
security checks at different levels during application development.
The JVM is designed to apply its security features during code
execution to ensure that the code is well-formed and written as
per Java standards.

Java supports the development of multithreaded applications to


perform multiple tasks concurrently. In a multithreaded application,
a single program can have multiple threads performing tasks
independently and concurrently. Java allows you to create thread
pools that can be used to obtain threads when required.

Distributed and Java supports distributed programming to deploy


and access resources across the network. It provides several
Application Programming Interfaces (APIs) to handle remote
transmission and requests over a network. Java also allows
dynamic execution of classes by storing them in a separate
location and loading the necessary classes dynamically at runtime.

Modular: The concept of modularity has been introduced since


Java 9. It was supposed to be incorporated in Java 7 and Java 8
but was not accomplished. Until Java 1.8, the packages were
bundled into executable .jar files for a Java application. But, with
Java 9, a new construct called Module has been introduced. A
module is similar to the JAR file but unlike the JAR file, it also
contains the configuration information in the form of a module-
info.java file. This allows a module to be more powerful and
flexible as compared to a JAR file since all dependencies are
specified in the module-info.java file. While using a JAR file, the
entire JAR file is loaded during application execution, but with the
module, only those modules that are part of the dependency list
will be loaded. This allows applications to remain light-weight as
well as execute faster.
1.3 Java platform and editions

The Java platform is a development and execution environment for


Java applications which is a mixture of software and hardware
components. The following image shows the components of a
Java platform:

Figure 1.3: Java platform

The above figure depicts the components of a Java platform. It is


formed of the Java Runtime Environment (JRE) which contains the
Java library (Java API) and Java Virtual Machine (JVM). In
languages such as C and C++, the compiled code is platform
dependent as it is in the form of executable binary code.
However, the Java compiler converts the code into an intermediate
bytecode which is an optimized set of instructions that can be
executed on any machine that has the appropriate JVM. Thus,
JVM provides platform independence to Java code. Each operating
system such as Windows, Linux, Mac, etc. has its JVM. Thus, Java
code follows the principle of write-once use many.

The Java API/library is a collection of ready-to-use components


such as call uses and interfaces that can be used to create
applications. For example, the Swing library is used to create a
user interface (UI) of a Java application. Java is released under
several editions to meet the requirements of a specific type of
device and application. The following is a brief description of the
different Java editions:

Java Standard Edition (Java The Java SE platform is the base for
creating applications that are console or network-based applications
mainly for desktop computers. It contains the core APIs which
include the basic types and classes for higher-level programming
such as networking, security, Graphical User Interface (GUI),
database manipulation, and parsing of XML data. It also provides
the virtual machine, development and deployment tools, and other
toolkits and libraries for advanced programming.

Java Enterprise Edition (Java EE): The Java EE platform is an


extension of the Java SE platform. It provides the tools and APIs
for the creation and deployment of large-scale, distributed,
scalable, multi-tier, reliable, and secure enterprise applications with
complex business logic.
Java Micro Edition (Java ME): The Java ME platform is mainly
used for creating embedded Java applications for small devices
such as mobiles, TVs set-top boxes, etc. It contains a subset of
Java SE APIs and a smaller virtual machine to execute Java
programs on small devices with lesser memory and storage space.
Java ME applications are generally used as clients of Java EE
platform services.

JavaFX: The JavaFX platform provides lightweight user interface


APIs for creating rich internet applications that use hardware-
accelerated graphics and media engines. Java FX allows you to
create high-performance graphic applications with a modern look-
and-feel. It also provides high-level APIs to connect with data
sources over the network. JavaFX applications can also be used as
clients of Java EE platform services.
1.4 Java SE platform components

The two important Java SE platform components are Java Runtime


Environment (JRE) and Java Development Kit (JDK). The JRE
contains all the Java libraries required to execute a Java program
whereas the JDK contains the libraries required to develop Java
programs and is distributed for different platforms like Windows,
MacOS X, Linux, etc. The JDK comprises the tools required for
application development, compilation, debugging, etc. It also has
its own JRE to execute and test Java applications. The following
image shows the different Java SE platform components:

Figure 1.4: Java SE platform

The brief descriptions of the tools and libraries are given below:
Development Tools and APIs: The tools and utilities form the base
for Java development. The development tools include the javac
compiler, Java launcher, a Javadoc documentation tool, etc. The
Java APIs are ready-to-use classes and interfaces for different
functionalities such as networking, XML parsing, GUI creation,
database manipulation, and many more.

Deployment Tools: The JDK provides software for deploying


applications on target machines. Java Web Start and Java Plug-In
are examples of deployment tools.

User Interface Toolkits: The JDK comes bundled with UI toolkits


such as Swing, Java2D, and Abstract Window Toolkit (AWT) for the
development of graphical user interfaces in Java applications.

Integration Libraries: Integration libraries such as Java Database


Connectivity (JDBC), Java Naming and Directory Interface (JNDI),
etc. provide access to databases and remote objects for data
manipulation and network access.

Other Base Libraries: These libraries include APIs for file


manipulation, networking, XML parsing, security,
internationalization, and so on.

Language and Utility Libraries: These libraries include Math,


Collections, Logging, Regular Expressions, etc. that allow you to
perform manipulation of data in a Java program.
1.5 Java SE version history

The Java Standard Edition (Java SE) is a platform for the


development of robust, reliable, and secure applications with the
development tools, APIs, utilities, and runtime environment
provided by the Java Development Kit The JDK has undergone
several modifications over the years with some major
enhancements and new features added with every new release.
The following table lists the different releases of JDK with the
corresponding features and enhancements:

enhancements: enhancements: enhancements:

enhancements: enhancements: enhancements: enhancements:


enhancements: enhancements: enhancements: enhancements:

enhancements: enhancements: enhancements: enhancements:


enhancements: enhancements: enhancements:

enhancements: enhancements: enhancements: enhancements:


enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements:

enhancements: enhancements: enhancements: enhancements:

enhancements: enhancements: enhancements: enhancements:


enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:

enhancements: enhancements: enhancements: enhancements:


enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:

enhancements: enhancements: enhancements: enhancements:


enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements:

enhancements: enhancements: enhancements: enhancements:


enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements:

enhancements: enhancements: enhancements: enhancements:


enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements: enhancements: enhancements:
enhancements: enhancements:

Table 1.1: Versions of Java


Discovering Diverse Content Through
Random Scribd Documents
bed. They wrap up their heads and lie down again. As soon as
they are fairly dreaming that they are at home, and need not get
up till they please, the horn startles them; they raise their heads,
see a light under the door, and the black woman looks in to drawl
out that they must please to make haste. It seems like a week
since they lay down; but they are not rested, and turn away sick
and dizzy from the flickering light.

In the morning you wonder where your fatigue is gone. As the day
steals through the forest, kindling up beauty as it goes, the
traveller's whole being is refreshed. The young aloes under the
fallen trunks glitter with dew; the gray moss, dangling from the
trees, waves in the breath of the morning. The busy little
chameleons run along the fences, and the squirrel erects his brush
as you pass. While the crescent moon and the morning star
glittered low down in the sky, you had longed to stay the sun
beneath the horizon; but, now that he is come, fresh vigour and
enjoyment seem to be shed down with his rays.

At such an hour you often come up with a family departing from


the spot where they had "camped out" for the night. I never had
the pleasure of camping out, but I know exactly what it must be
like, for I have seen establishments of this sort in every stage of
the process, from the searching out a spot blessed with a running
stream, a shelter to windward, a dry soil, and plenty of fuel, to the
piling the wagon with the pots, pans, and children previous to
starting at dawn. There is a striking air of cheer about the family
when beginning their new day; leaving behind the desolation they
have made; the scorched turf, the scattered brushwood, chips,
and meat-bones, and setting forth in renewed strength in the fresh
morning. I owe to these people many a picture such as will never
meet my eye in the galleries of art.

Our stationary rural life in the South was various and pleasant
enough; all shaded with the presence of slavery, but without any
other drawback. There is something in the make-shift, irregular
mode of life which exists where there are slaves, that is amusing
when the cause is forgotten.

The waking in the morning is accomplished by two or three black


women staring at you from the bedposts. Then it is five minutes'
work to get them out of the room. Perhaps, before you are half
dressed, you are summoned to breakfast. You look at your watch,
and listen whether it has stopped, for it seems not to be seven
o'clock yet. You hasten, however, and find your hostess making
the coffee. The young people drop in when the meal is half done,
and then it is discovered that breakfast has been served an hour
too early, because the clock has stopped, and the cook has
ordered affairs according to her own conjectures. Everybody
laughs, and nothing ensues. After breakfast a farmer in homespun
—blue trousers and an orange-brown coat, or all over gray—
comes to speak with your host. A drunken white has shot one of
his negroes, and he fears no punishment can be obtained,
because there were no witnesses of the deed but blacks. A
consultation is held whether the affair shall go into court; and,
before the farmer departs, he is offered cake and liqueur.

Your hostess, meantime, has given her orders, and is now


engaged in a back room, or out in the piazza behind the house,
cutting out clothes for her slaves; very laborious work in warm
weather. There may be a pretence of lessons among the young
people, and something more than pretence if they happen to have
a tutor or governess; but the probability is that their occupations
are as various as their tempers. Rosa cannot be found; she is lying
on the bed in her own room reading a novel; Clara is weeping for
her canary, which has flown away while she was playing with it;
Alfred is trying to ascertain how soon we may all go out to ride;
and the little ones are lounging about the court, with their arms
round the necks of blacks of their own size. You sit down to the
piano or to read, and one slave or another enters every half hour
to ask what is o'clock. Your hostess comes in at length, and you sit
down to work with her; she gratifies your curiosity about her
"people," telling you how soon they burn out their shoes at the
toes, and wear out their winter woollens, and tear up their
summer cottons; and how impossible it is to get black women to
learn to cut out clothes without waste; and how she never inquires
when and where the whipping is done, as it is the overseer's
business, and not hers. She has not been seated many minutes
when she is called away, and returns saying how babyish these
people are, that they will not take medicine unless she gives it to
them; and how careless of each other, so that she has been
obliged to stand by and see Diana put clean linen upon her infant,
and to compel Bet to get her sick husband some breakfast.

Morning visiters next arrive. It may be the clergyman, with some


new book that you want to look at; and inquiries whether your
host sees any prospect of getting the requisite number of
professors for the new college, or whether the present head of the
institution is to continue to fill all the chairs. It may be a lank
judge from some raw district, with a quid in his cheek, a
swordcane in his hand, and a legal doubt in his mind which he
wants your host to resolve. It may be a sensible woman, with
courtesy in her countenance and decision in her air, who is
accustomed really to rule her household, and to make the most of
such human material and such a human lot as are pressing around
and upon her. If so, the conversation between her and your
hostess becomes rapid and interesting; full of tales of perplexity
and trouble, of droll anecdotes, and serious and benevolent plans.
Or it may be a lady of a different cast, who is delighted at the
prospect of seeing you soon again. You look perplexed, and
mention that you fear you shall be unable to return this way. Oh,
but you will come and live here. You plead family, friends, and
occupation in England, to say nothing of England being your
home. Oh, but you can bring your family and friends with you. You
laughingly ask why. She draws up and replies, "for the honour and
glory of living in a republic."
Meantime Clara has dried her tears, for some one has recovered
her canary, and the door of the cage is shut. The carriage and
saddle-horses are scrambling on the gravel before the door, and
the children run in to know if they may ride with you. Cake, fruit,
and liqueurs, or perhaps tea, are brought in, and then the ladies
depart. The clergyman thinks he will ride round with your party,
hearing that you are going to inspect Mr. A.'s plantation. He warns
you that it will not be "pleasant to see even the best plantations,"
and your trembling heart fully agrees.

You admire the horsemanship of your host on his white horse, and
the boys on their black ponies. The carriage goes at good speed,
and yet the fast pace of the saddle-horses enables the party to
keep together. While you are looking out upon a picturesque
loghouse, peeping forth from a blossomy thicket, or admiring a
splendid hedge of the Cherokee rose in straggling bloom, Rosa
rouses herself from a revery, and asks you to tell her all about
Victoria.

"What shall I tell you?"

"What religion is she? A Unitarian, I suppose, like you."

Church of Englandism and dissent being explained, Rosa resumes,


in a plaintive voice, "Is she betrothed yet."

"Not that I know of."

"Oh, I hope she is! I wish I knew! When will she be queen? When
she is eighteen, won't she? Oh! I thought she was to be of age,
and be made queen at eighteen. How long will she be a queen?"

"As long as she lives."

"As long as she lives! Why I thought—"


Rosa has no idea of rulers not being changed every four or eight
years. Even her imagination is almost overpowered at the idea of
being set above everybody else for life.

The carriage stops, and you are invited to step out, and view the
ravages of a tornado a season or two ago; you see how clear a
path it made for itself in the forest, and how it swept across the
river, tearing down an answering gap through the tall canebrake
on the opposite bank. The prostrated trees lie sunk in swamp, half
hidden by flowering reeds and bright mosses, while their stumps,
twice as tall as yourself, are all cropped off, whatever may be their
thickness, precisely at the same height, and so wrenched and
twisted as to convince you that you never before conceived of the
power of the winds. The boys show you a dry path down to the
river side, that you may see the fishtraps that are laid in the
stream, and watch the couples of shad-fishers—dark figures amid
the flashing waters—who are pursuing their occupation in the
glare of noon. The girls tell you how father remembers the time
when there were bears in that canebrake, and there was great
trouble in getting them to come out of their thick covert to be
killed. When father first came here, this side of the river was all
canebrake too. Is not a canebrake very ugly? It may not have any
picturesque beauty; but your eye rests upon it with satisfaction, as
a tropical feature in the scene.

You proceed, and point out with admiration a beautifully-situated


dwelling, which you declare takes your fancy more than any you
have seen. The children are amused that you should suppose any
one lives there, overshadowed with trees as it is, so that its
inhabitants would be devoured by moschetoes. Your hostess tells
you that it is called Mr. B.'s Folly. He spent a good deal of money
and much taste upon it, but it is uninhabitable from being rather
too near the river. The fever appeared so immediately and
decisively that the family had to leave it in three months, and
there it stands, to be called B.'s Folly.
Your host paces up to the carriage window to tell you that you are
now on A.'s plantation. You are overtaking a long train of negroes
going to their work from dinner. They look all over the colour of
the soil they are walking on: dusky in clothing, dusky in
complexion. An old man, blacker than the rest, is indicated to you
as a native African; and you point out a child so light as to make
you doubt whether he be a slave. A glance at the long heel settles
the matter. You feel that it would be a relief to be assured that this
was a troop of monkeys dressed up for sport, rather than that
these dull, shuffling animals should be human.

There is something inexpressibly disgusting in the sight of a slave


woman in the field. I do not share in the horror of the Americans
at the idea of women being employed in outdoor labour. It did not
particularly gratify me to see the cows always milked by men
(where there were no slaves); and the hay and harvest fields
would have looked brighter in my eyes if women had been there
to share the wholesome and cheerful toil. But a negro woman
behind the plough presents a very different object from the
English mother with her children in the turnip-field, or the Scotch
lassie among the reapers. In her pre-eminently ugly costume, the
long, scanty, dirty woollen garment, with the shabby large bonnet
at the back of her head, the perspiration streaming down her dull
face, the heavy tread of the splay foot, the slovenly air with which
she guides her plough, a more hideous object cannot well be
conceived, unless it be the same woman at home, in the negro
quarter, as the cluster of slave dwellings is called.

You are now taken to the cotton-gin, the building to your left,
where you are shown how the cotton, as picked from the pods, is
drawn between cylinders so as to leave the seeds behind; and
how it is afterward packed, by hard pressure, into bales. The
neighbouring creek is dammed up to supply the water-wheel by
which this gin is worked. You afterward see the cotton-seed laid in
handfuls round the stalks of the young springing corn, and used in
the cotton field as manure.
Meantime you attempt to talk with the slaves. You ask how old
that very aged man is, or that boy; they will give you no intelligible
answer. Slaves never know, or never will tell their ages, and this is
the reason why the census presents such extraordinary reports on
this point, declaring a great number to be above a hundred years
old. If they have a kind master, they will boast to you of how much
he gave for each of them, and what sums he has refused for
them. If they have a hard master, they will tell you that they would
have more to eat and be less flogged, but that massa is busy, and
has no time to come down and see that they have enough to eat.
Your hostess is well known on this plantation, and her kind face
has been recognised from a distance; and already a negro woman
has come to her with seven or eight eggs, for which she knows
she shall receive a quarter dollar. You follow her to the negro
quarter, where you see a tidy woman knitting, while the little
children who are left in her charge are basking in the sun, or
playing all kinds of antics in the road; little shining, plump,
cleareyed children, whose mirth makes you sad when you look
round upon their parents, and see what these bright creatures are
to come to. You enter one of the dwellings, where everything
seems to be of the same dusky hue: the crib against the wall, the
walls themselves, and the floor, all look one yellow. More children
are crouched round the wood fire, lying almost in the embers. You
see a woman pressing up against the wall like an idiot, with her
shoulder turned towards you, and her apron held up to her face.
You ask what is the matter with her, and are told that she is shy.
You see a woman rolling herself about in a crib, with her head tied
up. You ask if she is ill, and are told that she has not a good
temper; that she struck at a girl she was jealous of with an axe,
and the weapon being taken from her, she threw herself into the
well, and was nearly drowned before she was taken out, with her
head much hurt.

The overseer has, meantime, been telling your host about the
fever having been more or less severe last season, and how well
off he shall think himself if he has no more than so many days'
illness this summer: how the vegetation has suffered from the late
frosts, pointing out how many of the oranges have been cut off,
but that the great magnolia in the centre of the court is safe. You
are then invited to see the house, learning by the way the extent
and value of the estate you are visiting, and of the "force" upon it.
You admire the lofty, cool rooms, with their green blinds, and the
width of the piazzas on both sides the house, built to compensate
for the want of shade from trees, which cannot be allowed near
the dwelling for fear of moschetoes. You visit the icehouse, and
find it pretty full, the last winter having been a severe one. You
learn that, for three or four seasons after this icehouse was built,
there was not a spike of ice in the state, and a cargo had to be
imported from Massachusetts.

When you have walked in the field as long as the heat will allow,
you step into the overseer's bare dwelling, within its bare
enclosure, where fowls are strutting about, and refresh yourself
with a small tumbler of milk; a great luxury, which has been
ordered for the party. The overseer's fishing-tackle and rifle are on
the wall, and there is a medicine chest and a shelf of books. He is
tall, sallow, and nonchalant, dropping nothing more about himself
and his situation than that he does not know that he has had more
than his share of sickness and trouble in his vocation, and so he is
pretty well satisfied.

Your hostess reminds the party that they are going out to dinner,
and that it is quite time to be returning to dress. So you go
straight home by a shorter road, stopping no more, but looking
out, now at a glorious trumpet honeysuckle dangling from a
branch, now at a lofty, spreading green tree, red hot close to the
ground, while a sheet of flame is spreading all about its roots, the
flames looking orange and blue in the bright sunshine.

You are glad to find, on arriving at home, that you have half an
hour to lie down before you dress, and are surprised, on rising, to
feel how you are refreshed. You have not very far to go to dinner;
only to Mr. E.'s cottage on the Sand Hills. The E.'s have just come
for the summer, the distant city being their winter residence. If
you find the accommodations poor, you must excuse it in
consideration of their recent removal. The E.'s live in very good
style in the city. The cottage is half way up a gentle ascent, with a
deep, sandy road leading to the wooden steps of the front piazza,
and pine forests in the rear. The entertainment to-day is not solely
on your account; it is a parting dinner to young Mr. and Mrs. F.,
who are going to reside farther West. They are leaving their
parents and friends, and the family estate, and are to live in a
loghouse till a proper dwelling can be built. Mrs. F. is rather low in
spirits, but her mother means to send the old family nurse with
her, so that she will have one comfort, at any rate, and will be able
to trust her infant out of her sight now and then. As for Mrs. E.,
she informs you that she has come out to the cottage sooner than
she usually does, as she is expecting her confinement. She has all
her five children in her presence always; and as she cannot trust
them for an hour with her "people," their noise and the heat would
be intolerable in town; but here, where her room opens upon the
piazza, she can have the children always in her sight or hearing
with less fatigue than in the city. You ask whether such a charge
be not too much for her. Certainly; but there is no use in
complaining, for it cannot be helped. She never had a nurse that
was not more plague than use. It is not only that the servants tell
the children improper things, and teach them falsehood, but it is
impossible to get the little boys' faces washed without seeing it
done; and the infant may, as likely as not, be dropped into the fire
or out of the window. Ladies must make the best of their lot, for
they cannot help themselves.

The dinner is plentiful, including, of course, turkey, ham, and


sweet potatoes; excellent claret, and large blocks of icecream. A
slave makes gentle war against the flies with the enormous bunch
of peacocks' feathers; and the agitation of the air is pleasant while
the ladies are engaged in eating, so that they cannot use their
own fans, which are hung by loops on the backs of their chairs.
The afternoon is spent in the piazza, where coffee is served. There
the ladies sit, whisking their feather fans, jesting with the children,
and talking over the last English poem or American novel, or
complaining bitterly of the dreadful incendiary publications which
Mr. E. heard from Mr. H., who had heard it from Mr. M., that Judge
R. had said that somebody had seen circulated among the negroes
by some vile agent of the horrid abolitionists of the North.

You go in to tea, and find the table strewed with prints, and the
piano open, and Mrs. F. plays and sings. The gentlemen have done
discussing the French war and the currency, and are praising the
conduct of the Committee of Vigilance; frankly informing you, as a
stranger, of the reasons of its formation, and the modes of its
operation in deterring abolitionists from coming into the
neighbourhood, in arresting them on any suspicion of tampering
with the negroes, and in punishing them summarily if any facts are
established against them. While you are endeavouring to learn the
nature of the crime and its evidence, you are summoned. There is
going to be a storm, and your party must get home, if possible,
before it comes on. In such a case Mrs. E. will say nothing in
opposition to your leaving her so early. She would not be the
means of exposing you to the storm. You hasten away, and reach
home during the first explosion of thunder.

You find there a bouquet, sent to you with Miss G.'s compliments;
a splendid bunch of quince, yellow jessamine, arbor vitæ,
hyacinths, cherry, and other blossoms. It is not nearly bedtime
yet; and you sit on the sofa, fanning yourself, with the table-lamp
dimmed by the momentary glare of blue lightning. Your hostess
learns from the servants that poor Miss Clara went to bed in great
grief, the cat having killed her canary in the afternoon. It has been
a sad day for poor Clara, from the adventures of her bird; but she
is now fast asleep.

Your host amuses you with anecdotes of South country life. He


asks you how you were struck with Mrs. L., whose call you
returned yesterday. You reply that she seems a cheerful, hearty
personage, who makes the best of a poor lot; and you relate how
pleased you were at the frankness with which she owned, pointing
to the stocking she was darning, that she knew little of books
nowadays, or of music, as she was making shirts and darning
stockings for her sons all the year round. You were sorry to see
such evidences of poverty; chairs with broken backs, and a piano
with three legs, and a cracked flute; but glad that Mrs. L. seemed
able to look on the bright side of things. Your host throws himself
back, and laughs for three minutes; and, when he recovers,
informs you that Mrs. L. is the wealthiest widow in the state. You
protest that you looked upon her with respect as a meritorious
widow, doing her best for a large family. Your host repeats that
she is the richest widow in the state, and that she and all her
family are odd about money. She has a sister in a neighbouring
state, Mrs. M., who is even more bent upon economy. Last year
Mrs. L. visited this sister, who lives in a country town. The sisters
went out in Mrs. M.'s carriage, to make calls and do shopping.
Mrs. L. observed that her sister's carriage was attended by a little
mulatto girl, who let down the steps, and put them up, and
mounted behind very dexterously. "The child is clever enough,"
said Mrs. L.; "but, sister, your carriage should have a proper
footman. You should not be seen in town with a girl behind your
carriage." Mrs. M. promised to consider the matter. The next day a
spruce mulatto lad was in waiting, of whom Mrs. L. fully approved.
When she looked in his face, however, as he was letting down the
steps at the entrance of a store, she was struck by his remarkable
likeness to the girl of yesterday, and observed upon it. Mrs. M.
laughed, and owned she had got a suit of boy's clothes made
since yesterday for the girl to wear during morning drives, and she
thought this an excellent plan. Many such a story does your host
amuse you with; observing that, though America has fewer
humourists than England, they may be met with in abundance in
rare settlements and retired districts, where they can indulge their
fancies without much suffering from public opinion.
The storm abates. You are the oracle as to what o'clock it is; and,
as you are confident that it is near eleven, the chamber lights are
brought. You dismiss your dusky attendants, and throw yourself on
your ample sofa for half an hour, to recall what you have seen and
heard this day, and meditate on the scope and tendencies of
Country Life in the Southern States.
CITY LIFE IN THE SOUTH.

"Ye thus hospitably live,


And strangers with good cheer receive."

Prior.
"Nor are those empty-hearted whose low sound
Reverbs no hollowness."

Shakspeare.

The disasters of our railroad journey to Charleston have been


[14]
described elsewhere. We were to have arrived at the city
about six P.M. of the 10th of March, when every object would have
looked bright in the sunshine of a spring evening. As it was, we
reached the railroad station at ten minutes past four the next
morning. There was much delay in obtaining our luggage and
getting away from the station. We could not think of disturbing the
slumbers of the friends whose hospitality we were about to enjoy,
and we therefore proceeded in the omnibus which was in waiting
to the Planter's Hotel. We were all hungry, having scarcely tasted
food since noon the day before; and very weary, having travelled
the whole of two nights, and enjoyed no sufficient rest since we
left Richmond, nine days before. Every little event became a great
one to persons so exhausted. The omnibus jolted and stopped,
and we were told that an accident had happened. The gentlemen
got out, but the darkness was total. A light was brought from a
private house, and it appeared that a wheel had touched the
kerbstone! It seemed as if horses were never backed in
Charleston, so long were we in proceeding. When I afterward saw
what the streets of Charleston are like, I do not wonder at any
extreme of caution in a driver. The soil is a fine sand, which, after
rain, turns into a most deceptive mud; and there is very little
pavement yet. The deficiency of stone is, however, becoming
supplied by importation, and the inhabitants hope soon to be able
to walk about the city in all weathers, without danger of being lost
in crossing the streets. They told me, as an on dit, that a horse
was drowned last winter in a mudhole in a principal street.

At the hotel all was dark and comfortless. We made a stir among
the servants; the gentlemen got two men to light a fire, and fetch
us wine and biscuits; and we persuaded two women to make up
beds and warm some water. We were foolish enough to be
tempted to take wine and water, as we could have neither tea or
coffee; and when we rose from our unrefreshing sleep an hour
after noon, we formed such a dismal group of aching heads as
could hardly be matched out of a hospital.

Two of us proceeded, in a light pretty hack-carriage, to the friend's


house where we were expected. Nothing could be more
considerate than our reception. A pile of English and American
letters and newspapers awaited us, and our hostess knew that we
must be fatigued; a fire was therefore immediately lighted in my
chamber, and we were told that the day was our own; that our
dinner would be sent up to us, and that we should not be
expected in the drawing-room till we chose to join the family. I
shall not soon forget the refreshment of lingering over family
letters and London newspapers; of feeling that we were not liable
to be called up in the dark for a fortnight at least; and of seeing
my clothes laid in drawers, for the first time, I think, since I
landed. A chest of drawers is seldom to be seen in the chambers,
or, at least, in the guest-chambers of American houses. We were
favoured in the article of closets with rows of pegs, but I believe I
had the use of a chest of drawers only two or three times during
my travels.

A circumstance happened this day which, as being illustrative of


manners, may be worth relating. The day before I left Richmond,
Virginia, two companions and myself had employed a hack-
carriage, driven by a black, for some hours; and, on dismissing it,
had paid the fare, which we thought reasonable, two dollars and a
half. The proprietor of the carriage and master of the driver had by
some means heard who it was that had been his customer. Finding
that I had left Richmond, he took the trouble to send the two
dollars and a half down to Charleston, five hundred miles, with a
message that it was not for the honour of Virginia that I should
pay carriage hire! and the money was awaiting me on my arrival.

I had soon reason to perceive that Charleston deserves its renown


for hospitality. A lecturer on phrenology sent us tickets for his
course; six carriages were immediately placed at my disposal, and
the servants came every morning for orders for the day. The
difficulty was to use them all and equally; but, by employing one
for the morning drive and another for the evening visiting, we
contrived to show our friends that we were willing to avail
ourselves of their kindnesses. I believe there was scarcely a
morning during our stay when some pretty present did not arrive
before I rose; sometimes it was a bouquet of hyacinths, which
were extremely rare that year, from the lateness and severity of
the frosts; sometimes it was a dish of preserve or marmalade;
sometimes a feather fan, when the day promised to be hot;
sometimes a piece of Indian work; sometimes of indigenous
literary production. One morning I found on my window-seat a
copy of the Southern Review, and a bouquet of hyacinths from
General Hayne; and the next a basket of wafers from Mrs. P.; and
the third a set of cambric handkerchiefs, inimitably marked with
complimentary devices, from Mrs. W.
In the midst of all this there was no little watchfulness, among a
totally different set of persons, about my proceedings with regard
to the negroes. I had not been in the city twenty-four hours before
we were amused with ridiculous reports of my championship on
behalf of the blacks; and, long after I had left the place, reported
speeches of mine were in circulation which were remarkably
striking to me when I at length heard them. This circumstance
shows how irritable the minds of the people are upon this topic. I
met with no difficulty, however, among my associates. I made it a
rule to allow others to introduce the subject of slavery, knowing
that they would not fail to do so, and that I might learn as much
from their method of approaching the topic as from anything they
could say upon it. Before half an hour had passed, every man,
woman, or child I might be conversing with had entered upon the
question. As it was likewise a rule with me never to conceal or
soften my own opinions, and never to allow myself to be irritated
by what I heard (for it is too serious a subject to indulge frailties
with), the best understanding existed between slaveholders and
myself. We never quarrelled, while, I believe, we never failed to
perceive the extent of the difference of opinion and feeling
between us. I met with much more cause for admiration in their
frankness than reason to complain of illiberality. The following may
serve as a specimen of this part of our intercourse:—

The first time I met an eminent Southern gentleman, a defender


of slavery, he said to me (within the half hour),

"I wish you would not be in such a hurry away. I wish you would
stay a year in this city. I wish you would stay ten years, and then
you would change your opinions."

"What opinions?"

"Your opinions on slavery."

"What do you know of my opinions on slavery?"


"Oh, we know them well enough: we have all read 'Demerara.'"

"Very well: now we shall understand each other; for I must tell
you that I think about slavery exactly as I did when I wrote that
story. Nothing that I have seen shows me that I have anything to
qualify of what is said there. So now you do know my opinions."

"Oh yes. I don't want to know anything more of your opinions. I


want you to know mine."

"That is exactly what I want. When will you let me have them?"

We had engaged to dine with this gentleman the next week; it


was now arranged that our party should go two hours earlier than
the other guests, in order to hear this gentleman's exposition of
slavery. He was well prepared, and his statement of facts and
reasons was clear, ready, and entertaining. The fault was in the
narrowness of his premises, for his whole argument was grounded
on the supposition that human rights consist in sufficient
subsistence in return for labour. Before he began I told him that I
fully understood his wish not to argue the question, and that I
came to hear his statement, not to controvert it; but that I must
warn him not to take my silence for assent. Upon this
understanding we proceeded, with some little irritability on his part
when I asked questions, but with no danger of any quarrel. I
never found the slightest difficulty in establishing a similar clear
understanding with every slaveholder I met. In the drawing-room
of the boarding-house at Richmond, Virginia, three gentlemen, two
of whom were entire strangers, attacked me in the presence of a
pretty large company one afternoon. This was a direct challenge,
which I did not think fit to decline, and we had it all out. They
were irritable at first, but softened as they went on; and when, at
the end of three hours, we had exhausted the subject, we were
better friends than when we began.
Some of the reports of my championship of the negroes arose
from a circumstance which occurred the day after my arrival at
Charleston. Our host proposed to take us up a church steeple, to
obtain a view of the city and its environs. The key of the church
was at the Guardhouse opposite, and our host said we might as
well go for it ourselves, and thus get a sight of the Guardhouse.
One of the city authorities showed us over it, and we stayed a few
moments in a room where a lady was preferring a complaint
against two negro boys for robbing a henroost. They were proved
guilty, and sentenced to be flogged at the place of punishment at
the other end of the city.

The view from the church steeple was very fine; and the whole,
steeped in spring sunshine, had an oriental air which took me by
surprise. The city was spread out beneath us in a fanlike form, in
streets converging towards the harbour. The heat and moisture of
the climate give to the buildings the hue of age, so as to leave
nothing of the American air of spruceness in the aspect of the
place. The sandy streets, the groups of mulattoes, the women
with turbaned heads, surmounted with water-pots and baskets of
fruit; the small panes of the house windows; the yucca bristling in
the gardens below us, and the hot haze through which we saw the
blue main and its islands, all looked so oriental as to strike us with
wonder. We saw Ashley and Cooper rivers, bringing down produce
to the main, and were taught the principal buildings—the churches
and the Custom-house, built just before the Revolution—and the
leading streets, Broad and Meeting streets intersecting, and
affording access to all that we were to see. It would be wise in
travellers to make it their first business in a foreign city to climb
the loftiest point they can reach, so as to have the scene they are
to explore laid out as in a living map beneath them. It is scarcely
credible how much time is saved and confusion of ideas obviated
by these means. I gained much by mounting the State House at
Boston, Pennsylvania Hospital at Philadelphia, the new hotel at
Baltimore, the Capitol at Washington, the high hills about
Cincinnati, the college at Lexington, the hill where the Statehouse
is to be at Nashville, the Cotton-press at New Orleans, and this
church steeple at Charleston.

Another care of the traveller should be to glance at the local


newspapers. This first morning I found a short newspaper article
which told volumes. It was an ordinance for raising ways and
means for the city. Charitable and religious institutions were left
free from taxation, as were the salaries of the clergy and
schoolmasters. There was a direct levy on real property, on slaves,
and on carriages, and a special tax on free people of colour; a
class who, being precluded from obtaining taxable property and
luxuries, were yet made to pay by means of a polltax.

Our mornings were divided between receiving callers and drives


about the city and in the country. The country is flat and sandy,
and the only objects are planters' mansions, surrounded with
evergreen woods, the gardens exhibiting the tropical yucca, and
fenced with hedges of the Cherokee rose. From the lower part of
the city glimpses of the main may be had; but the intervening
space is very ugly, except at high tide; an expanse of reeking slime
over which large flocks of buzzards are incessantly hovering. On
the top of each of the long row of stakes discovered at low water
sits a buzzard. A fine is imposed for killing one of these birds, the
unsalaried scavengers of the moister districts of the city.

The houses which we visited in returning calls were generally


handsome, with capacious piazzas, rich plants and bouquets, and
good furniture. The political bias of the inhabitant was often
discoverable from the books on the table, or the prints and casts
on the walls. In no society in the world could the division of parties
be more distinct, and their alienation more threatening than in
[15]
Charleston at the time I was there. The Union gentlemen and
ladies were dispirited and timid. They asked one another's opinion
whether there was not some mysterious stir among the nullifiers;
whether they were not concerting measures for a new defiance of
the general government. This anxious watchfulness contrasted
strangely with the arrogant bearing of the leading nullifiers. During
my stay Mr. Calhoun and his family arrived from Congress; and
there was something very striking in the welcome he received, like
that of a chief returned to the bosom of his clan. He stalked about
like a monarch of the little domain; and there was certainly an air
of mysterious understanding between him and his followers,
whether there was really any great secret under it or not. One
lady, who had contributed ample amounts of money to the
nullification funds, and a catechism to nullification lore, amused
while she grieved me by the strength of her political feelings.
While calling on her one morning, the conversation turned on
prints, and I asked an explanation of a strange-looking one which
hung opposite my eye; the portrait of a gentleman, the top of the
head and the dress visible, but the face obliterated or covered
over. She was only too ready to explain. It was a portrait of
President Jackson, which she had hung up in days when he
enjoyed her favour. Since nullification she had covered over the
face, to show how she hated him. A stranger hardly knows what
to think of a cause whose leaders will flatter and cherish the
perpetrators of a piece of petty spite like this; yet this lady is
treated as if she were a main pillar of the nullification party.

Some of our mornings were spent in going with the Hayne and
Calhoun families to the public library, to a panorama, and to the
arsenal. The library is supported by private subscriptions, and is
very creditable to the city, whose zeal about its books might well
have been exhausted by the repeated destruction of the library by
fire and in the war. We amused ourselves with files of newspapers
which have survived all disasters; old London Gazettes and
colonial papers extending as far back as 1678.

We visited the arsenal twice; the second time with Mr. Calhoun
and Governor Hayne, when we saw the arms and ammunition,
which were not visible the first time, because "the key was not on
the premises;" a token that no invasion was immediately expected.
There were two bombs brought in by Governor Hayne, and all the
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like