100% found this document useful (2 votes)
35 views63 pages

Complete Java 9 Recipes: A Problem-Solution Approach 3rd Edition Josh Juneau PDF For All Chapters

ebook

Uploaded by

eszhanjurisa
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
100% found this document useful (2 votes)
35 views63 pages

Complete Java 9 Recipes: A Problem-Solution Approach 3rd Edition Josh Juneau PDF For All Chapters

ebook

Uploaded by

eszhanjurisa
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/ 63

Full download textbook at textbookfull.

com

Java 9 Recipes: A Problem-Solution Approach


3rd Edition Josh Juneau

https://textbookfull.com/product/java-9-recipes-a-
problem-solution-approach-3rd-edition-josh-juneau/

Download more textbook from https://textbookfull.com


More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Java EE 7 Recipes A Problem Solution Approach 1st


Edition Juneau Josh

https://textbookfull.com/product/java-ee-7-recipes-a-problem-
solution-approach-1st-edition-juneau-josh/

Java 7 Recipes A Problem Solution Approach Juneau Josh


Beaty Mark Dea Carl Guime Freddy Oconner John

https://textbookfull.com/product/java-7-recipes-a-problem-
solution-approach-juneau-josh-beaty-mark-dea-carl-guime-freddy-
oconner-john/

Java 8 Recipes 2nd Edition Josh Juneau

https://textbookfull.com/product/java-8-recipes-2nd-edition-josh-
juneau/

MATLAB Machine Learning Recipes: A Problem-Solution


Approach 3rd Edition Michael Paluszek

https://textbookfull.com/product/matlab-machine-learning-recipes-
a-problem-solution-approach-3rd-edition-michael-paluszek/
Android Recipes A Problem-Solution Approach Dave Smith

https://textbookfull.com/product/android-recipes-a-problem-
solution-approach-dave-smith/

Raku Recipes: A Problem-Solution Approach J.J. Merelo

https://textbookfull.com/product/raku-recipes-a-problem-solution-
approach-j-j-merelo/

C Recipes - A Problem-Solution Approach 1st Edition


Shirish Chavan

https://textbookfull.com/product/c-recipes-a-problem-solution-
approach-1st-edition-shirish-chavan/

JavaScript Recipes: A Problem-Solution Approach 1st


Edition Russ Ferguson

https://textbookfull.com/product/javascript-recipes-a-problem-
solution-approach-1st-edition-russ-ferguson/

wxPython Recipes: A Problem - Solution Approach 1st


Edition Mike Driscoll

https://textbookfull.com/product/wxpython-recipes-a-problem-
solution-approach-1st-edition-mike-driscoll/
Java 9
Recipes
A Problem-Solution Approach

Third Edition

Josh Juneau
Java 9 Recipes
A Problem-Solution Approach

Third Edition

Josh Juneau
Java 9 Recipes: A Problem-Solution Approach
Josh Juneau
Hinckley, Illinois, USA
ISBN-13 (pbk): 978-1-4842-1975-1 ISBN-13 (electronic): 978-1-4842-1976-8
DOI 10.1007/978-1-4842-1976-8
Library of Congress Control Number: 2017943502
Copyright © 2017 by Josh Juneau
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.
Managing Director: Welmoed Spahr
Editorial Director: Todd Green
Acquisitions Editor: Jonathan Gennick
Development Editor: Laura Berendson
Technical Reviewer: Vinay Kumar
Coordinating Editor: Jill Balzano
Copy Editor: Brendan Frost
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
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/9781484219751. For more
detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
This book is dedicated to my wife and children.
Contents at a Glance

About the Author�������������������������������������������������������������������������������������������������� xliii


About the Technical Reviewer��������������������������������������������������������������������������������xlv
Acknowledgments������������������������������������������������������������������������������������������������xlvii
Introduction�����������������������������������������������������������������������������������������������������������xlix


■Chapter 1: Getting Started with Java 9����������������������������������������������������������������� 1

■Chapter 2: Java 9 Enhancements������������������������������������������������������������������������ 35

■Chapter 3: Strings����������������������������������������������������������������������������������������������� 47

■Chapter 4: Numbers and Dates���������������������������������������������������������������������������� 65

■Chapter 5: Object-Oriented Java������������������������������������������������������������������������� 99

■Chapter 6: Lambda Expressions������������������������������������������������������������������������ 137

■Chapter 7: Data Sources and Collections���������������������������������������������������������� 159

■Chapter 8: Input and Output������������������������������������������������������������������������������ 195

■Chapter 9: Exceptions and Logging������������������������������������������������������������������� 221

■Chapter 10: Concurrency����������������������������������������������������������������������������������� 239

■Chapter 11: Debugging and Unit Testing����������������������������������������������������������� 267

■Chapter 12: Unicode, Internationalization, and Currency Codes����������������������� 285

■Chapter 13: Working with Databases���������������������������������������������������������������� 305

■Chapter 14: JavaFX Fundamentals�������������������������������������������������������������������� 355

■Chapter 15: Graphics with JavaFX�������������������������������������������������������������������� 429

■Chapter 16: Media with JavaFX������������������������������������������������������������������������� 471

v
■ Contents at a Glance


■Chapter 17: Java Web Applications with JavaServer Faces������������������������������ 499

■Chapter 18: Nashorn and Scripting������������������������������������������������������������������� 529

■Chapter 19: E-mail��������������������������������������������������������������������������������������������� 553

■Chapter 20: JSON and XML Processing������������������������������������������������������������� 563

■Chapter 21: Networking������������������������������������������������������������������������������������ 585

■Chapter 22: Java Modularity����������������������������������������������������������������������������� 605

Index��������������������������������������������������������������������������������������������������������������������� 615

vi
Contents

About the Author�������������������������������������������������������������������������������������������������� xliii


About the Technical Reviewer��������������������������������������������������������������������������������xlv
Acknowledgments������������������������������������������������������������������������������������������������xlvii
Introduction�����������������������������������������������������������������������������������������������������������xlix


■Chapter 1: Getting Started with Java 9����������������������������������������������������������������� 1
1-1. Creating a Development Environment���������������������������������������������������������������������� 1
Problem�������������������������������������������������������������������������������������������������������������������������������������������������� 1
Solution�������������������������������������������������������������������������������������������������������������������������������������������������� 1
How It Works������������������������������������������������������������������������������������������������������������������������������������������� 2
1-2. Getting to “Hello, World”������������������������������������������������������������������������������������������� 3
Problem�������������������������������������������������������������������������������������������������������������������������������������������������� 3
Solution�������������������������������������������������������������������������������������������������������������������������������������������������� 3
How It Works������������������������������������������������������������������������������������������������������������������������������������������� 7
1-3. Configuring the CLASSPATH�������������������������������������������������������������������������������������� 9
Problem�������������������������������������������������������������������������������������������������������������������������������������������������� 9
Solution�������������������������������������������������������������������������������������������������������������������������������������������������� 9
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 10
1-4. Organizing Code with Packages����������������������������������������������������������������������������� 11
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 11
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 11
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 12
1-5. Declaring Variables and Access Modifiers�������������������������������������������������������������� 14
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 14
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 14
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 16
vii
■ Contents

1-6. Compiling and Executing from the Command-Line or Terminal Interpreter����������� 17


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 17
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 17
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 18

1-7. Developing Within the Interactive jShell����������������������������������������������������������������� 19


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 19
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 20
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 22

1-8. Converting to and from a String������������������������������������������������������������������������������ 24


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 24
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 24
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 24

1-9. Passing Arguments via Command-Line Execution������������������������������������������������� 25


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 25
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 25
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 26

1-10. Executing a Script via the jShell��������������������������������������������������������������������������� 27


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 27
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 27
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 27

1-11. Accepting Input from the Keyboard���������������������������������������������������������������������� 28


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 28
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 28
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 29

1-12. Documenting Your Code���������������������������������������������������������������������������������������� 30


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 30
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 30
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 31

viii
■ Contents

1-13. Reading Environment Variables���������������������������������������������������������������������������� 33


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 33
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 33
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 34

Summary������������������������������������������������������������������������������������������������������������������������ 34

■Chapter 2: Java 9 Enhancements������������������������������������������������������������������������ 35
2-1. Avoiding Redundancy in Interface Code����������������������������������������������������������������� 35
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 35
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 35
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 36

2-2. Creating Modules for Simplifying and Code Reuse������������������������������������������������� 36


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 36
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 36
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 38

2-3. Easily Retrieving Information on OS Processes������������������������������������������������������ 38


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 38
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 38
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 40

2-4. Handling Errors with Ease�������������������������������������������������������������������������������������� 40


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 40
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 41
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 41

2-5. Filtering Data Before and After a Condition with Streams�������������������������������������� 42


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 42
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 42
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 42

2-6. Developing a Concise HTTP Client�������������������������������������������������������������������������� 43


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 43
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 43
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 44

ix
■ Contents

2-7. Redirecting Platform Logs�������������������������������������������������������������������������������������� 44


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 44
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 44
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 45

2-8. Utilizing Factory Methods to Create Immutable Collections����������������������������������� 45


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 45
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 45
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 46

Summary������������������������������������������������������������������������������������������������������������������������ 46

■Chapter 3: Strings����������������������������������������������������������������������������������������������� 47
Compact Strings: Java 9 String Enhancements������������������������������������������������������������� 47
3-1. Obtaining a Subsection of a String������������������������������������������������������������������������� 47
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 47
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 47
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 48

3-2. Comparing Strings�������������������������������������������������������������������������������������������������� 48


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 48
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 48
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 50

3-3. Trimming Whitespace��������������������������������������������������������������������������������������������� 51


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 51
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 51
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 52

3-4. Changing the Case of a String�������������������������������������������������������������������������������� 52


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 52
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 52
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 52

3-5. Concatenating Strings�������������������������������������������������������������������������������������������� 53


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 53
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 53

x
■ Contents

Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 53
Solution 3��������������������������������������������������������������������������������������������������������������������������������������������� 54
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 54

3-6. Converting Strings to Numeric Values�������������������������������������������������������������������� 55


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 55
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 55
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 55
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 55

3-7. Iterating Over the Characters of a String���������������������������������������������������������������� 56


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 56
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 56
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 57

3-8. Finding Text Matches���������������������������������������������������������������������������������������������� 58


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 58
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 58
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 59
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 59

3-9. Replacing All Text Matches������������������������������������������������������������������������������������� 60


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 60
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 61
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 61
3-10. Determining Whether a File Suffix Matches a Given String���������������������������������� 61
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 61
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 62
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 62

3-11. Making a String That Can Contain Dynamic Information�������������������������������������� 62


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 62
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 62
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 63
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 63

Summary������������������������������������������������������������������������������������������������������������������������ 64

xi
■ Contents


■Chapter 4: Numbers and Dates���������������������������������������������������������������������������� 65
4-1. Rounding Float and Double Values to Integers������������������������������������������������������� 66
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 66
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 66
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 66

4-2. Formatting Double and Long Decimal Values��������������������������������������������������������� 67


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 67
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 67
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 68
4-3. Comparing int Values���������������������������������������������������������������������������������������������� 69
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 69
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 69
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 69
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 70

4-4. Comparing Floating-Point Numbers������������������������������������������������������������������������ 70


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 70
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 70
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 71
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 71

4-5. Calculating Monetary Values���������������������������������������������������������������������������������� 71


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 71
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 71
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 72
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 73

4-6. Randomly Generating Values���������������������������������������������������������������������������������� 74


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 74
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 74
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 75
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 75

xii
■ Contents

4-7. Obtaining the Current Date Without Time��������������������������������������������������������������� 76


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 76
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 76
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 76

4-8. Obtaining a Date Object Given Date Criteria����������������������������������������������������������� 76


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 76
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 76
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 77

4-9. Obtaining a Year-Month-Day Date Combination������������������������������������������������������ 77


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 77
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 77
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 77
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 78

4-10. Obtaining and Calculating Times Based on the Current Time������������������������������� 78


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 78
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 78
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 79

4-11. Obtaining and Using the Date and Time Together������������������������������������������������� 80


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 80
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 80
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 82
Solution 3��������������������������������������������������������������������������������������������������������������������������������������������� 82
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 83

4-12. Obtaining a Machine Timestamp�������������������������������������������������������������������������� 84


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 84
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 84
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 85

4-13. Converting Dates and Times Based on the Time Zone������������������������������������������ 85


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 85
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 85
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 87

xiii
■ Contents

4-14. Comparing Two Dates������������������������������������������������������������������������������������������� 88


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 88
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 88
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 89

4-15. Finding the Interval Between Dates and Times���������������������������������������������������� 89


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 89
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 89
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 90
Solution 3��������������������������������������������������������������������������������������������������������������������������������������������� 91
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 91

4-16. Obtaining Date-Time from a Specified String������������������������������������������������������� 92


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 92
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 92
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 93

4-17. Formatting Dates for Display�������������������������������������������������������������������������������� 94


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 94
Solution 1��������������������������������������������������������������������������������������������������������������������������������������������� 94
Solution 2��������������������������������������������������������������������������������������������������������������������������������������������� 94
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 95

4-18. Writing Readable Numeric Literals����������������������������������������������������������������������� 97


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 97
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 97
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 97

4-19. Declaring Binary Literals��������������������������������������������������������������������������������������� 97


Problem������������������������������������������������������������������������������������������������������������������������������������������������ 97
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 98
How It Works����������������������������������������������������������������������������������������������������������������������������������������� 98

Summary������������������������������������������������������������������������������������������������������������������������ 98

xiv
■ Contents


■Chapter 5: Object-Oriented Java������������������������������������������������������������������������� 99
5-1. Controlling Access to Members of a Class�������������������������������������������������������������� 99
Problem������������������������������������������������������������������������������������������������������������������������������������������������ 99
Solution������������������������������������������������������������������������������������������������������������������������������������������������ 99
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 100

5-2. Making Private Fields Accessible to Other Classes���������������������������������������������� 100


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 100
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 100
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 100
5-3. Creating a Class with a Single Instance��������������������������������������������������������������� 101
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 101
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 101
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 103
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 103

5-4. Generating Instances of a Class��������������������������������������������������������������������������� 104


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 104
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 104
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 106

5-5. Creating Reusable Objects������������������������������������������������������������������������������������ 106


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 106
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 106
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 107

5-6. Defining an Interface for a Class�������������������������������������������������������������������������� 108


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 108
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 108
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 108

5-7. Modifying Interfaces Without Breaking Existing Code������������������������������������������ 110


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 110
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 110
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 111

xv
■ Contents

5-8. Constructing Instances of the Same Class with Different Values������������������������� 112
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 112
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 112
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 115

5-9. Interacting with a Class via Interfaces������������������������������������������������������������������ 116


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 116
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 116
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 116

5-10. Making a Class Cloneable����������������������������������������������������������������������������������� 117


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 117
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 117
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 121

5-11. Comparing Objects��������������������������������������������������������������������������������������������� 121


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 121
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 121
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 122
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 125

5-12. Extending the Functionality of a Class���������������������������������������������������������������� 126


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 126
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 126
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 129

5-13. Defining a Template for Classes to Extend��������������������������������������������������������� 129


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 129
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 129
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 130

5-14. Increasing Class Encapsulation�������������������������������������������������������������������������� 131


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 131
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 131
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 134

Summary���������������������������������������������������������������������������������������������������������������������� 136

xvi
■ Contents


■Chapter 6: Lambda Expressions������������������������������������������������������������������������ 137
6-1. Writing a Simple Lambda Expression������������������������������������������������������������������� 137
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 137
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 137
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 138

6-2. Enabling the Use of Lambda Expressions������������������������������������������������������������� 140


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 140
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 140
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 140
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 141
6-3. Invoking Existing Methods by Name��������������������������������������������������������������������� 143
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 143
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 144
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 145

6-4. Sorting with Fewer Lines of Code������������������������������������������������������������������������� 147


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 147
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 148
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 148
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 149

6-5. Filtering a Collection of Data��������������������������������������������������������������������������������� 149


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 149
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 150
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 150

6-6. Implementing Runnable���������������������������������������������������������������������������������������� 150


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 150
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 150
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 151

6-7. Replacing Anonymous Inner Classes�������������������������������������������������������������������� 151


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 151
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 151
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 152

xvii
■ Contents

6-8. Accessing Class Variables from a Lambda Expression����������������������������������������� 153


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 153
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 153
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 154

6-9. Passing Lambda Expressions to Methods������������������������������������������������������������ 155


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 155
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 155
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 157

Summary���������������������������������������������������������������������������������������������������������������������� 157

■Chapter 7: Data Sources and Collections���������������������������������������������������������� 159
7-1. Defining a Fixed Set of Related Constants������������������������������������������������������������ 159
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 159
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 159
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 161

7-2. Designing Intelligent Constants���������������������������������������������������������������������������� 162


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 162
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 162
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 165

7-3. Executing Code Based on a Specified Value��������������������������������������������������������� 166


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 166
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 166
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 169

7-4. Working with Fix-Sized Arrays������������������������������������������������������������������������������ 170


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 170
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 170
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 172

7-5. Safely Enabling Types or Methods to Operate on Objects of Various Types���������� 174
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 174
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 175
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 176

xviii
■ Contents

7-6. Working with Dynamic Arrays������������������������������������������������������������������������������� 180


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 180
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 180
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 182

7-7. Making Your Objects Iterable�������������������������������������������������������������������������������� 183


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 183
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 183
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 185

7-8. Iterating Over Collections�������������������������������������������������������������������������������������� 186


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 186
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 186
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 188

7-9. Iterating Over a Map��������������������������������������������������������������������������������������������� 189


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 189
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 189
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 190

7-10. Executing Streams in Parallel����������������������������������������������������������������������������� 192


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 192
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 192
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 193

Summary���������������������������������������������������������������������������������������������������������������������� 193

■Chapter 8: Input and Output������������������������������������������������������������������������������ 195
8-1. Serializing Java Objects���������������������������������������������������������������������������������������� 196
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 196
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 196
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 197

8-2. Serializing Java Objects More Efficiently�������������������������������������������������������������� 199


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 199
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 199
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 199

xix
■ Contents

8-3. Serializing Java Objects as XML��������������������������������������������������������������������������� 200


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 200
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 200
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 201

8-4. Creating a Socket Connection and Sending Serializable Objects


Across the Wire����������������������������������������������������������������������������������������������������� 202
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 202
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 202
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 204

8-5. Obtaining the Java Execution Path����������������������������������������������������������������������� 205


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 205
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 205
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 205

8-6. Copying a File������������������������������������������������������������������������������������������������������� 205


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 205
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 206
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 206

8-7. Moving a File�������������������������������������������������������������������������������������������������������� 206


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 206
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 206
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 207

8-8. Creating a Directory���������������������������������������������������������������������������������������������� 207


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 207
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 207
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 207
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 208

8-9. Iterating Over Files in a Directory������������������������������������������������������������������������� 208


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 208
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 208
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 209

xx
■ Contents

8-10. Querying (and Setting) File Metadata����������������������������������������������������������������� 209


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 209
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 209
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 210

8-11. Monitoring a Directory for Content Changes������������������������������������������������������ 211


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 211
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 211
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 212

8-12. Reading Property Files���������������������������������������������������������������������������������������� 212


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 212
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 213
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 214

8-13. Uncompressing Files������������������������������������������������������������������������������������������ 214


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 214
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 214
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 215

8-14. Managing Operating System Processes������������������������������������������������������������� 216


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 216
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 216
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 217

Summary���������������������������������������������������������������������������������������������������������������������� 219

■Chapter 9: Exceptions and Logging������������������������������������������������������������������� 221
9-1. Catching Exceptions��������������������������������������������������������������������������������������������� 222
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 222
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 222
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 223

9-2. Guaranteeing a Block of Code Is Executed����������������������������������������������������������� 223


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 223
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 224
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 224

xxi
■ Contents

9-3. Throwing Exceptions��������������������������������������������������������������������������������������������� 224


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 224
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 225
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 225

9-4. Catching Multiple Exceptions������������������������������������������������������������������������������� 225


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 225
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 225
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 226
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 226

9-5. Catching the Uncaught Exceptions����������������������������������������������������������������������� 227


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 227
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 227
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 227
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 228

9-6. Managing Resources with try/catch Blocks��������������������������������������������������������� 228


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 228
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 228
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 229

9-7. Creating an Exception Class��������������������������������������������������������������������������������� 229


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 229
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 229
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 230
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 230

9-8. Rethrowing the Caught Exception������������������������������������������������������������������������ 230


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 230
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 230
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 231

9-9. Logging Events Within Your Application���������������������������������������������������������������� 231


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 231
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 231
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 232

xxii
■ Contents

9-10. Rotating and Purging Logs���������������������������������������������������������������������������������� 233


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 233
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 233
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 233

9-11. Logging Exceptions��������������������������������������������������������������������������������������������� 234


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 234
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 234
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 235

9-12. Logging with the Unified JVM Logger����������������������������������������������������������������� 235


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 235
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 235
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 236

Summary���������������������������������������������������������������������������������������������������������������������� 237

■Chapter 10: Concurrency����������������������������������������������������������������������������������� 239
10-1. Starting a Background Task�������������������������������������������������������������������������������� 239
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 239
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 239
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 240

10-2. Updating (and Iterating) a Map��������������������������������������������������������������������������� 240


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 240
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 241
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 241

10-3. Inserting a Key into a Map Only If the Key Is Not Already Present���������������������� 242
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 242
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 242
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 243

10-4. Iterating Through a Changing Collection������������������������������������������������������������� 244


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 244
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 244
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 244
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 244

xxiii
■ Contents

10-5. Coordinating Different Collections���������������������������������������������������������������������� 245


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 245
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 245
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 246
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 247

10-6. Splitting Work into Separate Threads����������������������������������������������������������������� 249


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 249
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 249
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 249

10-7. Coordinating Threads������������������������������������������������������������������������������������������ 250


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 250
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 250
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 251
Solution 3������������������������������������������������������������������������������������������������������������������������������������������� 252
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 253

10-8. Creating Thread-Safe Objects����������������������������������������������������������������������������� 255


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 255
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 255
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 256
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 256

10-9. Implementing Thread-Safe Counters������������������������������������������������������������������ 257


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 257
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 257
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 257

10-10. Breaking Down Tasks into Discrete Units of Work�������������������������������������������� 258


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 258
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 258
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 260

xxiv
■ Contents

10-11. Updating a Common Value Across Multiple Threads����������������������������������������� 261


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 261
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 261
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 263

10-12. Executing Multiple Tasks Asynchronously�������������������������������������������������������� 264


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 264
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 264
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 265

Summary���������������������������������������������������������������������������������������������������������������������� 266

■Chapter 11: Debugging and Unit Testing����������������������������������������������������������� 267
11-1. Understanding Exceptions���������������������������������������������������������������������������������� 267
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 267
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 267
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 268

11-2. Locking Down Behavior of Your Classes������������������������������������������������������������� 268


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 268
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 269
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 270

11-3. Scripting Your Unit Tests������������������������������������������������������������������������������������� 270


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 270
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 271
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 273

11-4. Finding Bugs Early���������������������������������������������������������������������������������������������� 273


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 273
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 274
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 275

11-5. Monitoring Garbage Collection in Your Application��������������������������������������������� 276


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 276
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 276
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 276
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 278

xxv
■ Contents

11-6. Obtaining a Thread Dump����������������������������������������������������������������������������������� 278


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 278
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 278
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 284


■Chapter 12: Unicode, Internationalization, and Currency Codes����������������������� 285
12-1. Converting Unicode Characters to Digits������������������������������������������������������������ 285
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 285
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 285
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 287

12-2. Creating and Working with Locales�������������������������������������������������������������������� 287


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 287
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 287
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 290

12-3. Setting the Default Locale���������������������������������������������������������������������������������� 291


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 291
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 291
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 292

12-4. Matching and Filtering Locales��������������������������������������������������������������������������� 293


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 293
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 293
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 295

12-5. Searching Unicode with Regular Expressions���������������������������������������������������� 295


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 295
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 295
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 297
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 297

12-6. Overriding the Default Currency������������������������������������������������������������������������� 298


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 298
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 298
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 299

xxvi
■ Contents

12-7. Converting Byte Arrays to and from Strings������������������������������������������������������� 300


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 300
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 300
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 301

12-8. Converting Character Streams and Buffers�������������������������������������������������������� 302


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 302
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 302
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 302
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 303

12-9. Setting the Search Order of Locale-Sensitive Services�������������������������������������� 304


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 304
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 304
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 304

Summary���������������������������������������������������������������������������������������������������������������������� 304

■Chapter 13: Working with Databases���������������������������������������������������������������� 305
13-1. Connecting to a Database����������������������������������������������������������������������������������� 305
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 305
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 305
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 306
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 306

13-2. Handling Connection and SQL Exceptions���������������������������������������������������������� 308


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 308
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 308
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 309

13-3. Querying a Database and Retrieving Results������������������������������������������������������ 310


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 310
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 310
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 310

xxvii
■ Contents

13-4. Performing CRUD Operations������������������������������������������������������������������������������ 312


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 312
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 312
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 314

13-5. Simplifying Connection Management����������������������������������������������������������������� 315


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 315
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 315
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 318

13-6. Guarding Against SQL Injection��������������������������������������������������������������������������� 318


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 318
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 319
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 320

13-7. Performing Transactions������������������������������������������������������������������������������������� 322


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 322
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 322
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 324

13-8. Creating a Scrollable ResultSet�������������������������������������������������������������������������� 326


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 326
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 326
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 327

13-9. Creating an Updatable ResultSet������������������������������������������������������������������������ 328


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 328
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 328
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 329

13-10. Caching Data for Use When Disconnected�������������������������������������������������������� 330


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 330
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 330
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 333

xxviii
■ Contents

13-11. Joining RowSet Objects When Not Connected to the Data Source������������������� 335
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 335
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 335
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 340

13-12. Filtering Data in a RowSet�������������������������������������������������������������������������������� 341


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 341
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 341
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 345

13-13. Querying and Storing Large Objects����������������������������������������������������������������� 346


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 346
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 347
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 348

13-14. Invoking Stored Procedures������������������������������������������������������������������������������ 349


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 349
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 350
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 350

13-15. Obtaining Dates for Database Use�������������������������������������������������������������������� 351


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 351
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 351
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 352

13-16. Closing Resources Automatically���������������������������������������������������������������������� 352


Problem���������������������������������������������������������������������������������������������������������������������������������������������� 352
Solution���������������������������������������������������������������������������������������������������������������������������������������������� 352
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 353

Summary���������������������������������������������������������������������������������������������������������������������� 353

■Chapter 14: JavaFX Fundamentals�������������������������������������������������������������������� 355
14-1. Creating a Simple User Interface������������������������������������������������������������������������ 356
Problem���������������������������������������������������������������������������������������������������������������������������������������������� 356
Solution 1������������������������������������������������������������������������������������������������������������������������������������������� 356
Solution 2������������������������������������������������������������������������������������������������������������������������������������������� 357
How It Works��������������������������������������������������������������������������������������������������������������������������������������� 359

xxix
Another random document with
no related content on Scribd:
+ N Y Times 25:10 Jl 18 ’20 1300w
R of Rs 62:112 Jl ’20 40w

“There is a tone of sincere frankness in the interviews which


carries weight. Lieutenant Berger is evidently a man of tact and
discernment; he refused to enter upon useless discussion, but he was
able to guide the conversation so skilfully as to secure for his
superiors the desired information.” C: Seymour

+ Yale R n s 10:419 Ja ’21 310w

BERGSON, HENRI LOUIS. Mind-energy.


*$2.50 (3c) Holt 194
20–15087

This collection of lectures and essays, translated from the French


by H. Wildon Carr, is not only an authorized translation, says the
translator, but has been carefully supervised by M. Bergson himself,
as to details of meaning and expression, in order to give it the same
authority as the original French. The lectures are partly in exposition
of philosophical theory, partly detailed psychological investigation
and metaphysical research illustrative of their author’s concept of
reality as a fundamentally spiritual activity. Contents: Life and
consciousness; The soul and the body; “Phantasms of the living” and
psychical research; Dreams; Memory of the present and false
recognition; Intellectual effort; Brain and thought; a philosophical
illusion; Index.
+ Booklist 17:137 Ja ’21

“Bergson is brilliant, and he is in close touch with the life of men.


He is always worth reading for his intellectual strength and his
insight into things spiritual. In this book Bergson is found at his
best.” F. W. C.

+ Boston Transcript p4 S 22 ’20 1050w

“The present volume is valuable for students of Bergson just


because its confident reaffirmations proclaim that, in the author’s
judgment, his theories have stood the test of time. Hence this is a
good opportunity for attempting a total estimate of Bergson’s work
and a sorting out of what is likely to live from what is likely to die.” R.
F. A. Hoernle

+ N Y Evening Post p6 Ja 15 ’21 850w

“The student who lacks either the time or the training to study Mr
Bergson’s larger and more difficult work will find in this volume of
essays clues not difficult to understand and profitable to follow.”

+ Outlook 126:767 D 29 ’20 300w

“The essays before us, though diversely prompted, all converge


towards one centre, which is revealed by the title of the book. At the
end they leave the feeling that he has been pursuing the same subject
all the time. The tenacity with which he applies his principles is
certainly to be noted in a thinker who suggests such a flexible, almost
elusive, view of reality. There is a fascinating essay about ‘false
recognition.’”
+ The Times [London] Lit Sup p715 N 4
’20 800w

BERNSTORFF, JOHANN HEINRICH


ANDREAS HERMANN ALBRECHT, graf von.
My three years in America. *$5 Scribner 940.32
20–11505

“As a pendant to Mr Gerard’s reminiscences of the American


embassy in Berlin during the war, Count Bernstorff’s account of his
work as German ambassador at Washington is of some historic
interest. He is mainly concerned to defend himself and to put all the
blame for the quarrel with America on the Berlin foreign office and
on the military chiefs. He denies, of course, that he had anything to
do with the campaign of bomb outrages which German-Americans,
assisted by Irish-Americans, waged against American and Canadian
factories and allied shipping. He records the profound horror and
indignation caused by the torpedoing of the Lusitania, but disclaims
all previous knowledge of that foul deed.”—Spec
“For the historian and student of the war Count von Bernstorff’s
book has undoubted value. The excellence of the translation may be
due in part to the style of Count von Bernstorff; for, unlike many
German writers, he does not hide his thought behind dense and
complicated entanglements of language, but sets it forth in clear,
short, crisp sentences.” E. E. Sperry

+ Am Hist R 26:99 O ’20 1100w

“There are many curious statements in the book, some of which no


sophisticated reader will believe without confirmation. At any rate
students of political science will find many things in this volume to
provoke dissent, and some also that will meet with hearty
concurrence.”

+ − Am Pol Sci R 14:736 N ’20 250w

“The book is interesting and has a certain historical value.”

+ Ath p11 Jl 2 ’20 580w

“The tone is reasonable and conciliatory, the logic sometimes too


smooth.”

+ − Booklist 17:23 O ’20

“Throughout the narrative Count Bernstorff is wonderfully frank.


Whether this frankness arises from an honest openness of mind or
from an utter absence of ability to realize his own obliquity is a
question for each reader to solve for himself.” E. J. C.

+ Boston Transcript p6 Jl 10 ’20 900w

“Count Bernstorff himself is not a thinker like Norman Angell and


Bertrand Russell, but he is intelligent to a high degree, exact,
fearless, without cheap pride, living in a much more real atmosphere
than most of the German war statesmen. He has the prime
advantage, for a time of such complexity, of having a good mind that
functions without interference from his prejudices or his passions.”
Norman Hapgood

+ Nation 111:132 Jl 31 ’20 1750w


“The story is told coolly and without any sign of prejudice, except
for an occasional slurring reference to Colonel Roosevelt or
Ambassador Gerard. The narrator analyzes his characters in an
objective sort of way, unmoved by anger or enthusiasm, except for
one exclamation of admiration for Colonel House; he dissects, he
does not eulogize or condemn.” C. W. Thompson

+ N Y Times 25:3 Jl 4 ’20 2150w

“This book, as a real contribution to history, will assuredly take its


place alongside volumes of such permanent value as Viscount
Haldane’s, General von Falkenhayn’s, and Count Czernin’s. Indeed,
in none of these is there sharper, more illuminative, and more
cynical observation both of men and events.”

+ Outlook 126:690 D 15 ’20 250w


Review 3:710 Jl 7 ’20 360w

“It would be a serious mistake to consider his ‘plaidoyer’ as


dispassionate history. It is a further and exceedingly interesting
addition to that large library of self-justification now appearing in
Germany. It differs from other volumes only on a point of good
taste.” Christian Gauss

− + Review 3:190 S 1 ’20 1200w

“The reader into whose hands it may come will not fail to find its
chapters exceedingly interesting, as they review familiar episodes
from what to Americans is an unfamiliar standpoint.”

+ R of Rs 62:221 Ag ’20 240w


“We think that all the great actors in the German tragedy, military,
political and diplomatic, have now told their story, except the ex-
Kaiser. Count Bernstorff’s is certainly the best of these ‘pieces
justificatives,’ for it shows that the writer’s judgment was better than
that of his masters, and his style is temperate and logical.”

+ Sat R 129:542 Je 12 ’20 900w


Spec 124:799 Je 12 ’20 430w

“His attempt to gauge American character is on the whole happy.


Even those who differ with him will find it difficult to disprove his
findings. There is no rancor in his judgments. There is no attempt to
add piquancy to the narrative by gossip.”

+ Springf’d Republican p6 Ag 9 ’20 280w

BERRIMAN, ALGERNON E., and others.


Industrial administration. (Manchester univ.
publications) il *$2.40 Longmans 331
20–9654

“The lectures published in this volume were delivered in the


department of industrial administration in the College of technology,
Manchester, during the session 1918–19, by various well-known
authorities on subjects relating to industrial administration.”
(Nature) “Contents: Social obligations of industry to labour, by B. S.
Rowntree; The applications of psychology to industry, by T. H. Pear;
Education as a function of management, by A. E. Berriman;
Occupational diseases, by T. M. Legge; Atmospheric conditions and
efficiency, by L. Hill; Industrial councils and their possibilities, by T.
B. Johnston; Training for factory administration, by St G. Heath;
Industrial fatigue, by A. F. S. Kent.” (Am Econ R)

Am Econ R 10:840 D ’20 50w


Ath p814 Je 18 ’20 60w
Nature 106:74 S 16 ’20 620w

BETTER letters; a little book of suggestions and


information about business correspondence. $1
Herbert S. Browne, 608 S. Dearborn st., Chicago 658
20–3557

“This little book has been compiled for the average person in
business, whether executive or stenographer, who wants a statement
in simple and direct form of the elementary things that are essential
to good letters. It is a first-aid manual of style for business
correspondence, suitable for adoption by any commercial concern,
large or small.” (Introd.) Contents of part 1—The letter itself:
Appearance; Substance; Phraseology; Punctuation; Paragraphing;
Abbreviations; Miscellaneous. Contents of part 2—Words, right and
wrong; Some misused words; Verbal vulgarisms; Similar words often
confused; Pronouns: their use and abuse; Miscellaneous.

Booklist 17:17 O ’20


BIERSTADT, EDWARD HALE, ed. Three
plays of the Argentine; tr. from the Spanish by Jacob
S. Fassett, jr. *$1.75 Duffield 862
20–4775

In his introduction to these plays Mr Bierstadt has given us a


glimpse of the culture of one of our American neighbors to the South,
of whom we have hitherto known too little. His historical sketch of
the folk drama of the Argentine, known as the drama criollo, shows it
to have sprung from the very heart of the people, the gaucho, and to
have had its inception in the sawdust ring of the circus. As given in
the translation, the plays are transcriptions from the original popular
and unprinted versions and although modified, have retained their
true atmospheric and colorful qualities. Of the two first Mr Bierstadt
says: “They are perhaps the most famous in all the category of
gaucho plays, and carry as do no others the very spirit of the
pampas.” These are “Juan Moreira” and “Santos Vega.” The third,
“The witches’ mountain,” is not in the same sense a gaucho play, as it
is set in the mountain country, but is considered as marking the last
milestone in the epoch of truly native drama.

+ Booklist 16:336 Jl ’20

“‘The witches’ mountain’ is the only one of the three plays included
that conforms to the canons of real drama.”

+ Dial 59:664 D ’20 80w


“The second, while sufficiently crude and violent, has elements of
great beauty. The third, The witches’ mountain, is a really
magnificent piece, both in conception and construction.”

+ Freeman 1:214 My 12 ’20 400w

“When we come to the actual texture of the ‘dramas criollos’ the


impression is one of slight disappointment. The figure of the
wandering ‘gaucho’ and minstrel is romantic rather than naive.
Speech and verse, at least in their translated forms, present a curious
mixture of the sentimental and the artificial. In The witches’
mountain there is high and concentrated dramatic passion. But this
play is obviously the least primitive of the three.”

+ − Nation 110:693 My 22 ’20 260w

“These plays have a freshness and vigor of spaces our Wild West
scenarios somehow lack. There are the same conventional gestures,
the same corroborated sentiment from which any informing fire has
gone out. But at least these are reminiscent of authentic instead of
manufactured emotion.” Lola Ridge

+ − New Repub 25:236 Ja 19 ’21 660w


+ − Review 2:605 Je 5 ’20 240w

“However primitive the plays, they possess what our American


drama strives in vain to discover, the soul of their native land.... The
witches’ mountain is doubtless the most actable, and the most easily
understood by an American audience.” D. Grafly
+ Springf’d Republican p13a Ap 25 ’20
600w

“If these plays seem immature rather than naive; crude, rather
than in the spirit of the folk; if Mr Bierstadt seems to have mistaken
the drama inherent in the life and character of the ‘gaucho’ for drama
in the plays that represent him, there is still nothing but gratitude
due him for introducing the ‘gaucho’ to our unromantic world.”

+ − Theatre Arts Magazine 4:256 Jl ’20


380w

BIGELOW, MELVILLE MADISON. Papers on


the legal history of government; difficulties
fundamental and artificial. *$2 (4½c) Little 320.1
20–4206

The author warns against making a fetish of history and points out
the difficulty in the way of its infallibility as a teacher. The number
and complexity of the facts, in part hidden, in part incomprehensible,
impede correct judgment. Besides, latent energies may at any time
spring into action to change men’s reactions to given facts. On the
other hand there is a certain fundamental principle on which society
rests and which serves as constant in the interpretation of history. It
is the object of the book to study the past, to give assurance of the
principle and then to see how men have acted and are acting in its
presence. Contents: Unity in government; The family in English
history: an inquiry; Medieval English sovereignty; The old jury;
Becket and the law; Index.
Am Pol Sci R 14:738 N ’20 50w
Booklist 17:10 O ’20
Boston Transcript p6 Ap 28 ’20 220w

[2]
BINDLOSS, HAROLD. Lister’s great
adventure (Eng title, Head of the house). il *$2 (2c)
Stokes

George Lister, a young Canadian engineer, has his pluck and


natural ability rather than a defective scientific training to thank for
a moderate success. His self-reliance scorns the help of friends. He
rescues a young girl, Barbara Hyslop, from an amorous crook who
has induced her to run away with him. Later he is instrumental in
returning the girl to the bosom of her family. Having lost his job he
resolves to see something of the world and goes to England, and
while there undertakes to raise a wreck off the African coast for
Barbara’s step-father. After heroic efforts he succeeds but succumbs
to the fever-ridden locality. Barbara, who from conscientious
scruples over her romantic exploit, had refused his love, now calls
him back to health with the gift of it.

“The heroine and the various members of her family have more
individuality than is usual in this class of literature.”

+ Ath p523 O 15 ’20 80w


“There are no improbabilities and no excesses of sentimentality,
the style is simple and effective, and the pace is brisk and
unwavering.”

+ The Times [London] Lit Sup p621 S 23


’20 90w

BINDLOSS, HAROLD. Wilderness mine. il


*$1.90 (1½c) Stokes
20–14600

This story is divided into three distinct parts, the first and third of
which take place in England, and the second in Canada. Creighton
and Stayward are partners in business until Creighton, driven on by
his wife’s extravagances and his daughter’s need of an education,
misappropriates some of the funds and Stayward dissolves the
partnership. Creighton disappears and his wife spreads stories about
Stayward’s cruelty and dishonesty to her husband. The Canadian
part of the story has to do with Geoffrey Lisle, Stayward’s nephew,
who is managing a mine there, and who comes in contact with Tom
Carson, cook and chemist, who helps him defeat the rival mining
company he is working against. Upon his return to England at his
uncle’s death, Geoffrey again meets the girl who has been in his
thoughts ever since he left England, to discover that she is Ruth
Creighton, and theoretically his enemy. The timely discovery of who
Tom Carson really was helps him to win the girl and to clear his
uncle’s name in her eyes.

Booklist 17:70 N ’20


“His latest effort is a far more polished production than some of
those that have gone before it. As it is not the best kind of romance,
quite naturally it is not the best kind of adventure, but it serves very
well for an hour or so’s amusement, and lovers of Mr Bindloss will
find in this tale all the ingredients of his other efforts.”

+ − Boston Transcript p8 S 15 ’20 350w

“Mr Bindloss is one of those writers (all too few) who handle the
adventure story without stressing the adventures to the disadvantage
of all the other parts of the story. In other words, his characterization
is always clear and distinct and worked up with some elaboration,
and he has a quick eye at the description of natural scenery.”

+ N Y Times p27 Ag 22 ’20 370w

“The Canadian part of the book is much the best.”

+ Outlook 126:378 O 27 ’20 40w

BINDLOSS, HAROLD. Wyndham’s pal. *$1.75


(2c) Stokes
19–16148

Harry Wyndham having inherited from his forefathers an old


business enterprise of somewhat doubtful credit, along with a
romantic, restless, daring temperament, sets out on a trading
adventure in the wild lagoons, mandrake swamps, fever atmosphere,
and mysterious dangers of the Caribbean coast. There is a girl back
home in England, for whose sake he wishes to return wealthy and
successful. He achieves his purpose, although in order to do it he has
to deal with a dangerous, sinister, mysterious creature called the Bat,
and has to compromise his honesty and honor. Found out by his
bride and business partner he seriously undertakes reparation and
re-establishes his own self-respect, as well as the respect of others.

“Men, and boys in their teens, will like this story.”

+ Booklist 16:242 Ap ’20

“Without being particularly exciting or particularly vivid, it holds


the reader’s attention.”

+ N Y Times 25:120 Mr 14 ’20 380w


Outlook 124:479 Mr 17 ’20 50w

“To an astonishing degree, he maintains his average. And his


average is good.” H. Dick

+ Pub W 97:604 F 21 ’20 280w

“We have read better stories by this author.”

+ − Sat R 128:422 N 1 ’19 60w

“The story is rather better than many of the author’s recent books,
and his readers will find considerable entertainment in its pages.”
+ Springf’d Republican p11a Mr 7 ’20
300w
The Times [London] Lit Sup p502 S 18
’19 100w

BINNS, OTTWELL. Mating in the wilds. (Borzoi


western stories). *$2 (2c) Knopf
20–15961

Hubert Stane, who has served a prison sentence on a false charge,


is in the north woods. Here he meets Gerald Ainley, the man who
was responsible for his sentence. Ainley apparently stands high in
the estimation of Hudson Bay company officials and is a suitor for
the hand of Helen Yardely, a beautiful English girl who is making a
tour of the posts with her uncle. Helen is lost in the woods. Stane
finds her and fate forces the two to spend long months of exile
together. Helen takes naturally to primitive life and when Stane’s
name is cleared the two are married at an English mission and
continue their wilderness life.

“An exciting tale told with literary excellence beyond the average of
adventure stories.”

+ N Y Times p25 Ag 29 ’20 550w

“It is all admirably and romantically told. Though we know the tale
of old, it is still alive when the right chronicler takes it up; and Mr
Binns never for a moment lets it flag.”
+ The Times [London] Lit Sup p126 F 19
’20 200w

BIRDSEYE, CLARENCE FRANK. American


democracy versus Prussian Marxism. *$2.50 Revell
335
20–4906

“Clarence F. Birdseye, in a volume entitled ‘American democracy


versus Prussian Marxism,’ presents what he calls ‘a study in the
nature and results of purposive or beneficial government,’ his object
being to warn his fellow-citizens of the great danger threatening the
American form of government through the attacks that are being
made upon it by Marxian socialists. In order to make clear the
danger is real, and not fanciful, Mr Birdseye analyzes both
governmental forms and shows conclusively that no tolerance of the
Marxian idea can be permitted in this country without damage to
American institutions and ideals.”—N Y Times

“In this compact little volume, rich in well selected facts and
information throughout, the author has performed a useful service.”
W. B. Guthrie

+ Am Pol Sci R 14:510 Ag ’20 420w


N Y Times p31 S 5 ’20 90w
R of Rs 61:560 My ’20 50w
BIRNBAUM, MARTIN. Introductions; painters,
sculptors and graphic artists. il *$5 Sherman, F:
Fairchild 704
20–2849

“Papers by an American critic on Beardsley, Conder, C. H.


Shannon, C. Ricketts, Pakst, Dulac, Alfred Stevens, John Flaxman,
and some younger American artists—Maurice Sterne, Paul Manship
(sculptor), Alfred Sterner (painter, lithographer, etc.), Robert Blum
(illustrator, decorator, pastellist), Edie Nadeloman (Polish sculptor),
Kay Nielsen, the Danish water-colourist, Jules Pascrin, the Austrian
satiric artist.”—The Times [London] Lit Sup

“The Aubrey Beardsley and Conder introductions may be taken as


the perfect models for this form of art. Mr Birnbaum, himself, never
quite arose to the same plane of detachment in his later writings. The
citations, though brilliant, become too incessant and the authorities
parading through the pages scarcely give each other elbow room. The
feats of memory displayed are prodigious, comparable to those of Mr
Huneker. In fact, stylistically, there is more than a suspicion that Mr
Birnbaum is Mr Huneker’s child.” H: McBride

+ − Dial 68:371 Mr ’20 1850w

“To be graceful, informing, and readily understood was the


problem. The author has solved it with sure literary tact and offers as
well a fine criticism which was not in the bond.”

+ Review 2:184 F 21 ’20 350w


+ Springf’d Republican p8 S 10 ’20 580w
The Times [London] Lit Sup p304 My
13 ’20 50w

BIRRELL, AUGUSTINE. Frederick Locker-


Lampson. il *$8 Scribner
(Eng ed 20–14702)

“A kinship of spirit as well as relationship by marriage bound Mr


Birrell and Locker-Lampson, and in every page of his character
sketch, he reveals a sympathy that is both personal and professional.
Few books are both more and less a biography than this. It is merely
a series of impressions and appreciations. Less than half its opening
pages contain the biographical matter, and then follow some fifty
pages of letters from eminent literary men—including Thackeray,
Dickens, Tennyson, Holmes, Ruskin, Hardy and Stevenson—which
reveal the esteem in which Locker-Lampson was held by his
contemporaries. The other material which completes the volume
includes six letters written by him to his son at Eton, some family
bookplates, bibliographical notes on the books in the famous
Rowfant library, and a brief account of the Rowfant library at
Cleveland, with a list of its publications.”—Boston Transcript

“Mr Birrell’s biography reads so queerly because it brings before us


a real human being. It is not that he is more profound than others, or
that he has a story to tell to which we cannot fail to listen. It is that
the values of life are quite different from those of biography. There is
such a thing as living. One of the chief merits of Mr Birrell’s method,
which is a peculiar compound of wit and sanity, is that it reduces
these nineteenth-century phantoms to human scale.” V. W.
+ Ath p201 Ag 13 ’20 1300w

“It has been a long time since ‘London lyrics’ first appeared, but
none the less this intimate and accurate character sketch of their
author has a genuine interest and value.” H: L. West

+ Bookm 52:73 S ’20 450w

“A gentle and a genial tribute, it may well be said, is this volume to


the personality, the achievements and the memory of a rare being.”
E. F. E.

+ Boston Transcript p6 Je 30 ’20 1250w

“As a piece of book-making, the offering is admirable; as a book—!


But Mr Birrell is a devoted chronicler and if, from these impeccable
pages, his placid father-in-law emerges an even less interesting
figure than he seemed before one’s perusal of his memorial, the
meticulous chronicler himself can not escape scot-free.” L:
Untermeyer

− + Freeman 2:163 O 27 ’20 750w

“Hitherto the best analysis of Locker’s work was to be found in the


sympathetic study prepared by Austin Dobson in 1904. Mr Birrell’s
sketch is ampler than Mr Dobson’s and it is also more discursive. It
abounds in playful digressions and in pleasant irrelevancies.”
Brander Matthews

+ N Y Times 25:14 Jl 11 ’20 2300w


“His sketch is somewhat discursive and casual, containing more
background than definite statements, but it includes some agreeable
Birrelling.”

+ − Sat R 129:588 Je 26 ’20 1000w

“Nowhere has he gossiped more charmingly; and if he cannot


resist an occasional divagation from his main topic, his obiter dicta
are as pleasant as ever.”

+ Spec 124:82 Jl 17 ’20 1500w


+ Springf’d Republican p11a Jl 18 ’20
650w

“In reading this book, and noticing how Mr Birrell is always sliding
away from his subject to talk about himself, or about somebody or
something other than Frederick Locker, you ask why he chose
‘Frederick Locker-Lampson: a character sketch’ for the title of a book
that might just as properly have been called ‘Scraps,’ or ‘Chips,’ or
‘Jottings.’ In the end nevertheless, you feel that you have been unfair.
Mr Birrell, in his odd, slipshod way, is a man of letters—at least a
man who delights in letters; and he gives you a faint character sketch
of Frederick Locker-Lampson.”

+ − The Times [London] Lit Sup p381 Je 17


’20 1500w

[2]
BISHOP, CARLTON THOMAS. Structural
drafting and the design of details. il *$5 Wiley 744
20–4714

“The author was formerly chief draftsman to one of the largest


bridge companies, and is now a professor at Yale university. Part 1
covers comprehensively the duties of the draftsman and what he
should know in a general way about organization of plant and office,
as well as a survey of the manufacture and fabrication of structural
steel. Part 2 tells in detail about the technique of drawing, with
special chapters devoted to beams, girders, trusses, bracing systems,
bills, checking, etc. Part 3 deals closely with the theory and practice
of designing different types of construction members.”—N Y P L New
Tech Bks

+ Booklist 17:102 D ’20

“To the student or inexperienced draftsman the book is invaluable.


The experienced draftsman can hardly fail to add to his efficiency by
reading it. The typography of the book is all that needs be desired.
This, with the general excellence of the contents, will make it a
standard in the field of structural drafting for some time to come.”

+ Engin News-Rec 84:1215 Je 17 ’20 1150w


+ Iron Age 105:1293 Ap 29 ’20 160w
Mining & Scientific Press 121:33 Jl 3
’20 110w

“On the whole we are inclined to name this the best book on the
subject.”
+ N Y P L New Tech Bks p27 Ap ’20 170w
Pratt p16 O ’20 20w

BISHOP, ERNEST SIMONS. Narcotic drug


problem. *$1.50 Macmillan 613.8
20–1614

“‘It is becoming apparent that in spite of all the work which has
been done there has been practically no change in the general
situation, and there has been no solution of the drug problem.’ This
is the conclusion of Dr Ernest S. Bishop, clinical professor of
medicine in the New York polyclinic medical school. Two
outstanding elements appear to Dr Bishop to have received
insufficient consideration in the efforts to solve the narcotic drug
problem. One of these elements is the suffering of the addict: the
other is the nature of the physical disease with which he is afflicted.
Dr Bishop asserts that the exploitation of human weakness and
suffering would be checked on any large scale, if the disease created
by continued administration of opiates were recognized and its
physical demands comprehended and provided for in legitimate and
relatively unobjectionable ways.... Dr Bishop also recommends the
establishment under proper supervision and management of stations
or clinics at which those who for financial or other reasons are
unable to secure honest medical help, may obtain their necessary
opiate at minimum expense without ‘resorting to underworld
associations and illicit commerce.’”—Springf’d Republican

+ Cleveland p74 Ag ’20 50w


“Occasionally, very occasionally, one finds a book upon a
somewhat technical subject which is not merely readable and
informative, but actually liberating. Such a book is Dr Bishop’s
discourse on the narcotic drug problem.”

+ No Am 211:428 Mr ’20 850w


Review 3:112 Ag 4 ’20 130w

“A criticism of the book might well be directed against its


redundancy. Nor does it appear just what type of audience he had in
mind when inditing his message. Obviously it is not intended for the
narcotic drug addict. If addressed to the physician, it is incomplete
and fragmentary. If meant for the layman only casually interested in
the problem, the message should have had greater emotional
appeal.” H. E. K.

+ − Social Hygiene 6:586 O ’20 480w

“Dr Bishop’s study of the situation is scientific, thorough and


humane. It will authoritatively inform the public regarding a subject
on which enlightenment is needed.

+ Springf’d Republican p6 Ja 29 ’20 800w

“The real problems of the narcotic drug situation are related to the
origin and prevention of heroin and cocaine addictions and the
treatment and after-care of those so addicted. This book avoids these
questions and is sterile of information on these essential points of
the narcotic drug problem.” Medicus

+ − Survey 44:253 My 15 ’20 450w


BISHOP, H. C. W. Kut prisoner. (On active
service ser.) il *$1.50 (3c) Lane 940.47
20–5240

The author, a subaltern of the Indian army reserve of officers,


gives an account of prison life at Kastamuni in Asia Minor, and of his
escape in company with three other officers, their recapture, and
rescue by Turkish brigands and their voyage across the Black sea in a
small boat, to the Russian border and freedom. Contents: Ctesiphon;
Kut; From Kut to Kastamuni; Life in Kastamuni; Escape from
Kastamuni; The first night; On the hills; Slow progress; Bluffing the
peasants; Reaching the coast; Recaptured; Rescued; In hiding with
the Turks; Continued delays; Three days on the Black sea; The
Crimea and home; Friends in captivity. There are maps, illustrations
and appendices.

“The book is interesting.”

+ Ath p386 Mr 19 ’20 30w


+ Boston Transcript p8 S 15 ’20 250w

“Mr Bishop describes his adventures simply and clearly, and his
book is worth reading.”

+ Spec 124:216 F 14 ’20 70w


The Times [London] Lit Sup p90 F 5
’20 60w
BISHOP, JOSEPH BUCKLIN. Theodore
Roosevelt and his time shown in his own letters. 2v il
*$10 Scribner
20–17013

“Seven years ago, when Theodore Roosevelt published his


‘Autobiography,’ he prefixed to it a foreword, which began with this
sentence. ‘Naturally, there are chapters of my autobiography which
cannot now be written.’ Yet he had written from day to day, on the
spur of the moment, in his frank letters to one or another of his
multitude of friends, the very passages which he could not give to the
public while he was still in the thick of the fight. And it is these
passages which enliven and illuminate the two volumes which Mr
Bishop has now selected and set in order, and explained and
annotated. The work was begun while Roosevelt still lived; it had his
complete approval; parts of it were read to him and amplified from
his recollections.”—N Y Times

“The biography which will be most worth while to libraries.”

+ Booklist 17:68 N ’20

“One of the most notable works of the season is Joseph Bucklin


Bishop’s ‘Theodore Roosevelt.’” Margaret Ashmun

+ Bookm 52:345 D ’20 140w

“With perfect taste and judgment Mr Bishop has stood aside and
allowed the story to be told through Roosevelt’s letters. He has made
an excellent book, important, always readable and often extremely
amusing. With the ‘Autobiography’ and Mr Thayer’s book, the
present work, ‘Theodore Roosevelt and his time’ is one of the three
indispensable books on this subject. With Mr Huneker’s
‘Steeplejack,’ it is one of the two best American biographies of this
year.” E. L. Pearson

+ Boston Transcript p5 O 23 ’20 2750w

“It is a work of notable artistic merit. Perhaps fifty years hence it


may generally be conceded that this book preserves what is
important in ‘the true Theodore Roosevelt’s’ character. At present
one cannot help feeling that Mr Bishop’s figure of rugged integrity,
unerring rectitude, and loftiest patriotism has been shorn of some of
its beams.” S. P. Sherman

+ − Nation 112:18 Ja 5 ’21 2500w

“A difficult task has been accomplished triumphantly, and the


result is a portrait of Roosevelt by himself, set in an editorial frame
which is artistically unobstructive. Mr Bishop has given us a work
which does for one president of the United States what was done for
an earlier president by the publication of Grant’s ‘Personal memoirs.’
And neither of these great men would object to the comparison.”
Brander Matthews

+ N Y Times p4 O 3 ’20 2300w

“There are a few little errors, nothing of consequence. But the book
is undoubtedly partisan; which does not prevent it from being a
thoroughly good and complete biography.” C: W. Thompson

+ − N Y Times p5 O 3 ’20 3450w


“It is a work after Roosevelt’s own heart, the sort of record that he
himself would have endorsed just as it stands, showing him in the
full strength and weakness of his very human quality.” F: T. Cooper

+ Pub W 98:1196 O 16 ’20 480w

Reviewed by E. L. Pearson

+ Review 3:314 O 13 ’20 340w

“These two volumes, as they stand, will serve not only for the
present time but for future generations.”

+ R of Rs 62:669 D ’20 280w

“Mr Bishop has succeeded in giving us two volumes of great value


and readability.”

+ Wis Lib Bul 16:236 D ’20 110w (Reprinted


from Atlantic D ’20)

BISHOP, LOUIS FAUGÈRES. Heart troubles;


their prevention and relief. il *$3.50 Funk 616.1
20–13070

A book written in popular style and addressed to the layman. The


author believes that a patient is entitled to the full confidence of his
physician and thinks that in heart disease “the educated patient can
help more when wisely advised than in almost any other form of
disease.” The book is in two parts: Physiological and symptomatic,
and Therapeutic. The final chapter is devoted to Nursing in heart
troubles. The book is illustrated and indexed and there is a one-page
list of collateral reading. The author is professor of the heart and
circulatory diseases, Fordham university, New York city.

+ Cath World 112:410 D ’20 90w

“The immediate effect of this sane and sensible work should be a


wider dissemination of modern knowledge of the heart, its affections
and their treatment; the ultimate result should be a reduction in the
alarming death rate from heart disease in the United States.” V. B.
Thorne

+ N Y Times p17 Ag 29 ’20 3000w

“A ‘doctor book’ of an unusual sort and one which will be found of


great interest and of much practical value.”

+ Springf’d Republican p6 Ag 2 ’20 130w

BISPHAM, DAVID SCULL. Quaker singer’s


recollections. il *$4 Macmillan
20–1629

“For thirty years and more David Bispham has been prominent,
here and abroad, as a baritone of note, a singing actor, and an
advocate of the use of English speech in opera. In these recollections
he has packed into one volume the record of a long and busy life—a
life of many strange and varied experiences. Unlike most men who
have their hour in opera, he has had his in society. He has traveled
far and wide, and mixed with people who were worth knowing and
far-famed in many ways. To this it may be added, unreservedly, that
he has more than an instinctive turn for setting down, in plain but
vivid words, what he would tell.”—Review

Booklist 16:241 Ap ’20

“The style, unfortunately, is plainly that of a singer, and wavers


continually between the exclamatory and the sentimental.”

+ − Dial 68:402 Mr ’20 90w

“While Mr Bispham’s book may appeal primarily to singers and


students of singing, it is none the less a valuable text book for
students of the drama.”

+ Drama 10:356 Jl ’20 140w

“It is an interesting volume full of the writer’s personality written


with more literary skill and taste than many such books, giving many
sidelights on the musical life of the period of which it treats.” R:
Aldrich

+ N Y Times 25:6 F 29 ’20 2150w


“If we were disappointed in David Bispham’s ‘A Quaker singer’s
recollections,’ it was not because of lack of thoroughness, but
because that delightful singer’s fund of anecdote has not been used to
advantage.”

+ − N Y Times 25:192 Ap 18 ’20 80w

“A singer who can write with ease and style is rarer than that rare
bird, the black swan. One artist of the kind is David Bispham.” C: H:
Meltzer

+ Review 2:289 Mr 20 ’20 950w


R of Rs 61:333 Mr ’20 100w

“An excellent volume of reminiscences.”

+ Spec 124:694 My 22 ’20 780w

“He has perhaps not grasped the first bitter truth to be learned by
an author that of all the countless incidents which his own mind
makes picturesque in retrospect only those are interesting which he
can make picturesque to others. The bald stretches, however, are
only occasional.”

+ − The Times [London] Lit Sup p233 Ap


15 ’20 850w

BISS, GERALD. Door of the unreal. *$2 (3c)


Putnam

You might also like