Download as pdf or txt
Download as pdf or txt
You are on page 1of 44

Java: The Complete Reference 12th

Edition Herbert Schildt


Visit to download the full and correct content document:
https://ebookmass.com/product/java-the-complete-reference-12th-edition-herbert-schi
ldt/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Java: The Complete Reference (Complete Reference


Series) 13th Edition Schildt

https://ebookmass.com/product/java-the-complete-reference-
complete-reference-series-13th-edition-schildt/

Java: The Complete Reference, Twelfth Edition Schildt

https://ebookmass.com/product/java-the-complete-reference-
twelfth-edition-schildt/

Java: A Beginner’s Guide, Eighth Edition Herbert


Schildt

https://ebookmass.com/product/java-a-beginners-guide-eighth-
edition-herbert-schildt/

Java: A Beginner's Guide: Create, Compile, and Run Java


Programs Today 9th Edition Herbert Schildt

https://ebookmass.com/product/java-a-beginners-guide-create-
compile-and-run-java-programs-today-9th-edition-herbert-schildt/
Core Java, Vol. II-Advanced Feature 12th Edition Cay S.
Horstmann

https://ebookmass.com/product/core-java-vol-ii-advanced-
feature-12th-edition-cay-s-horstmann/

Gomella and Haist's Clinician's Pocket Reference, 12th


Edition Leonard G. Gomella

https://ebookmass.com/product/gomella-and-haists-clinicians-
pocket-reference-12th-edition-leonard-g-gomella/

Private Wealth Management: The Complete Reference for


the Personal Financial Planner, Ninth Edition 9th
Edition, (Ebook PDF)

https://ebookmass.com/product/private-wealth-management-the-
complete-reference-for-the-personal-financial-planner-ninth-
edition-9th-edition-ebook-pdf/

The Crosscultural, Language, and Academic Development


Handbook: A Complete K 12 Reference Guide 6th Edition,
(Ebook PDF)

https://ebookmass.com/product/the-crosscultural-language-and-
academic-development-handbook-a-complete-k-12-reference-
guide-6th-edition-ebook-pdf/

Core Java vol 1 & 2 for the impatient and effective


PACK 12th ed Cay S Horstmann

https://ebookmass.com/product/core-java-vol-1-2-for-the-
impatient-and-effective-pack-12th-ed-cay-s-horstmann/
CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9 / blind folio: i

The
Complete Java™
Reference Twelfth Edition

00-FM.indd 1 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9 / blind folio: ii

About the Author


Best-selling author Herbert Schildt has written extensively about programming
for over three decades and is a leading authority on the Java language. Called “one
of the world’s foremost authors of books about programming” by International
Developer magazine, his books have sold millions of copies worldwide and
have been translated into all major foreign languages. He is the author of
numerous books on Java, including Java: A Beginner’s Guide, Herb Schildt’s
Java Programming Cookbook, Introducing JavaFX 8 Programming, and Swing:
A Beginner’s Guide. He has also written extensively about C, C++, and C#.
Featured as one of the rock star programmers in Ed Burns’ book Secrets of
the Rock Star Programmers: Riding the IT Crest, Schildt is interested in all
facets of computing, but his primary focus is computer languages. Schildt
holds both BA and MCS degrees from the University of Illinois. His website is
www.HerbSchildt.com.

About the Technical Editor


Dr. Danny Coward has worked on all editions of the Java platform. He led the
definition of Java Servlets into the first version of the Java EE platform and
beyond, web services into the Java ME platform, and the strategy and planning
for Java SE 7. He founded JavaFX technology and, most recently, designed the
largest addition to the Java EE 7 standard, the Java WebSocket API. From
coding in Java, to designing APIs with industry experts, to serving for several
years as an executive to the Java Community Process, he has a uniquely broad
perspective into multiple aspects of Java technology. In addition, he is the
author of two books on Java programming: Java WebSocket Programming and
Java EE 7: The Big Picture. Most recently, he has been applying his knowledge
of Java to helping scale massive Java-based services for one of the world’s most
successful software companies. Dr. Coward holds a bachelor’s, master’s, and
doctorate in mathematics from the University of Oxford.

00-FM.indd 2 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9 / blind folio: iii

The
Complete Java™
Reference Twelfth Edition

Herbert Schildt

New York Chicago San Francisco


Athens London Madrid Mexico City
Milan New Delhi Singapore Sydney Toronto

00-FM.indd 3 22/09/21 6:45 PM


Copyright © 2022 by McGraw Hill. All rights reserved. Except as permitted under the United States Copyright Act of 1976,
no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval
system, without the prior written permission of the publisher.

ISBN: 978-1-26-046342-2
MHID: 1-26-046342-7

The material in this eBook also appears in the print version of this title: ISBN: 978-1-26-046341-5,
MHID: 1-26-046341-9.

eBook conversion by codeMantra


Version 1.0

All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a
trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of
infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps.

McGraw-Hill Education eBooks are available at special quantity discounts to use as premiums and sales promotions or for
use in corporate training programs. To contact a representative, please visit the Contact Us page at www.mhprofessional.com.

Information has been obtained by McGraw Hill from sources believed to be reliable. However, because of the possibility of
human or mechanical error by our sources, McGraw Hill, or others, McGraw Hill does not guarantee the accuracy, adequacy,
or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use of
such information.

Oracle Corporation does not make any representations or warranties as to the accuracy, adequacy, or completeness of any in-
formation contained in this Work, and is not responsible for any errors or omissions.

TERMS OF USE

This is a copyrighted work and McGraw-Hill Education and its licensors reserve all rights in and to the work. Use of this work
is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the
work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit,
distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill Education’s prior consent.
You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited. Your right
to use the work may be terminated if you fail to comply with these terms.

THE WORK IS PROVIDED “AS IS.” McGRAW-HILL EDUCATION AND ITS LICENSORS MAKE NO GUARANTEES
OR WARRANTIES AS TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED
FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK
VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, IN-
CLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICU-
LAR PURPOSE. McGraw-Hill Education and its licensors do not warrant or guarantee that the functions contained in the work
will meet your requirements or that its operation will be uninterrupted or error free. Neither McGraw-Hill Education nor its
licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any
damages resulting therefrom. McGraw-Hill Education has no responsibility for the content of any information accessed through
the work. Under no circumstances shall McGraw-Hill Education and/or its licensors be liable for any indirect, incidental,
special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them
has been advised of the possibility of such damages. This limitation of liability shall apply to any claim or cause whatsoever
whether such claim or cause arises in contract, tort or otherwise.
CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

Contents at a Glance
PART I The Java Language
1 The History and Evolution of Java 3
2 An Overview of Java 21
3 Data Types, Variables, and Arrays 39
4 Operators 67
5 Control Statements 87
6 Introducing Classes 117
7 A Closer Look at Methods and Classes 137
8 Inheritance 171
9 Packages and Interfaces 199
10 Exception Handling 227
11 Multithreaded Programming 247
12 Enumerations, Autoboxing, and Annotations 277
13 I/O, Try-with-Resources, and Other Topics 315
14 Generics 347
15 Lambda Expressions 391
16 Modules 421
17 Switch Expressions, Records,
  and Other Recently Added Features 449
PART II The Java Library
18 String Handling 483
19 Exploring java.lang 511
20 java.util Part 1: The Collections Framework 571
21 java.util Part 2: More Utility Classes 653
22 Input/Output: Exploring java.io 713
23 Exploring NIO 763
24 Networking 795
25 Event Handling 819
26 Introducing the AWT: Working with
  Windows, Graphics, and Text 851
27 Using AWT Controls, Layout Managers, and Menus 879
28 Images 929
29 The Concurrency Utilities 955
30 The Stream API 1005
31 Regular Expressions and Other Packages 1031

00-FM.indd 5 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

vi  Java: The Complete Reference

PART III Introducing GUI Programming with Swing


32 Introducing Swing 1061
33 Exploring Swing 1079
34 Introducing Swing Menus 1109
PART IV Applying Java
35 Java Beans 1145
36 Introducing Servlets 1157
PART V Appendixes
A Using Java’s Documentation Comments 1183
B Introducing JShell 1191
C Compile and Run Simple Single-File Programs in
  One Step 1201

Index
1203

00-FM.indd 6 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxxi

Part I The Java Language


Chapter 1 The History and Evolution of Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Java’s Lineage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Birth of Modern Programming: C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
C++: The Next Step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Stage Is Set for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
The Creation of Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
The C# Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
How Java Impacted the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Java Applets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Java’s Magic: The Bytecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Moving Beyond Applets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
A Faster Release Schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Servlets: Java on the Server Side . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
The Java Buzzwords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Simple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Object-Oriented . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Robust . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Multithreaded . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Architecture-Neutral . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Interpreted and High Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Distributed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Dynamic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
The Evolution of Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
A Culture of Innovation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Chapter 2 An Overview of Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Two Paradigms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Abstraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
The Three OOP Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

vii

00-FM.indd 7 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

viii  Java: The Complete Reference

A First Simple Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27


Entering the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Compiling the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
A Closer Look at the First Sample Program . . . . . . . . . . . . . . . . . . . . . . 28
A Second Short Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Two Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Using Blocks of Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Lexical Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Whitespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Separators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The Java Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
The Java Class Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Chapter 3 Data Types, Variables, and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Java Is a Strongly Typed Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
The Primitive Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
byte . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
short . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
int . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
long . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Floating-Point Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
float . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
double . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Booleans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
A Closer Look at Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Integer Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Floating-Point Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Boolean Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Character Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
String Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Declaring a Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Dynamic Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
The Scope and Lifetime of Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Type Conversion and Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Java’s Automatic Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Casting Incompatible Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

00-FM.indd 8 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

Contents   ix

Automatic Type Promotion in Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54


The Type Promotion Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
One-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Alternative Array Declaration Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Introducing Type Inference with Local Variables . . . . . . . . . . . . . . . . . . . . . . 62
Some var Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
A Few Words About Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Chapter 4 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
The Basic Arithmetic Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
The Modulus Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Arithmetic Compound Assignment Operators . . . . . . . . . . . . . . . . . . . 69
Increment and Decrement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
The Bitwise Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
The Bitwise Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
The Left Shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
The Right Shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
The Unsigned Right Shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Bitwise Operator Compound Assignments . . . . . . . . . . . . . . . . . . . . . . . 79
Relational Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Boolean Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Short-Circuit Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The Assignment Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
The ? Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Operator Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Using Parentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Chapter 5 Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Java’s Selection Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
The Traditional switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Iteration Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
do-while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
The For-Each Version of the for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Local Variable Type Inference in a for Loop . . . . . . . . . . . . . . . . . . . . . 108
Nested Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Jump Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Using break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Using continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115

00-FM.indd 9 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

x  Java: The Complete Reference

Chapter 6 Introducing Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117


Class Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
The General Form of a Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
A Simple Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Declaring Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
A Closer Look at new . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Assigning Object Reference Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Introducing Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Adding a Method to the Box Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Returning a Value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Adding a Method That Takes Parameters . . . . . . . . . . . . . . . . . . . . . . . 127
Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Parameterized Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
The this Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Instance Variable Hiding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Garbage Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
A Stack Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Chapter 7 A Closer Look at Methods and Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Overloading Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Overloading Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Using Objects as Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
A Closer Look at Argument Passing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Returning Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Introducing Access Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Understanding static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Introducing final . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
Arrays Revisited . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Introducing Nested and Inner Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Exploring the String Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Using Command-Line Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Varargs: Variable-Length Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Overloading Vararg Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Varargs and Ambiguity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Local Variable Type Inference with Reference Types . . . . . . . . . . . . . . . . . . 168
Chapter 8 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Inheritance Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Member Access and Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
A More Practical Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
A Superclass Variable Can Reference a Subclass Object . . . . . . . . . . . 176
Using super . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Using super to Call Superclass Constructors . . . . . . . . . . . . . . . . . . . . . 177
A Second Use for super . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180

00-FM.indd 10 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

Contents   xi

Creating a Multilevel Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181


When Constructors Are Executed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Method Overriding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Dynamic Method Dispatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Why Overridden Methods? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Applying Method Overriding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
Using Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Using final with Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Using final to Prevent Overriding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Using final to Prevent Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Local Variable Type Inference and Inheritance . . . . . . . . . . . . . . . . . . . . . . . 195
The Object Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Chapter 9 Packages and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Defining a Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Finding Packages and CLASSPATH . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
A Short Package Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Packages and Member Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
An Access Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Importing Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Defining an Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Implementing Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Nested Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Applying Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Variables in Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Interfaces Can Be Extended . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Default Interface Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Default Method Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
A More Practical Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Multiple Inheritance Issues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Use static Methods in an Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Private Interface Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Final Thoughts on Packages and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Chapter 10 Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Exception-Handling Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Exception Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Uncaught Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Using try and catch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Displaying a Description of an Exception . . . . . . . . . . . . . . . . . . . . . . . 232
Multiple catch Clauses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Nested try Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
throw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
throws . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237

00-FM.indd 11 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

xii  Java: The Complete Reference

finally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Java’s Built-in Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
Creating Your Own Exception Subclasses . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Chained Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Three Additional Exception Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245
Using Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
Chapter 11 Multithreaded Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
The Java Thread Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Thread Priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Messaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
The Thread Class and the Runnable Interface . . . . . . . . . . . . . . . . . . . . 250
The Main Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Creating a Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Implementing Runnable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Extending Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Choosing an Approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Creating Multiple Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Using isAlive( ) and join( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
Thread Priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Using Synchronized Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
The synchronized Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
Interthread Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Deadlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Suspending, Resuming, and Stopping Threads . . . . . . . . . . . . . . . . . . . . . . . . 272
Obtaining a Thread’s State . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
Using a Factory Method to Create and Start a Thread . . . . . . . . . . . . . . . . . 275
Using Multithreading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
Chapter 12 Enumerations, Autoboxing, and Annotations . . . . . . . . . . . . . . . . . . . . . 277
Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Enumeration Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
The values( ) and valueOf( ) Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Java Enumerations Are Class Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Enumerations Inherit Enum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Another Enumeration Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Type Wrappers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287
The Numeric Type Wrappers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
Autoboxing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Autoboxing and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Autoboxing/Unboxing Occurs in Expressions . . . . . . . . . . . . . . . . . . . 291
Autoboxing/Unboxing Boolean and Character Values . . . . . . . . . . . . 292

00-FM.indd 12 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

Contents   xiii

Autoboxing/Unboxing Helps Prevent Errors . . . . . . . . . . . . . . . . . . . . 293


A Word of Warning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
Annotation Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Specifying a Retention Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Obtaining Annotations at Run Time by Use of Reflection . . . . . . . . . 296
The AnnotatedElement Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
Using Default Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
Marker Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
Single-Member Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
The Built-In Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Type Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Repeating Annotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Some Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Chapter 13 I/O, Try-with-Resources, and Other Topics . . . . . . . . . . . . . . . . . . . . . . . 315
I/O Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Byte Streams and Character Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
The Predefined Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Reading Console Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
Reading Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
Reading Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
Writing Console Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322
The PrintWriter Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Reading and Writing Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Automatically Closing a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
The transient and volatile Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333
Introducing instanceof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
strictfp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
Native Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Using assert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
Assertion Enabling and Disabling Options . . . . . . . . . . . . . . . . . . . . . . 339
Static Import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
Invoking Overloaded Constructors Through this( ) . . . . . . . . . . . . . . . . . . . 342
A Word About Value-Based Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
Chapter 14 Generics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
What Are Generics? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
A Simple Generics Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Generics Work Only with Reference Types . . . . . . . . . . . . . . . . . . . . . . 352
Generic Types Differ Based on Their Type Arguments . . . . . . . . . . . . 352
How Generics Improve Type Safety . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352
A Generic Class with Two Type Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 355
The General Form of a Generic Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
Bounded Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356

00-FM.indd 13 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

xiv  Java: The Complete Reference

Using Wildcard Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359


Bounded Wildcards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Creating a Generic Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
Generic Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Generic Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Raw Types and Legacy Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372
Generic Class Hierarchies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374
Using a Generic Superclass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
A Generic Subclass . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377
Run-Time Type Comparisons Within a Generic Hierarchy . . . . . . . . 378
Casting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Overriding Methods in a Generic Class . . . . . . . . . . . . . . . . . . . . . . . . . 380
Type Inference with Generics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
Local Variable Type Inference and Generics . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Erasure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
Bridge Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384
Ambiguity Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386
Some Generic Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Type Parameters Can’t Be Instantiated . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Restrictions on Static Members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
Generic Array Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
Generic Exception Restriction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
Chapter 15 Lambda Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Introducing Lambda Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Lambda Expression Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392
Functional Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393
Some Lambda Expression Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
Block Lambda Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397
Generic Functional Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
Passing Lambda Expressions as Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . 401
Lambda Expressions and Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 404
Lambda Expressions and Variable Capture . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
Method References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Method References to static Methods . . . . . . . . . . . . . . . . . . . . . . . . . . 406
Method References to Instance Methods . . . . . . . . . . . . . . . . . . . . . . . . 407
Method References with Generics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
Constructor References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Predefined Functional Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 418
Chapter 16 Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
Module Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421
A Simple Module Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 422
Compile and Run the First Module Example . . . . . . . . . . . . . . . . . . . . . 426
A Closer Look at requires and exports . . . . . . . . . . . . . . . . . . . . . . . . . . 428

00-FM.indd 14 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

Contents   xv

java.base and the Platform Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429


Legacy Code and the Unnamed Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
Exporting to a Specific Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
Using requires transitive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
Use Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
Service and Service Provider Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436
The Service-Based Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
A Module-Based Service Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 437
Module Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444
Three Specialized Module Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
Open Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
The opens Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
requires static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Introducing jlink and Module JAR Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
Linking Files in an Exploded Directory . . . . . . . . . . . . . . . . . . . . . . . . . 446
Linking Modular JAR Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
JMOD Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
A Brief Word About Layers and Automatic Modules . . . . . . . . . . . . . . . . . . 448
Final Thoughts on Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 448
Chapter 17 Switch Expressions, Records, and Other Recently Added Features . . . . 449
Enhancements to switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
Use a List of case Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Introducing the switch Expression and the yield Statement . . . . . . . . 452
Introducing the Arrow in a case Statement . . . . . . . . . . . . . . . . . . . . . . 454
A Closer Look at the Arrow case . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 456
Another switch Expression Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Text Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Text Block Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
Understanding Leading Whitespace . . . . . . . . . . . . . . . . . . . . . . . . . . . . 460
Use Double Quotes in a Text Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Escape Sequences in Text Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463
Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Record Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
Create Record Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Another Record Constructor Example . . . . . . . . . . . . . . . . . . . . . . . . . . 470
Create Record Getter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Pattern Matching with instanceof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
Pattern Variables in a Logical AND Expression . . . . . . . . . . . . . . . . . . 474
Pattern Matching in Other Statements . . . . . . . . . . . . . . . . . . . . . . . . . . 475
Sealed Classes and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 476
Sealed Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
Sealed Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478
Future Directions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 480

00-FM.indd 15 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

xvi  Java: The Complete Reference

Part II The Java Library


Chapter 18 String Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 483
The String Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
String Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
Special String Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
String Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 486
String Concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
String Concatenation with Other Data Types . . . . . . . . . . . . . . . . . . . . 487
String Conversion and toString( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
Character Extraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
charAt( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
getChars( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
getBytes( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
toCharArray( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
String Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490
equals( ) and equalsIgnoreCase( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
regionMatches( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 491
startsWith( ) and endsWith( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
equals( ) Versus == . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 492
compareTo( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
Searching Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
Modifying a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
substring( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
concat( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
replace( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
trim( ) and strip( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Data Conversion Using valueOf( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
Changing the Case of Characters Within a String . . . . . . . . . . . . . . . . . . . . . 499
Joining Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Additional String Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
StringBuffer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
StringBuffer Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
length( ) and capacity( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503
ensureCapacity( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
setLength( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
charAt( ) and setCharAt( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
getChars( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
append( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
insert( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
reverse( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
delete( ) and deleteCharAt( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
replace( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 507
substring( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
Additional StringBuffer Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 508
StringBuilder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509

00-FM.indd 16 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

Contents   xvii

Chapter 19 Exploring java.lang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511


Primitive Type Wrappers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
Number . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
Double and Float . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
Understanding isInfinite( ) and isNaN( ) . . . . . . . . . . . . . . . . . . . . . . . . 516
Byte, Short, Integer, and Long . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 517
Character . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 526
Additions to Character for Unicode Code Point Support . . . . . . . . . . 528
Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Void . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 532
Executing Other Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 534
Runtime.Version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
ProcessBuilder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 538
Using currentTimeMillis( ) to Time Program Execution . . . . . . . . . . 540
Using arraycopy( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Environment Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
System.Logger and System.LoggerFinder . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
Using clone( ) and the Cloneable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545
ClassLoader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
Math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548
Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
Exponential Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
Rounding Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550
Miscellaneous Math Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
StrictMath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
Thread, ThreadGroup, and Runnable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
The Runnable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
Thread . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
ThreadGroup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 556
ThreadLocal and InheritableThreadLocal . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
ModuleLayer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
RuntimePermission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
Throwable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
SecurityManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 562
StackTraceElement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 563
StackWalker and StackWalker.StackFrame . . . . . . . . . . . . . . . . . . . . . . . . . . . 564
Enum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 564
Record . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565

00-FM.indd 17 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

xviii  Java: The Complete Reference

ClassValue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
The CharSequence Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565
The Comparable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
The Appendable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
The Iterable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 566
The Readable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
The AutoCloseable Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
The Thread.UncaughtExceptionHandler Interface . . . . . . . . . . . . . . . . . . . . 567
The java.lang Subpackages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
java.lang.annotation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
java.lang.constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
java.lang.instrument . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
java.lang.invoke . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
java.lang.management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568
java.lang.module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
java.lang.ref . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
java.lang.reflect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
Chapter 20 java.util Part 1: The Collections Framework . . . . . . . . . . . . . . . . . . . . . . . 571
Collections Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 572
The Collection Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
The Collection Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 574
The List Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
The Set Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
The SortedSet Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
The NavigableSet Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581
The Queue Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
The Deque Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
The Collection Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
The ArrayList Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585
The LinkedList Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
The HashSet Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 590
The LinkedHashSet Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591
The TreeSet Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 592
The PriorityQueue Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593
The ArrayDeque Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 594
The EnumSet Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Accessing a Collection via an Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Using an Iterator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 597
The For-Each Alternative to Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . 599
Spliterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
Storing User-Defined Classes in Collections . . . . . . . . . . . . . . . . . . . . . . . . . . 602
The RandomAccess Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
Working with Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 604
The Map Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
The Map Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612

00-FM.indd 18 22/09/21 6:45 PM


CompRef_2010 / Java: The Complete Reference, Twelfth Edition / Schildt / 126046-341-9

Contents   xix

Comparators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
Using a Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 619
The Collection Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625
Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631
The Legacy Classes and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
The Enumeration Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 636
Vector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 637
Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 641
Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643
Hashtable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 644
Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
Using store( ) and load( ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650
Parting Thoughts on Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 652
Chapter 21 java.util Part 2: More Utility Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
StringTokenizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653
BitSet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655
Optional, OptionalDouble, OptionalInt, and OptionalLong . . . . . . . . . . . . 658
Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 660
Calendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 662
GregorianCalendar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665
TimeZone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 667
SimpleTimeZone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 668
Locale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 669
Random . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 670
Timer and TimerTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 672
Currency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
Formatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676
The Formatter Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676
The Formatter Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677
Formatting Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 677
Formatting Strings and Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
Formatting Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 679
Formatting Time and Date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 681
The %n and %% Specifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
Specifying a Minimum Field Width . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683
Specifying Precision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685
Using the Format Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686
Justifying Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 686
The Space, +, 0, and ( Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 687
The Comma Flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688
The # Flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688
The Uppercase Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 688
Using an Argument Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 689
Closing a Formatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 690
The Java printf( ) Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691

00-FM.indd 19 22/09/21 6:45 PM


Another random document with
no related content on Scribd:
Abb. 63. Dinkelsbühl. Georgskirche. Inneres.
Für ihre Breite erscheint der Pfeiler viel zu schlank. Gerade das
unfeste Stehen ist charakteristisch für die zierliche, unsachliche Art
dieses späten Stiles. Es ist von derselben Art, wenn der Fuß des
Pokales unmittelbar über der Fußplatte ganz schmal wird und der
Leib seine höchste Breite im obersten Rand des Deckels erreicht
(Bd. II Abb. 14), wenn die Monstranz auf durchbrochenem,
gezacktem Fuß schmal emporsteigt, dessen Knoten nicht mehr, wie
beim romanischen Kelch (Abb. 46) Bindung, sondern Auflösung ist,
das Behältnis unter Ornamentwerk, dessen regellose Glieder der
Architektur entnommen sind, fast erstickt und in ganz schmaler
Spitze endigt (Abb. 64), oder wenn die Truhe nun zum
Stollenschrank wird, der auf schlanken hohen Füßen steht und über
und über mit geschnitzten Ornamenten bedeckt ist. Es ist vom
selben Geschmack, wenn die Männertracht der Zeit an den vom
Gewand eng umspannten Beinen spitze Schnabelschuhe fordert und
das bunte Gewand selbst in „Zaddeln“ ausgezackt wird, wenn die
gezierte Form der gotischen Kurve, bis zur martervoll erzwungenen
Biegung übertrieben, für die Frau eine Modesache wird (Abb. 66).
Wir können diese Vorliebe der Zeit für die unruhige Linie genau
verfolgen, sehen, wie man jetzt nicht mehr mit geschlossenen,
sondern wenn möglich mit gegrätschten Beinen sitzt, etwa auf einem
dreieckigen Stuhl, dessen eine Ecke zwischen den Beinen
hervorsteht.
Abb. 64. Spätgotische
Monstranz.
Diese Sucht, den Raum mit Bewegung zu füllen, führt zur
Schaffung ganz neuer kirchlicher Mobilienformen, wie etwa des
Sakramentshäuschens. Das eigentliche Behältnis für das Sakrament
kommt in ihm gar nicht mehr zu Wort. Auf ganz leichten Stützen ruht
es; sogar das Karyatidenmotiv, von dessen momentaner Art schon
die Rede war, findet sich an dem besonders reichen Exemplar der
Gattung, das Adam Kraft in Nürnberg meißelte, in den Gestalten von
Meister und Gesellen wieder. Den Hauptwert, der ein
Bewegungswert ist, trägt ein elegant ansteigender Turm, der in
zierlichstem, spitzenartigem Steinwerk gearbeitet, von überreich
verknoteten Ornamenten umsponnen, mit figürlichen Elementen
durchsetzt ist. Er steigt ganz steil empor und wagt es noch nicht
einmal, spitz zu endigen, sondern rollt die zierliche Spitze zur
Schnecke zusammen.
Es ist also eine gesteigerte Erregtheit des Sehens, die Plastiker
und Maler des 15. Jahrhunderts bis zum Phantastischen führt. Man
hat von ihrer Kunst als dem Beginn einer „deutschen Renaissance“
gesprochen; aber trotzdem die italienische Frührenaissance ihre
Fülle zur gleichen Zeit entfaltet, darf man doch den Stilbegriff nicht
einfach verpflanzen. Denn Masaccio und Donatello stehen am
Anfang einer neuen Bewegung, Schongauer und Riemenschneider
aber sind das letzte Resultat der Gotik, und das, trotzdem sie nahe
am Zeitalter der Reformation und mitten unter ihren Vorboten
stehen. Denn nur im Gegensatz zu unmittelbar Vorhergegangenem
gesehen, bedeutet die Reformation den Beginn eines neuen
Zeitalters. Sie ist es nicht mehr als die Schwärmerei der Kreuzzüge
gegenüber der Selbstverständlichkeit romanischer Hingabe, und die
Steigerung der gotischen Inbrunst führt wiederum zur Reformation.
Wie jene die feudale Oberschicht erregt diese das ganze Volk, und
auch hier ist die Entwicklung des Erlebens in Religion und Kunst
ganz parallel. Es gibt keinen besseren Beweis dafür als die
Geschichte des Kirchenbaues, die nach den Kirchen des frühen
Mittelalters, in denen die Gemeinde von fern den Kulthandlungen,
wie unbeteiligt, folgen mußte, die Pfarrkirche, die der Gemeinde
gehört, zugleich mit der Predigt schafft, weil das Volk das Bedürfnis
nach tieferem Anteil an der Religion hat, und jetzt, zugleich mit der
Forderung gleichen Rechts mit dem Geistlichen, etwa des
Laienkelches, die Hallenkirche als Bau ohne jede Scheidung
entstehen läßt. Und so bereichert man das religiöse Gerät an Zahl
und Form, um es mit den Inhalten eines erweiterten
Vorstellungskreises zu schmücken. Wie das Sakramentshäuschen
entsteht der Altarschrein, der an sich schon eine Auflösung
formstrengerer Gestaltung bedeutet. In der Zeit des romanischen
Stiles war der geweihte Stein der wichtigste Teil des Altars; wollte
man ihn schmücken, so umkleidete man ihn mit getriebenen
Goldplatten und anderem Flachschmuck. Der mittelromanische Stil
bringt dann den Altaraufsatz als oberen Abschluß des Steines, wie
er die strenge Horizontale der Architektur durch die Türme lockert.
Aber erst die Gotik erhebt diesen Altaraufsatz zu einem wichtigen
Teil des Altars, die späte Gotik geradezu zum wichtigsten. Wenn der
Priester der romanischen Zeit auf Reisen ging, so führte er einen
kleinen, geweihten Altarstein, einen sog. Tragaltar, mit. Wenn aber
der Fürst des 15. Jahrhunderts auf Reisen geht, so nimmt er einen
kleinen Flügelaltar als Reisealtar mit. Das Interesse hat sich also
geradezu vom Altar selbst dem Aufsatz zugewandt, der vom
Standpunkt des Gottesdienstes nur Schmuck war, aber ihm mit
seinen Darstellungen bis ins Innerste seines Gefühls folgen konnte.
Die übliche Form ist überall der Flügelaltar (Abb. 65), in Deutschland
von schmaler Staffel aufsteigend, sich zum Schrein verbreiternd und
in spitzem Fialenaufbau endigend, also ein Gebilde vom gleichen
Umriß wie die Monstranz oder das Sakramentshäuschen. Der
Hauptteil ist der mit gemalten oder geschnitzten Darstellungen
gefüllte Mittelschrein, der von zwei innen und außen mit
Darstellungen bedeckten Türen geschlossen wird. Die Entwicklung
scheint zu sein, daß man seine Holzschnitzereien vor Staub
schützen wollte, und daß er später, ohne von der einmal üblich
gewordenen Form abzuweichen, zur gemalten Tafel wird, weil sie die
Möglichkeit bot, durch religiöse Beziehungen verknüpfte
Darstellungen zusammenzustellen. Für das 15. Jahrhundert und die
Folgezeit ist diese Form geradezu ein Gegenstand des
künstlerischen Raffinements. Man wählt die an den Werktagen
sichtbaren Außenflügel in matten Farben, oft grau in grau, um an
Festtagen mit dem Farbenreichtum des inneren Teiles der Flügel
und des Mittelschreins eine um so vollere Festfreude auszudrücken.
Abb. 65. Tilman Riemenschneider. Heiliger
Blutaltar. Rotenburg o. T

Wie die Zahl der Aufgaben wächst die Zahl der Künstler. Die
Kunst ist, eben wegen ihrer reichen Ausdrucksmöglichkeit, eine der
Lebensformen des Zeitalters geworden, von einer Wichtigkeit und
Vielgestaltigkeit wie nur in der späten Antike. In Frankreich und
besonders am Hof der burgundischen Fürsten ist die späte Gotik
eine raffinierte Luxuskunst. Das zerlegte Ornament wird zu einem
höchst sensitiven Organ zierlicher Möbel, zartfarbige Gobelins
schmücken die Wand, und die Buchmalerei schafft ihre luxuriösesten
Livres d’heures. Aus ihr entwickelt sich in der ersten Hälfte des 15.
Jahrhunderts eine Malerreihe, an deren Anfängen die Brüder van
Eyck stehen, starke Seher des wirklichen Seins. Aber spätgotisch
zart sind neben ihnen die Altäre des burgundischen Hofmalers
Rogier van der Weyden, des Hugo van der Goes, der seine Tage im
Kloster beschließt, und des Hans Memling. In Deutschland hat
damals jede Stadt von Bedeutung ihren Malerkreis, der sich in Köln
um Stephan Lochner, in Ulm um Multscher, in Nürnberg um
Wolgemut, am Oberrhein um Witz und Isenmann gruppiert. Und es
ist bezeichnend für den neuen Geschmack, daß in der Plastik das
vielfältiger modellierbare Holz das Hauptmaterial wird — die
wichtigsten Schnitzer sind Tilman Riemenschneider in Franken und
Pacher in Tirol —, und daß der Kupferstich als eine neue Technik
gefunden wird, die ebenfalls gegenüber der Malerei die Möglichkeit
feinerer Durcharbeitung und zarterer Auflösungen bietet (Abb. 66).
Sie wird sofort beliebter als der derbere buchillustrierende
Holzschnitt. Ihre Hauptmeister sind Martin Schongauer in Kolmar,
der sog. Hausbuchmeister, und andere, dem Namen nach nicht
bekannte.
Abb. 66. Martin Schongauer:
Törichte Jungfrau.

Der künstlerische Vortrag wird gesteigert wie in der Architektur:


der Formstil von der Modellierung zur Zerlegung, der Darstellungsstil
von der Einheit zur Fülle. Wie in der späten Antike umfaßt die
Entwicklung gleichzeitig alle Möglichkeiten, werden die beiden
relativen Gegensätze des ruhigen und des bewegten Menschen bis
zur kontrastreichen Zierlichkeit einerseits, bis zum kontrastreichen
Realismus andererseits gesteigert.
Wie sich im geistlichen Schauspiel der Ton bis zur Pöbelhaftigkeit
erniedrigt, bis schließlich aus dem edlen Osterspiel eine wüste
Szene voll Zoten und Schimpfreden geworden ist, in der Hans Wurst
das große Wort führt, so scheut die biblische Darstellung sich vor
keiner Konsequenz eines gegebenen Themas. Die Geißelung
Christi, die Martyrien der heiligen Männer und Frauen werden mit
einer Brutalität, die Physiognomien der Henker voll einer Roheit
dargestellt, die die Charakteristik bis an die Grenze der Karikatur
führen. Es ist kein Zufall, daß mit den Kreuzzügen die
Judenverfolgungen beginnen, und daß sie und die Hexengerichte
jetzt grauenhaften Umfang annehmen. Denn die Roheit ist
charakteristisch für psychisch erregte Zeitalter. Auch in der antiken
Welt kommen die Tierhetzen erst in der parallelen Epoche der
späten Republik, von deren Sensationslust wir sprachen, und die
seltsame Dekadenz der kretisch-mykenischen Zeit kannte ähnliches.
Man wird verstehen, daß die spätantike wie die spätgotische Epoche
auch erotisch äußerst erregt waren. So erklärt es sich vielleicht am
ersten, warum Schongauer neben raufenden Lehrbuben und
polternden Landsknechten die zartesten Frauen zeichnet mit
trippelndem Schritt, mit weich geschwungener Körperlinie, zierlich
geschnittenem Mündchen und zartem Gesichtsoval (Abb. 66). Die
gotische Kurve wird bis zu den unmöglichsten Drehungen gesteigert.
Der Oberkörper der Frau wird zurückgebogen, der Leib
hervorgestreckt, und, wie wir sahen, gilt das nicht nur in der Kunst,
sondern auch in der Wirklichkeit als Schönheitsideal. Wir sprachen
schon von dem Nebeneinander von Zartem und Rohem, das in
Wirklichkeit nur die gleiche Steigerung des Ausdruckes nach zwei
Richtungen bedeutet, wie in der Architektur jetzt größtes
Raumpathos mit zartestem Ornament verknüpft ist. Wie in der
Architektur hört auch in den anderen Künsten die Klarheit auf, eine
Tugend zu sein, und die Überfüllung des Raumes heißt Reichtum,
heißt Schönheit. Wie sich über und zwischen den Skulpturen im
Altarschrein zierliches Rankenwerk ansetzt, so darf in gemalten oder
gestochenen Darstellungen kein leerer Raum im Bilde bleiben. Man
schiebt Bauwerke, Bäume und anderes mit hinein, aber ohne
Rücksicht auf Klarheit des Raumes oder des Vorganges, ja in den
zeichnenden Künsten greift man zu dem Aushilfsmittel, den leeren
Raum einfach mit Ranken und Bandrollen zu füllen.
Es ist dasselbe Gefühl, das den neuen Formstil schafft, ebenfalls
als bloße Bereicherung der gotischen Gewandfigur. Werden die
Körperdrehungen reicher, so werden die Körper selbst nicht klarer
unter den Kleidern, erst in Schongauers letzten Jahren spürt er ein
unklares Bedürfnis nach Formerkenntnis. Gerade hier zeigt sich, daß
Realismus keine Stilform sondern eine Tendenz ist, die jeder Stil
haben kann. Er gründet sich hier nicht auf Formerkenntnis, wie der
Gegensatz zeigt, der scheinbar zwischen den realistischen Köpfen
und den ganz unwirklich stilisierten Gewändern besteht. Vielmehr
werden die Köpfe so faltig durchmodelliert, weil der Stil die reiche
Form braucht, und er findet sie ebenso im Gewand, indem er die
weiche gotische Kurve zerknittert und dadurch vervielfacht, wie die
Architektur das Ornament vervielfachte. Der spätgotische Stil bildet
einen einheitlichen Komplex von Erscheinungen, und die Auflösung
des spätgotischen Altars im Aufbau ist mit den Sterngewölben über
ihm und dem starken Licht- und Schattenspiel in seinen
Schnitzfiguren so völlig in Einklang, wie die Raumdehnung des
Titusbogens mit dem Raumgefühl in seinen Friesen.
Dieser Parallelismus ist tief begründet. Verfolgt man die
Stilentwicklung von Antike und Mittelalter, so zeigt sich eine genaue
Kongruenz. Drei Hauptstufen arbeiten sich heraus: die tektonische,
die einheitlich bewegte und die richtungslos bewegte Stilform, in der
Antike repräsentiert durch den dorischen Tempel, den Zeusaltar von
Pergamon und den Rundtempel von Baalbek, im Mittelalter durch St.
Michael in Hildesheim, das Münster von Straßburg und dessen
Laurentius-Portal. Diese Formen sind nicht nur in der Baukunst
parallel, sondern auch in Gebundenheit, Loslösung und Freiheit von
Plastik und Malerei, selbst in den Phasen des religiösen Erlebens,
die von der ruhigen Hingabe des Glaubens zur enthusiastischen
Hingabe, zur Ekstase und schließlich zur Auflösung führen, und
denen des seelischen Erlebens überhaupt. Innerhalb dieser
Übereinstimmung unterscheiden sich dann freilich alle Details, alle
Einzelerscheinungen genau so weit voneinander, wie sich der
bewußte, einheitliche antike Mensch von dem dumpfen dualistischen
mittelalterlichen Menschen unterscheidet.
Verzeichnis der Abbildungen und
ihrer Quellen.
Abb.
1. Säulenhof im Totentempel des Königs Ne-user-re. Rekonstruktion. Nach
Borchardt, Der Totentempel des Königs Ne-user-re.
2. Lotossäule des alten Reiches. Nach: Die ägyptische Pflanzensäule von
L. Borchardt 1897, nach de Morgan Red. Arch. 1894, S. 28/29.
3. Relief aus dem Grab des Ma-nofer. (Berliner Museum.) Nach
Photographie.
4. Fassade des Tempels von Luksor. Nach Perrot u. Chipiez, Geschichte
der Kunst im Altertum.
5. Ammontempel zu Karnak. Nach Perrot u. Chipiez, Geschichte der Kunst
im Altertum.
6. König Seti I. räuchernd. Nach: Denkmäler ägyptischer Skulptur.
Herausgegeben von Fr. W. von Bissing.
7. Palast von Knossos. Aus Dussaud, Civilisations.
8. Jüngling ein Gefäß tragend. Fresko aus Knossos. Nach Drerup, Homer.
9. Tongefäß aus Kreta. Nach Annual of British School of Athens.
10. Das Löwentor zu Mykenai. Nach Photographie.
11. Tempel des Poseidon zu Pästum. Nach Photographie.
12. Westfront des Tempels von Ägina. (Rekonstruktion von Furtwängler.)
Nach einer Photographie des Modells in der Münchner Glyptothek.
13. Grundrisse des Antentempels Nach Wägner-Baumgarten, Hellas.
14. Grundriß eines Peripteros. Springer-Michaelis, Kunstgeschichte I.
15. Vasenscherbe des sog. Dipylonstiles. Nach Mon. d. Inst. IX.
16. Hydria schwarzfigurigen Stiles aus Caere. (Wiener Museum.) Nach
Furtwängler u. Reichhold, Griechische Vasenmalerei.
17. Amphora rotfigurigen Stiles. Nach Furtwängler u. Reichhold,
Griechische Vasenmalerei.
18. Grabstele des Aristion. Nach Conze, Athenische Grabreliefs I.
19. Westgiebel des Zeustempels zu Olympia. Nach der Rekonstruktion von
Treu.
20. Grabstele der Hegeso. Nach Sauerlandt, Griechische Bildwerke.
21. Athen. Tempel der Nike Apteros. Nach Photographie von Beer.
22. Grundriß des Amphiprostylos. Nach Wägner-Baumgarten, Hellas.
23. Athen. Denkmal des Lysikrates. Nach Winter, Kunstgeschichte in Bildern
I.
24. Amazonenkampf. Denkmäler griech. und röm. Skulptur. Verlagsanstalt
für Kunst und Wissenschaft von Friedr. Bruckmann, München.
25. Zeusaltar von Pergamon. Rekonstruiert von G. Schrammen. Verlag von
Georg Reimer, Berlin.
26. Athena im Gigantenkampf. Relief vom Zeusaltar zu Pergamon.
Heliogravüre von Georg Büchsenstein u. Co. Verlag von Georg Reimer,
Berlin.
27. Isiskult. Fresko aus Herkulanum. Nach Photographie.
28. Pompeji. Haus der Vettier. Peristyl. Nach: Aus dem klassischen Süden.
29. Rom. Inneres des Pantheon.
30. Baalbek. Rundtempel.
31. Spiegel aus Boscoreale. Nach Mon. Piot V.
32. Elfenbeinpyxis im Kaiser-Friedrich-Museum, Berlin. Nach Photographie.
33. Konstantinopel. Inneres der Kirche Hagia Sophia. Nach Photographie.
34. Ravenna. S. Apollinare in classe. Inneres. Nach Dehio und Bezold,
Kirchl. Baukunst des Abendlandes I. Tafel 20, 3 4.
35. Ravenna. S. Vitale. Kapitell und Kämpfer. Nach Photographie.
36. Ravenna. S. Apollinare in classe. Äußeres. Nach Photographie.
37. Ravenna. S. Vitale. Kopf des Justinian vom Mosaik des Altarraumes.
Nach Photographie.
38. Griff und Beschlag vom Schwert des Childerich. Paris. Nach Molinier,
Histoire Générale des Arts Appliqués à l’industrie.
39. Gewandnadel aus einem alemann. Grab. Nach Lindenschmit,
Altertümer.
40. Die vier Evangelisten. Karolingische Buchmalerei. Aus einer
Evangelienhandschrift in Aachen.
41. Hildesheim. St. Godehard. Äußeres. Nach einer Aufnahme der Neuen
Photographischen Gesellschaft A.-G., Steglitz-Berlin.
42. Portal der Marienkirche in Gelnhausen.
43. Hildesheim. St. Michael. Inneres. Originalaufnahme der Königlich
Preußischen Meßbildanstalt zu Berlin.
44. Köln. St. Gereon. Krypta. Nach Photographie.
45. Sündenfall an der Decke von St. Michael zu Hildesheim.
Originalaufnahme der Kgl. Preuß. Meßbildanstalt zu Berlin.
46. Kelch von Wilthen. Aus Geschichte des Deutschen Kunstgewerbes von
Jakob v. Falke.
47. System des Domes zu Mainz. Nach Springer, Handbuch der
Kunstgeschichte.
48. Gotisches System. (Kathedrale zu Amiens.) Nach Viollet-le-Duc.
49. System der Kathedrale von Noyon. Nach Springer, Handbuch der
Kunstgeschichte II.
50. Frühgotisches Hörnerkapitell. Nach Vitry-Briere, Sculpt. Franç. d. M. A.
51. Paris. Notre Dame. Fassade. Nach Photographie.
52. Limburg a. L. Dom. Inneres. Nach Dehio und v. Bezold.
53. Marienreliquiar im Dome zu Aachen. Nach Springer, Handbuch der
Kunstgeschichte II.
54. Inneres und äußeres System des Domes zu Reims. Nach Dehio u. v.
Bezold, Kirchl. Baukunst.
55. Straßburg. Dom. Inneres. Nach Springer, Handbuch II.
56. Gotisches Pfeilerkapitell. Nach Vitry-Briere, Sculpture Franç. d. M. A.
57. Grundriß des Domes zu Köln. Nach Springer, Handbuch II.
58. Köln. Dom. Fassade.
59. Karlsreliquiar. Bologna. Nach Hirths Formenschatz.
60. Portalskulpturen an der Kathedrale zu Reims. Nach Photographie.
61. Gotische Skulptur (Kluge Jungfrau). Aus Hartmann, Die gotische
Monumentalplastik in Schwaben.
62. Straßburg. Dom. Laurentius-Portal. Nach Photographie des
Dombauamts zu Straßburg.
63. Dinkelsbühl. Georgskirche. Inneres. Nach Lübke-Semrau II.
64. Spätgotische Monstranz. Nach Knackfuß, Kunstgeschichte.
65. Tilman Riemenschneider: Heiliger Blutaltar. Rotenburg o. T.
66. Martin Schongauer: Törichte Jungfrau. Nach Max Lehrs.
Die Sammlung

„Aus Natur und Geisteswelt“


nunmehr schon über 600 Bändchen umfassend, sucht seit ihrem Entstehen
dem Gedanken zu dienen, der heute in das Wort: „F r e i e B a h n d e m
T ü c h t i g e n ! “ geprägt ist. Sie will die Errungenschaften von Wissenschaft,
Kunst und Technik e i n e m j e d e n z u g ä n g l i c h machen, ihn dabei
zugleich unmittelbar im B e r u f f ö r d e r n , den G e s i c h t s k r e i s
e r w e i t e r n d , die E i n s i c h t in die Bedingungen der Berufsarbeit
vertiefend.
Sie bietet wirkliche „E i n f ü h r u n g e n “ in die Hauptwissensgebiete für
den U n t e r r i c h t o d e r S e l b s t u n t e r r i c h t d e s L a i e n , wie sie den
heutigen methodischen Anforderungen entsprechen. So erfüllt sie ein
Bedürfnis, dem Skizzen, die den Charakter von „Auszügen“ aus großen
Lehrbüchern tragen, nie entsprechen können; denn solche setzen vielmehr
eine Vertrautheit mit dem Stoffe schon voraus.
Sie bietet aber auch dem F a c h m a n n eine r a s c h e z u v e r l ä s s i g e
Ü b e r s i c h t über die sich heute von Tag zu Tag weitenden Gebiete des
geistigen Lebens in weitestem Umfang und vermag so vor allem auch dem
immer stärker werdenden Bedürfnis des F o r s c h e r s zu dienen, sich a u f
d e n N a c h b a r g e b i e t e n auf dem laufenden zu erhalten.
In den Dienst dieser Aufgabe haben sich darum auch in dankenswerter
Weise von Anfang an die besten Namen gestellt, gern die Gelegenheit
benutzend, sich an weiteste Kreise zu wenden, an ihrem Teil bestrebt, der
Gefahr der „Spezialisierung“ unserer Kultur entgegenzuarbeiten.
So konnte der Sammlung auch der Erfolg nicht fehlen. Mehr als die Hälfte
der Bändchen liegen, bei jeder Auflage durchaus neu bearbeitet, bereits in 2.
bis 6. Auflage vor, insgesamt hat die Sammlung bis jetzt eine Verbreitung von
weit über 4 Millionen Exemplaren gefunden.
Alles in allem sind die schmücken, gehaltvollen Bände besonders
geeignet, die Freude am Buche zu wecken und daran zu gewöhnen, einen
kleinen Betrag, den man für Erfüllung körperlicher Bedürfnisse nicht
anzusehen pflegt, auch für die Befriedigung geistiger anzuwenden. Durch den
billigen Preis ermöglichen sie es tatsächlich jedem, auch dem wenig
Begüterten, sich eine Bücherei zu schaffen, die das für ihn Wertvollste „Aus
Natur und Geisteswelt“ vereinigt.
Jedes der meist reich illustrierten Bändchen
ist in sich abgeschlossen und einzeln käuflich
Jedes Bändchen geheftet M. 1.20, gebunden M. 1.50
Teuerungszuschläge 30% einschließl. 10% Zuschlag der Buchhandlung

Leipzig, im Juni 1918. B. G. Teubner


Jedes Bändchen geheftet M. 1.20, gebunden M. 1.50

Zur bildenden Kunst, Musik und


Schauspielkunst
sind bisher erschienen:

Bildende Kunst
Allgemeines:
Das Wesen der deutschen bildenden Kunst. Von Geh. Rat Prof. Dr.
H . T h o d e . (Bd. 585.)
Bau und Leben der bildenden Kunst. Von Direktor Prof. Dr. T h .
V o l b e h r . 2. Aufl. Mit 44 Abbildungen. (Bd. 68.)
Kunstpflege in Haus und Heimat. Von weil. Superintendent R .
B ü r k n e r . 3. Auflage. Mit 29 Abbildungen. (Bd. 77.)
Ästhetik. Von Prof. Dr. R . H a m a n n . 2. Aufl. (Bd. 345.)
*Einführung in die Geschichte der Ästhetik. Von Privatdozent Dr.
H . N o h l . (Bd. 602.)
Geometrisches Zeichnen. Von akad. Zeichenlehrer A.
S c h u d e i s k y . Mit Fig. (Bd. 568.)
Projektionslehre. Die rechtwinklige Parallelprojektion und ihre
Anwendung auf die Darstellung technischer Gebilde nebst einem
Anhang über die schiefwinklige Parallelprojektion in kurzer
leichtfaßlicher Darstellung für Selbstunterricht und Schulgebrauch.
Von akad. Zeichenlehrer A . S c h u d e i s k y . Mit 208 Figuren im Text.
(Bd. 564.)
Grundzüge der Perspektive nebst Anwendungen. Von Prof. Dr. K .
D o e h l e m a n n . Mit 91 Fig. u. 11 Abb. (Bd. 510.)
Der Weg zur Zeichenkunst. Ein Büchlein für theoretische und
praktische Selbstbildung. Von Dr. E . W e b e r . 2. Aufl. Mit 81
Abbildungen und 1 Farbtafel. (Bd. 430.)

Geschichte:
Die Entwicklungsgeschichte d. Stile in d. bildenden Kunst. Von
Dr. E . C o h n - W i e n e r . 2 Bde. 2. Aufl. (Auch in 1 Bd. geb.) Bd. I:
Vom Altertum bis zur Gotik. Mit 66 Abb. (Bd. 317.) Bd. II: Von d.
Renaissance b. z. Gegenw. M. 42 Abb. (Bd. 318.)
*Wörterbuch zur Kunstgeschichte. Von Dr. E . C o h n - W i e n e r .
(Teubners kleine Fachwörterbücher. Geb. ca. M. 3.—.)

Altertum:
Die Blütezeit der griechischen Kunst im Spiegel der
Reliefsarkophage. Eine Einführung in die griechische Plastik. Von
Prof. Dr. H . W a c h t l e r . Mit 8 Tafeln und 32 Abb. (Bd. 272.)
Pompeji, eine hellenistische Stadt in Italien. Von Prof. Dr. F r . v .
D u h n . 3. Aufl. Mit 62 Abbildungen im Text und auf einer Tafel, sowie
einem Plan. (Bd. 114.)

Mittelalter und Neuzeit:


Deutsche Baukunst im Mittelalter. Von Geh. Reg.-Rat Prof. Dr. A .
M a t t h a e i . I: Von den Anfängen bis zum Ausgang der romanischen
Baukunst. Mit 42 Abb. im Text und auf einer Doppeltafel. II: Gotik und
Spätgotik. 4. Aufl. Mit zahlr. Abb. (Bd. 8–9.)
Die altdeutschen Maler in Süddeutschland. Von H . N e m i t z . Mit
1 Abbildung im Text und einem Bilderanhang. (Bd. 464.)
Albrecht Dürer. Von weil. Prof. Dr. R . W u s t m a n n . 2. Aufl. von
Geh. Reg.-Rat Prof. Dr. A . M a t t h a e i . Mit Titelbild und zahlr. Abb.
(Bd. 97.)
Die Renaissancearchitektur in Italien I. Von Dr. P. F r a n k l . Mit 12
Tafeln und 27 Textabbildungen. (Bd. 331.) II. In Vorb. (Bd. 362.)
Michelangelo. Eine Einführung in das Verständnis seiner Werke. Von
Prof. Dr. E . H i l d e b r a n d t . Mit 44 Abbildungen. (Bd. 392.)
Niederländische Malerei im 17. Jahrhundert. Von Prof. Dr. H .
J a n t z e n . Mit 37 Abbildungen. (Bd. 373.)
Rembrandt. Von Prof. Dr. P. S c h u b r i n g . 2., verb. Aufl. Mit 48
Abbildungen auf 28 Tafeln im Anhang. (Bd. 158.)
Deutsche Baukunst seit dem Mittelalter bis zum Ausgang des 18.
Jahrhunderts: Renaissance, Barock, Rokoko. Von Geh. Reg.-Rat
Prof. Dr. A . M a t t h a e i . 2. Aufl. Mit Abbildungen und Tafeln. (Bd.
326.)

19. Jahrhundert:
Deutsche Baukunst im 19. Jahrhundert. Von Geh. Reg.-Rat Prof.
Dr. A . M a t t h a e i . Mit 35 Abbildungen. (Bd. 453.)
Die deutsche Malerei im 19. Jahrhundert. Von Prof. Dr. R .
H a m a n n . 2 Bände Text, 2 Bände mit 57 ganzseitigen und 200
halbseitigen Abbildungen (Bd. 448–451, in 2 Doppelbänden je geh. M.
2.40, geb. M. 3.—, auch in 1 Halbpergamentband M. 7.—)
Die Maler des Impressionismus. Von Prof. Dr. B . L á z à r . Mit 92
Abbildungen und 1 farbigen Tafel. (Bd. 395.)

Kunstgewerbe:
Die dekorative Kunst des Altertums. V. Dr. F r . P o u l s e n . M. 112
Abb. (Bd. 454.)
Deutsche Kunst im tägl. Leben bis zum Schlusse d. 18.
Jahrhunderts. Von Prof. Dr. B . H a e n d c k e . Mit 63 Abbildungen.
(Bd. 198.)
Geschichte der Gartenkunst. Von Baurat Dr.-Ing. C h r . R a n c k .
Mit 41 Abb. (B. 274.)
Die künstlerische Photographie. Ihre Entwicklung, ihre Probleme,
ihre Bedeutung. Von Dr. M . W a r s t a t . Mit 12 Tafeln. (Bd. 410.)

Musik
Geschichte der Musik. Von Dr. A l f r e d E i n s t e i n . (Bd. 436.)
Beispielsammlung zur älteren Musikgeschichte. Von Dr. A .
E i n s t e i n . (Bd. 439.)
Haydn, Mozart, Beethoven. Von Prof. Dr. C . K r e b s . 2. Aufl. M. 4
Bildn. (Bd. 92.)
Die Blütezeit der musikalischen Romantik in Deutschland. Von Dr.
E . I s t e l . Mit 1 Silhouette. (Bd. 239.)
Das Kunstwerk Richard Wagners. Von Dr. E . I s t e l . 2. Aufl. Mit 1
Bildnis Richard Wagners. (Bd. 330.)
Die moderne Oper. Vom Tode Wagners bis zum Weltkrieg (1888–
1914). Von Dr. E . I s t e l . Mit 3 Bildnissen. (Bd. 495.)
Die Grundlagen der Tonkunst. Versuch einer entwickelnden
Darstellung der allgemeinen Musiklehre. Von Prof. Dr. H . R i e t s c h .
2., durchgesehene Auflage. (Bd. 178.)
Musikalische Kompositionsformen. Von S . G . K a l l e n b e r g . 2
Bände. Bd. I: Die elementaren Tonverbindungen als Grundlage der
Harmonielehre. Bd. II: Kontrapunktik und Formenlehre. (Bd. 412 u.
413, auch in 1 Band gebunden.)
*Harmonielehre. Von Dr. H . S c h o l z . (Bd. 560.)
Das moderne Orchester in seiner Entwicklung. Von Prof. Dr. F r .
V o l b a c h . 3. Aufl. Mit Partiturbeispielen u. Tafeln. (Bd. 308.)
Die Instrumente des Orchesters. V. Prof. Dr. F r . V o l b a c h . Mit 60
Abb. (Bd. 384.)
Klavier, Orgel, Harmonium. Das Wesen der Tasteninstrumente. Von
Professor Dr. O . B i e . (Bd. 325.)

Schauspielkunst
Das Theater. Schauspielhaus und Schauspielkunst vom griechischen
Altertum bis auf die Gegenwart. Von Dr. C h r . G a e h d e . 2. Aufl. Mit
18 Abb. (Bd. 280.)
Die griechische Tragödie. Von Prof. Dr. J . G e f f c k e n . Mit 5
Abbildungen im Text und 1 Tafel. (Bd. 566.)
Die griechische Komödie. Von Prof. Dr. A . K ö r t e . M. Titelb. u. 2
Taf. (Bd. 400.)
Das Drama. Von weil. Dr. B . B u s s e . Mit 3 Abb. 3 Bde. I: Von der
Antike z. franz. Klassizismus. 2. Auflage, neu bearbeitet von
Oberlehrer Dr. N i e d l i c h , Prof. Dr. R . I m e l m a n n und Prof. Dr.
G l a s e r . II: Von Versailles bis Weimar. III: Von der Romantik zur
Gegenwart. (Bd. 287/289.)
Das deutsche Drama des 19. Jahrhunderts. In seiner Entwicklung
dargestellt von Prof. Dr. G . W i t k o w s k i . 4. Auflage. Mit 1 Bildnis
Hebbels. (Bd. 51.)

You might also like