100 Solutions In Java A Handson Introduction To Programming In Java Dhruti Shah download
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
https://ebookbell.com/product/100-solutions-in-java-2nd-edition-2nd-
edition-dhruti-shah-53640426
https://ebookbell.com/product/plugin-css-100-power-solutions-1st-
edition-robin-nixon-2260648
https://ebookbell.com/product/plugin-javascript-100-power-solutions-
robin-nixon-4702434
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
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
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
ISBN: 978-93-89845-600
Distributors:
BPB PUBLICATIONS
New Delhi-110002
Ph: 23254990/23254991
MICRO MEDIA
Ph: 22078296/22078297
DECCAN AGENCIES
Hyderabad-500195
Ph: 24756967/24756400
BPB BOOK CENTRE
Delhi-110006
Ph: 23861747
www.bpbonline.com
Dedicated to
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.
https://rebrand.ly/i6o42il
Errata
errata@bpbonline.com
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.
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!
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
Assignment
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
Index
CHAPTER 1
Introduction to Java
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 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.
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.
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.
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.
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.
"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?"
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 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.
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.
Prior.
"Nor are those empty-hearted whose low sound
Reverbs no hollowness."
Shakspeare.
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.
"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?"
"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."
"That is exactly what I want. When will you let me have them?"
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.
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.
ebookbell.com