Beginning Java 9 Fundamentals: Arrays, Objects, Modules, JShell, and Regular Expressions Sharan pdf download
Beginning Java 9 Fundamentals: Arrays, Objects, Modules, JShell, and Regular Expressions Sharan pdf download
https://textbookfull.com/product/beginning-java-9-fundamentals-
arrays-objects-modules-jshell-and-regular-expressions-sharan/
https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-
loucas/
https://textbookfull.com/product/java-language-features-with-
modules-streams-threads-i-o-and-lambda-expressions-2nd-edition-
kishori-sharan/
https://textbookfull.com/product/java-9-with-jshell-introducing-
the-full-range-of-java-9-s-new-features-via-jshell-1st-edition-
gaston-c-hillar/
https://textbookfull.com/product/java-9-revealed-for-early-
adoption-and-migration-1st-edition-kishori-sharan-auth/
JavaScript Regular Expressions 1st Edition Groner
Loiane Manricks Gabriel
https://textbookfull.com/product/javascript-regular-
expressions-1st-edition-groner-loiane-manricks-gabriel/
https://textbookfull.com/product/java-apis-extensions-and-
libraries-kishori-sharan/
https://textbookfull.com/product/regular-and-irregular-holonomic-
d-modules-london-mathematical-society-lecture-note-series-1st-
edition-masaki-kashiwara/
https://textbookfull.com/product/big-java-early-objects-7th-
edition-cay-s-horstmann/
https://textbookfull.com/product/java-9-modularity-revealed-
project-jigsaw-and-scalable-java-applications-alexandru-jecan/
Beginning Java 9
Fundamentals
Arrays, Objects, Modules, JShell,
and Regular Expressions
—
Second Edition
—
Kishori Sharan
Beginning Java 9
Fundamentals
Arrays, Objects, Modules, JShell,
and Regular Expressions
Second Edition
Kishori Sharan
Beginning Java 9 Fundamentals: Arrays, Objects, Modules, JShell, and Regular Expressions
Kishori Sharan
Montgomery, Alabama, USA
ISBN-13 (pbk): 978-1-4842-2843-2 ISBN-13 (electronic): 978-1-4842-2902-6
https://doi.org/10.1007/978-1-4842-2902-6
Library of Congress Control Number: 2017958824
Copyright © 2017 by Kishori Sharan
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage
and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or
hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material
contained herein.
Cover image by Freepik (www.freepik.com)
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Steve Anglin
Development Editor: Matthew Moodie
Technical Reviewer: Wallace Jackson
Coordinating Editor: Mark Powers
Copy Editor: Kezia Endsley
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC
and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected], or visit http://www.apress.com/
rights-permissions.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web
page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers
on GitHub via the book’s product page, located at www.apress.com/9781484228432. For more detailed
information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
Contents at a Glance
■
■Chapter 1: Programming Concepts����������������������������������������������������������������������� 1
■
■Chapter 2: Setting Up the Environment��������������������������������������������������������������� 33
■
■Chapter 3: Writing Java Programs���������������������������������������������������������������������� 45
■
■Chapter 4: Data Types������������������������������������������������������������������������������������������ 99
■
■Chapter 5: Operators����������������������������������������������������������������������������������������� 145
■
■Chapter 6: Statements��������������������������������������������������������������������������������������� 191
■
■Chapter 7: Classes��������������������������������������������������������������������������������������������� 223
■
■Chapter 8: Methods������������������������������������������������������������������������������������������� 255
■
■Chapter 9: Constructors������������������������������������������������������������������������������������ 323
■
■Chapter 10: Modules����������������������������������������������������������������������������������������� 355
■
■Chapter 11: Object and Objects Classes������������������������������������������������������������ 395
■
■Chapter 12: Wrapper Classes���������������������������������������������������������������������������� 439
■
■Chapter 13: Exception Handling������������������������������������������������������������������������ 461
■
■Chapter 14: Assertions�������������������������������������������������������������������������������������� 511
■
■Chapter 15: Strings������������������������������������������������������������������������������������������� 521
iii
■ Contents at a Glance
■
■Chapter 16: Dates and Times����������������������������������������������������������������������������� 549
■
■Chapter 17: Formatting Data����������������������������������������������������������������������������� 631
■
■Chapter 18: Regular Expressions���������������������������������������������������������������������� 669
■
■Chapter 19: Arrays�������������������������������������������������������������������������������������������� 701
■
■Chapter 20: Inheritance������������������������������������������������������������������������������������� 755
■
■Chapter 21: Interfaces��������������������������������������������������������������������������������������� 823
■
■Chapter 22: Enum Types������������������������������������������������������������������������������������ 895
■
■Chapter 23: Java Shell��������������������������������������������������������������������������������������� 921
■
■Appendix A: Character Encodings��������������������������������������������������������������������� 985
■
■Appendix B: Documentation Comments������������������������������������������������������������ 997
Index������������������������������������������������������������������������������������������������������������������� 1023
iv
Contents
■
■Chapter 1: Programming Concepts����������������������������������������������������������������������� 1
What Is Programming?����������������������������������������������������������������������������������������������������� 1
Components of a Programming Language����������������������������������������������������������������������� 4
Programming Paradigms�������������������������������������������������������������������������������������������������� 4
Imperative Paradigm������������������������������������������������������������������������������������������������������������������������������ 6
Procedural Paradigm������������������������������������������������������������������������������������������������������������������������������ 6
Declarative Paradigm����������������������������������������������������������������������������������������������������������������������������� 7
Functional Paradigm������������������������������������������������������������������������������������������������������������������������������� 8
Logic Paradigm��������������������������������������������������������������������������������������������������������������������������������������� 8
Object-Oriented Paradigm���������������������������������������������������������������������������������������������������������������������� 9
What Is Java?����������������������������������������������������������������������������������������������������������������� 12
The Object-Oriented Paradigm and Java������������������������������������������������������������������������ 13
Abstraction������������������������������������������������������������������������������������������������������������������������������������������� 14
Encapsulation and Information Hiding�������������������������������������������������������������������������������������������������� 23
Inheritance�������������������������������������������������������������������������������������������������������������������������������������������� 25
Polymorphism��������������������������������������������������������������������������������������������������������������������������������������� 26
Summary������������������������������������������������������������������������������������������������������������������������ 31
■
■Chapter 2: Setting Up the Environment��������������������������������������������������������������� 33
System Requirements���������������������������������������������������������������������������������������������������� 33
Installing JDK 9�������������������������������������������������������������������������������������������������������������� 33
v
■ Contents
vi
■ Contents
vii
■ Contents
NaN����������������������������������������������������������������������������������������������������������������������������������������������������� 135
Denormals������������������������������������������������������������������������������������������������������������������������������������������ 136
viii
■ Contents
ix
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 251
x
■ Contents
■
■Chapter 8: Methods������������������������������������������������������������������������������������������� 255
What Is a Method?������������������������������������������������������������������������������������������������������� 255
Declaring Methods of a Class��������������������������������������������������������������������������������������� 255
Local Variables������������������������������������������������������������������������������������������������������������� 260
Rule #1����������������������������������������������������������������������������������������������������������������������������������������������� 260
Rule #2����������������������������������������������������������������������������������������������������������������������������������������������� 261
Rule #3����������������������������������������������������������������������������������������������������������������������������������������������� 261
Rule #4����������������������������������������������������������������������������������������������������������������������������������������������� 261
xi
■ Contents
■
■Chapter 9: Constructors������������������������������������������������������������������������������������ 323
What Is a Constructor?������������������������������������������������������������������������������������������������� 323
Declaring a Constructor����������������������������������������������������������������������������������������������� 323
Overloading a Constructor�������������������������������������������������������������������������������������������� 326
Writing Code for a Constructor������������������������������������������������������������������������������������� 327
Calling a Constructor from Another Constructor���������������������������������������������������������� 330
Using a return Statement Inside a Constructor������������������������������������������������������������ 332
Access Level Modifier for a Constructor���������������������������������������������������������������������� 333
Default Constructor������������������������������������������������������������������������������������������������������ 337
A static Constructor������������������������������������������������������������������������������������������������������ 338
Instance Initialization Block����������������������������������������������������������������������������������������� 338
static Initialization Block���������������������������������������������������������������������������������������������� 339
The final Keyword�������������������������������������������������������������������������������������������������������� 341
final Local Variables���������������������������������������������������������������������������������������������������������������������������� 342
final Parameters��������������������������������������������������������������������������������������������������������������������������������� 343
final Instance Variables���������������������������������������������������������������������������������������������������������������������� 343
final Class Variables��������������������������������������������������������������������������������������������������������������������������� 346
final Reference Variables�������������������������������������������������������������������������������������������������������������������� 346
Compile-Time vs. Runtime final Variables������������������������������������������������������������������������������������������ 347
xii
■ Contents
xiii
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 435
■
■Chapter 12: Wrapper Classes���������������������������������������������������������������������������� 439
Wrapper Classes���������������������������������������������������������������������������������������������������������� 439
Numeric Wrapper Classes������������������������������������������������������������������������������������������������������������������ 442
The Character Wrapper Class������������������������������������������������������������������������������������������������������������� 445
The Boolean Wrapper Class���������������������������������������������������������������������������������������������������������������� 447
xiv
■ Contents
xv
■ Contents
xvi
■ Contents
xvii
■ Contents
xviii
■ Contents
xix
■ Contents
Summary���������������������������������������������������������������������������������������������������������������������� 750
■
■Chapter 20: Inheritance������������������������������������������������������������������������������������� 755
What Is Inheritance?���������������������������������������������������������������������������������������������������� 755
Inheriting Classes��������������������������������������������������������������������������������������������������������� 756
The Object Class Is the Default Superclass������������������������������������������������������������������ 759
Inheritance and Hierarchical Relationship������������������������������������������������������������������� 759
What Is Inherited by a Subclass?��������������������������������������������������������������������������������� 760
Upcasting and Downcasting����������������������������������������������������������������������������������������� 762
The instanceof Operator����������������������������������������������������������������������������������������������� 766
xx
■ Contents
Binding������������������������������������������������������������������������������������������������������������������������� 768
Early Binding�������������������������������������������������������������������������������������������������������������������������������������� 769
Late Binding���������������������������������������������������������������������������������������������������������������������������������������� 772
xxi
■ Contents
xxii
■ Contents
xxiii
■ Contents
xxiv
■ Contents
Index������������������������������������������������������������������������������������������������������������������� 1023
xxv
About the Author
xxvii
About the Technical Reviewer
Wallace Jackson has been writing for leading multimedia publications about his work in new media content
development since the advent of Multimedia Producer Magazine nearly two decades ago. He has authored
a half-dozen Android book titles for Apress, including four titles in the popular Pro Android series. Wallace
received his undergraduate degree in business economics from the University of California at Los Angeles
and a graduate degree in MIS design and implementation from the University of Southern California. He is
currently the CEO of Mind Taffy Design, a new media content production and digital campaign design and
development agency.
xxix
Acknowledgments
I would like to thank my family members and friends for their encouragement and support: my mom
Pratima Devi; my elder brothers, Janki Sharan and Dr. Sita Sharan; my nephews, Gaurav and Saurav;
my sister Ratna; my friends Karthikeya Venkatesan, Rahul Nagpal, Ravi Datla, Mahbub Choudhury,
Richard Castillo; and many more friends not mentioned here.
My wife, Ellen, was always patient when I spent long hours at my computer desk working on this book.
I want to thank her for all of her support in writing this book.
My special thanks to my friend Preethi Vasudev for offering her valuable time for providing solutions
to the exercises in this book. She likes programming challenges—particularly Google Code Jam. I bet she
enjoyed solving the exercises in each chapter of this book.
My sincere thanks are due to the wonderful team at Apress for their support during the publication of
this book. Thanks to Mark Powers, the Editorial Operations Manager, for providing excellent support. Last
but not least, my sincere thanks to Steve Anglin, the Lead Editor at Apress, for taking the initiative for the
publication of this book.
xxxi
Another Random Scribd Document
with Unrelated Content
South Carolina—Mr. Kean, aye; Mr. Huger, aye.
Georgia—Mr. Few, aye; Mr. Pierce, aye.
So it was resolved in the affirmative." (Page 754, volume 4.)
I do not quote this passage for any thing that I now see out of
place in that peroration; but for a quite different purpose—for the
purpose of showing that I was slow to believe in any design to
subvert this Union—that at the time of this great debate (February
and March, 1830) I positively discredited it, and publicly proclaimed
my incredulity. I did not want to believe it. I repulsed the belief. I
pushed aside every circumstance that Mr. Webster relied on, and
softened every expression that Mr. Hayne used, and considered him
as limiting (practically) his threatened resistance to the tariff act, to
the kind of resistance which Virginia made to the alien and sedition
laws—which was an appeal to the reason, judgment and feelings of
the other States—and which had its effect in the speedy repeal of
those laws. Mr. Calhoun had not then uncovered his position in
relation to nullification. I knew that Mr. Webster was speaking at him
in all that he said to Mr. Hayne: but I would believe nothing against
him except upon his own showing, or undoubted evidence. Although
not a favorite statesman with me, I felt admiration for his high
intellectual endowments, and respect for the integrity and purity of
his private life. Mr. Hayne I cordially loved; and believed, and still
believe, in the loyalty of his intentions to the Union. They were both
from the South—that sister Carolina, of which the other was my
native State, and in both of which I have relatives and hereditary
friends—and for which I still have the affections which none but the
wicked ever lose for the land of their birth: and I felt as they did in
all that relates to the tariff—except their remedy. But enough for the
present. The occasion will come, when we arrive at the practical
application of the modern nullification doctrine, to vindicate the
constitution from the political solecism of containing within itself a
suicidal principle, and to vindicate the Virginia resolutions, and their
authors (and, in their own language), from the "anarchical and
preposterous" interpretation which has been put upon their words.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
textbookfull.com