Professional Documents
Culture Documents
Java: A Beginner’s Guide 7th Edition Herbert Schildt full chapter instant download
Java: A Beginner’s Guide 7th Edition Herbert Schildt full chapter instant download
Herbert Schildt
Visit to download the full and correct content document:
https://ebookmass.com/product/java-a-beginners-guide-7th-edition-herbert-schildt/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...
https://ebookmass.com/product/java-a-beginners-guide-eighth-
edition-herbert-schildt/
https://ebookmass.com/product/java-a-beginners-guide-create-
compile-and-run-java-programs-today-9th-edition-herbert-schildt/
https://ebookmass.com/product/beginning-c-from-beginner-to-
pro-7th-edition-gonzalez-morris/
https://ebookmass.com/product/ocp-java-se-8-programmer-ii-exam-
guide-exam-1z0-809-7th-edition-kathy-sierra/
Beginning C: From Beginner to Pro, 7th Edition German
Gonzalez-Morris
https://ebookmass.com/product/beginning-c-from-beginner-to-
pro-7th-edition-german-gonzalez-morris/
https://ebookmass.com/product/linux-administration-a-beginners-
guide-7th-edition-wale-soyinka/
https://ebookmass.com/product/java-all-in-one-for-dummies-7th-
edition-doug-lowe/
https://ebookmass.com/product/english-file-beginner-teachers-
guide-for-speakers-of-spanish-fourth-edition-christina-latham-
koenig/
https://ebookmass.com/product/java-programming-a-comprehensive-
introduction-first-edition/
About the Author
Best-selling author Herbert Schildt has written extensively about programming for
over three decades and is a leading authority on the Java language. His books have
sold millions of copies worldwide and have been translated into all major foreign
languages. He is the author of numerous books on Java, including Java: The
Complete Reference, Herb Schildt’s Java Programming Cookbook, Introducing
JavaFX 8 Programming, and Swing: A Beginner’s Guide. He has also written
extensively about C, C++, and C#. Although interested in all facets of computing, his
primary focus is computer languages. Schildt holds both graduate and undergraduate
degrees from the University of Illinois. His website is www.HerbSchildt.com.
ISBN: 978-1-25-958932-4
MHID: 1-25-958932-3.
The material in this eBook also appears in the print version of this title: ISBN: 978-
1-25-958931-7, MHID: 1-25-958931-5.
All trademarks are trademarks of their respective owners. Rather than put a
trademark symbol after every occurrence of a trademarked name, we use names in an
editorial fashion only, and to the benefit of the trademark owner, with no intention of
infringement of the trademark. Where such designations appear in this book, they
have been printed with initial caps.
Oracle and Java are registered trademarks of Oracle Corporation and/or its affiliates.
All other trademarks are the property of their respective owners, and McGraw-Hill
Education makes no claim of ownership by the mention of products that contain
these marks.
TERMS OF USE
This is a copyrighted work and McGraw-Hill Education and its licensors reserve all
rights in and to the work. Use of this work is subject to these terms. Except as
permitted under the Copyright Act of 1976 and the right to store and retrieve one
copy of the work, you may not decompile, disassemble, reverse engineer, reproduce,
modify, create derivative works based upon, transmit, distribute, disseminate, sell,
publish or sublicense the work or any part of it without McGraw-Hill Education’s
prior consent. You may use the work for your own noncommercial and personal use;
any other use of the work is strictly prohibited. Your right to use the work may be
terminated if you fail to comply with these terms.
INTRODUCTION
1 Java Fundamentals
The Origins of Java
Java’s Lineage: C and C++
How Java Impacted the Internet
Java Simplified Web-Based Programming
Java Applets
Security
Portability
Java’s Magic: The Bytecode
Moving Beyond Applets
The Java Buzzwords
Object-Oriented Programming
Encapsulation
Polymorphism
Inheritance
Obtaining the Java Development Kit
A First Simple Program
Entering the Program
Compiling the Program
The First Sample Program Line by Line
Handling Syntax Errors
A Second Simple Program
Another Data Type
Try This 1-1: Converting Gallons to Liters
Two Control Statements
The if Statement
The for Loop
Create Blocks of Code
Semicolons and Positioning
Indentation Practices
Try This 1-2: Improving the Gallons-to-Liters Converter
The Java Keywords
Identifiers in Java
The Java Class Libraries
Chapter 1 Self Test
7 Inheritance
Inheritance Basics
Member Access and Inheritance
Constructors and Inheritance
Using super to Call Superclass Constructors
Using super to Access Superclass Members
Try This 7-1: Extending the Vehicle Class
Creating a Multilevel Hierarchy
When Are Constructors Executed?
Superclass References and Subclass Objects
Method Overriding
Overridden Methods Support Polymorphism
Why Overridden Methods?
Applying Method Overriding to TwoDShape
Using Abstract Classes
Using final
final Prevents Overriding
final Prevents Inheritance
Using final with Data Members
The Object Class
Chapter 7 Self Test
9 Exception Handling
The Exception Hierarchy
Exception Handling Fundamentals
Using try and catch
A Simple Exception Example
The Consequences of an Uncaught Exception
Exceptions Enable You to Handle Errors Gracefully
Using Multiple catch Statements
Catching Subclass Exceptions
Try Blocks Can Be Nested
Throwing an Exception
Rethrowing an Exception
A Closer Look at Throwable
Using finally
Using throws
Three Additional Exception Features
Java’s Built-in Exceptions
Creating Exception Subclasses
Try This 9-1: Adding Exceptions to the Queue Class
Chapter 9 Self Test
10 Using I/O
Java’s I/O Is Built upon Streams
Byte Streams and Character Streams
The Byte Stream Classes
The Character Stream Classes
The Predefined Streams
Using the Byte Streams
Reading Console Input
Writing Console Output
Reading and Writing Files Using Byte Streams
Inputting from a File
Writing to a File
Automatically Closing a File
Reading and Writing Binary Data
Try This 10-1: A File Comparison Utility
Random-Access Files
Using Java’s Character-Based Streams
Console Input Using Character Streams
Console Output Using Character Streams
File I/O Using Character Streams
Using a FileWriter
Using a FileReader
Using Java’s Type Wrappers to Convert Numeric Strings
Try This 10-2: Creating a Disk-Based Help System
Chapter 10 Self Test
11 Multithreaded Programming
Multithreading Fundamentals
The Thread Class and Runnable Interface
Creating a Thread
One Improvement and Two Simple Variations
Try This 11-1: Extending Thread
Creating Multiple Threads
Determining When a Thread Ends
Thread Priorities
Synchronization
Using Synchronized Methods
The synchronized Statement
Thread Communication Using notify( ), wait( ), and notifyAll( )
An Example That Uses wait( ) and notify( )
Suspending, Resuming, and Stopping Threads
Try This 11-2: Using the Main Thread
Chapter 11 Self Test
13 Generics
Generics Fundamentals
A Simple Generics Example
Generics Work Only with Reference Types
Generic Types Differ Based on Their Type Arguments
A Generic Class with Two Type Parameters
The General Form of a Generic Class
Bounded Types
Using Wildcard Arguments
Bounded Wildcards
Generic Methods
Generic Constructors
Generic Interfaces
Try This 13-1: Create a Generic Queue
Raw Types and Legacy Code
Type Inference with the Diamond Operator
Erasure
Ambiguity Errors
Some Generic Restrictions
Type Parameters Can’t Be Instantiated
Restrictions on Static Members
Generic Array Restrictions
Generic Exception Restriction
Continuing Your Study of Generics
Chapter 13 Self Test
15 Modules
Module Basics
A Simple Module Example
Compile and Run the First Module Example
A Closer Look at requires and exports
java.base and the Platform Modules
Legacy Code and the Unnamed Module
Exporting to a Specific Module
Using requires transitive
Try This 15-1: Experiment with requires transitive
Use Services
Service and Service Provider Basics
The Service-Based Keywords
A Module-Based Service Example
Additional Module Features
Open Modules
The opens Statement
requires static
Continuing Your Study of Modules
Chapter 15 Self Test
16 Introducing Swing
The Origins and Design Philosophy of Swing
Components and Containers
Components
Containers
The Top-Level Container Panes
Layout Managers
A First Simple Swing Program
The First Swing Example Line by Line
Swing Event Handling
Events
Event Sources
Event Listeners
Event Classes and Listener Interfaces
Use JButton
Work with JTextField
Create a JCheckBox
Work with JList
Try This 16-1: A Swing-Based File Comparison Utility
Use Anonymous Inner Classes or Lambda Expressions to Handle Events
Chapter 16 Self Test
17 Introducing JavaFX
JavaFX Basic Concepts
The JavaFX Packages
The Stage and Scene Classes
Nodes and Scene Graphs
Layouts
The Application Class and the Life-cycle Methods
Launching a JavaFX Application
A JavaFX Application Skeleton
Compiling and Running a JavaFX Program
The Application Thread
A Simple JavaFX Control: Label
Using Buttons and Events
Event Basics
Introducing the Button Control
Demonstrating Event Handling and the Button
Three More JavaFX Controls
CheckBox
Try This 17-1: Use the CheckBox Indeterminate State
ListView
TextField
Introducing Effects and Transforms
Effects
Transforms
Demonstrating Effects and Transforms
What Next?
Chapter 17 Self Test
D Introducing JShell
JShell Basics
List, Edit, and Rerun Code
Add a Method
Create a Class
Use an Interface
Evaluate Expressions and Use Built-in Variables
Importing Packages
Exceptions
Some More JShell Commands
Exploring JShell Further
Index
Introduction
T
he purpose of this book is to teach you the fundamentals of Java programming.
It uses a step-by-step approach complete with numerous examples, self tests,
and projects. It assumes no previous programming experience. The book starts
with the basics, such as how to compile and run a Java program. It then discusses the
keywords, features, and constructs that form the core of the Java language. You’ll
also find coverage of some of Java’s most advanced features, including
multithreaded programming, generics, lambda expressions, and modules. An
introduction to the fundamentals of Swing and JavaFX concludes the book. By the
time you finish, you will have a firm grasp of the essentials of Java programming.
It is important to state at the outset that this book is just a starting point. Java is
more than just the elements that define the language. Java also includes extensive
libraries and tools that aid in the development of programs. To be a top-notch Java
programmer implies mastery of these areas, too. After completing this book, you will
have the knowledge to pursue any and all other aspects of Java.
“Sir,—
“After carefully perusing the letter of your
correspondent, dated Scutari, in your impression of Wednesday
last, I perceive that, although the kitchen under the
superintendence of Miss Nightingale affords so much relief, the
system of management at the large one in the Barrack Hospital
is far from being perfect. I propose offering my services
gratuitously, and proceeding direct to Scutari at my own personal
expense, to regulate that important department, if the
Government will honour me with their confidence, and grant me
the full power of acting according to my knowledge and
experience in such matters.
“I have the honour to remain, sir,
“Your obedient servant,
“A. Soyer.”
It is the cause, and not the death, that makes the martyr.—
Napoleon.
Before many weeks had passed by, Miss Nightingale was again
called to mourn the loss of another of her helpers. The next claimed
by death was Sister Winifred, a Sister of Charity, who, with other
nuns from Ireland, was tending the Irish soldiers in the hospital at
Balaclava, to which they had recently come from Scutari and Kullali.
Only a few days after her arrival Sister Winifred was attacked by
cholera, which had broken out afresh at Balaclava.
Very touching is the account which Sister Mary Aloysius gives of
the death of her comrade: “Our third day in Balaclava was a very sad
one for us. One of our dear band, Sister Winifred, got very ill during
the night with cholera. She was a most angelic sister, and we were
all deeply grieved. She was attacked at about three o’clock in the
morning with the symptoms which were now so well known to us;
every remedy was applied; our beloved Rev. Mother never left her.
She was attended by Father Unsworth, from whom she received the
last rites of our holy religion; and she calmly breathed her last on the
evening of the same day. A hut was arranged in which to place the
remains; and so alarming were the rats—and such huge animals
were they—that we had to watch during the night so that they should
not touch her. She, the first to go of our little band (viz. the Roman
Catholic sisters), had been full of life and energy the day before. We
were all very sad, and we wondered who would be the next.”
A burial-place was found for Sister Winifred on a piece of ground
between two rocks, on the hills of Balaclava, where her remains
could repose without fear of desecration. The funeral formed a
contrast to that of the Protestant sister at Smyrna, but was equally
impressive. We can picture the sad cavalcade, distinguished by the
symbols of the Roman Catholic faith, wending its way up the hillside
to the lonely spot in the rocks above the Black Sea. Two priests
preceded the coffin, chanting the prayers, and the black-robed nuns
came closely behind, while soldiers and military and medical officers
followed.
Amongst the mourning band walked one tall, slight figure
dressed simply in black whose presence arrested attention. It was
Florence Nightingale, who had come to pay her tribute of love and
honour to the sister who, if divided by faith, had been united with her
in holy work and deeds of mercy.
A tribute was paid to the memory of Sister Winifred in a poem by
a friend, from which we quote the following verses:—
* * * * *
Yet far away from her convent grey, and far from her lowly cell,
And far from the soft and silvery tone of the sweet convent bell,
And far from the home she loved so well, and far from her native sky,
’Mid the cannon’s roar on a hostile shore she laid her down to die.
* * * * *
She went not forth to gain applause, she sought not empty fame;
E’en those she tended might not know her history or her name;
No honours waited on her path, no flattering voice was nigh;
For she only sought to toil and love, and ’mid her toil to die.
* * * * *
And most glorious its lot to point out to the stranger,
The hallowed remains of the sainted and blest;
For those angels of mercy that dared every danger
To bring to the soldier sweet comfort and rest.