PDF by Landray transform
Core Java® Volume II—Advanced FeaturesCore Java® Volume II—Advanced Features
Ninth EditionNinth Edition
Cay S. HorstmannCay S. Horstmann
Gary CornellGary Cornell
Upper Saddle River, NJ • Boston • Indianapolis • San Francisco
New York • Toronto • Montreal • London • Munich • Paris • Madrid
Capetown • Sydney • Tokyo • Singapore • Mexico City
PDF by Landray transform
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where
those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed
with initial capital letters or in all capitals.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.
The authors and publisher have taken care in the preparation of this book, but make no expressed or implied warranty of any
kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in
connection with or arising out of the use of the information or programs contained herein.
This document is provided for information purposes only and the contents hereof are subject to change without notice. This
document is not warranted to be error-free, nor subject to any other warranties or conditions, whether expressed orally or
implied in law, including implied warranties and conditions of merchantability or fitness for a particular purpose. We
specifically disclaim any liability with respect to this document and no contractual obligations are formed either directly
or indirectly by this document. This document may not be reproduced or transmitted in any form or by any means, electronic or
mechanical, for any purpose, without our prior written permission.
The publisher offers excellent discounts on this book when ordered in quantity for bulk purchases or special sales, which may
include electronic versions and/or custom covers and content particular to your business, training goals, marketing focus,
and branding interests. For more information, please contact:
U.S. Corporate and Government Sales
(800) 382-3419
corpsales@pearsontechgroup.com
For sales outside the United States, please contact:
International Sales
international@pearson.com
Visit us on the Web: informit.com/ph
Library of Congress Cataloging-in-Publication Data:
Horstmann, Cay S., 1959-
Core Java / Cay S. Horstmann, Gary Cornell.—Ninth edition.
pages cm
Includes index.
ISBN 978-0-13-708189-9 (v. 1 : pbk. : alk. paper) 1. Java (Computer program
language) I. Cornell, Gary. II. Title.
QA76.73.J38H6753 2013
005.13'3—dc23
2012035397
Copyright © 2013 Oracle and/or its affiliates. All rights reserved.
500 Oracle Parkway, Redwood Shores, CA 94065
Printed in the United States of America. This publication is protected by copyright, and permission must be obtained from the
publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means,
electronic, mechanical, photocopying, recording, or likewise. To obtain permission to use material from this work, please
submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey
07458, or you may fax your request to (201) 236-3290.
ISBN-13: 978-0-13-708160-8
ISBN-10: 0-13-708160-X
Text printed in the United States on recycled paper at Edwards Brothers Malloy in Ann Arbor, Michigan.
First printing, February 2013
PDF by Landray transform
ContentsContents
Preface
Acknowledgments
Chapter 1: Streams and FilesChapter 1: Streams and Files
1.1 Streams
1.1.1 Reading and Writing Bytes
1.1.2 The Complete Stream Zoo
1.1.3 Combining Stream Filters
1.2 Text Input and Output
1.2.1 How to Write Text Output
1.2.2 How to Read Text Input
1.2.3 Saving Objects in Text Format
1.2.4 Character Sets
1.3 Reading and Writing Binary Data
1.3.1 Random-Access Files
1.4 ZIP Archives
1.5 Object Streams and Serialization
1.5.1 Understanding the Object Serialization File Format
1.5.2 Modifying the Default Serialization Mechanism
1.5.3 Serializing Singletons and Typesafe Enumerations
1.5.4 Versioning
1.5.5 Using Serialization for Cloning
1.6 Working with Files
1.6.1 Paths
1.6.2 Reading and Writing Files
1.6.3 Copying, Moving, and Deleting Files
1.6.4 Creating Files and Directories
1.6.5 Getting File Information
1.6.6 Iterating over the Files in a Directory
1.6.7 ZIP File Systems
1.7 Memory-Mapped Files
1.7.1 The Buffer Data Structure
1.7.2 File Locking
1.8 Regular Expressions
Chapter 2: XMLChapter 2: XML
2.1 Introducing XML
2.1.1 The Structure of an XML Document
2.2 Parsing an XML Document
2.3 Validating XML Documents
2.3.1 Document Type Definitions
2.3.2 XML Schema
2.3.3 A Practical Example
2.4 Locating Information with XPath
2.5 Using Namespaces
2.6 Streaming Parsers
2.6.1 Using the SAX Parser
2.6.2 Using the StAX Parser
2.7 Generating XML Documents
2.7.1 Documents without Namespaces
2.7.2 Documents with Namespaces
2.7.3 Writing Documents
2.7.4 An Example: Generating an SVG File
2.7.5 Writing an XML Document with StAX
2.8 XSL Transformations
Chapter 3: NetworkingChapter 3: Networking
3.1 Connecting to a Server
3.1.1 Socket Timeouts
3.1.2 Internet Addresses
PDF by Landray transform
3.2 Implementing Servers
3.2.1 Serving Multiple Clients
3.2.2 Half-Close
3.3 Interruptible Sockets
3.4 Getting Web Data
3.4.1 URLs and URIs
3.4.2 Using a URLConnection to Retrieve Information
3.4.3 Posting Form Data
3.5 Sending E-Mail
Chapter 4: Database ProgrammingChapter 4: Database Programming
4.1 The Design of JDBC
4.1.1 JDBC Driver Types
4.1.2 Typical Uses of JDBC
4.2 The Structured Query Language
4.3 JDBC Configuration
4.3.1 Database URLs
4.3.2 Driver JAR Files
4.3.3 Starting the Database
4.3.4 Registering the Driver Class
4.3.5 Connecting to the Database
4.4 Executing SQL Statements
4.4.1 Managing Connections, Statements, and Result Sets
4.4.2 Analyzing SQL Exceptions
4.4.3 Populating a Database
4.5 Query Execution
4.5.1 Prepared Statements
4.5.2 Reading and Writing LOBs
4.5.3 SQL Escapes
4.5.4 Multiple Results
4.5.5 Retrieving Autogenerated Keys
4.6 Scrollable and Updatable Result Sets
4.6.1 Scrollable Result Sets
4.6.2 Updatable Result Sets
4.7 Row Sets
4.7.1 Constructing Row Sets
4.7.2 Cached Row Sets
4.8 Metadata
4.9 Transactions
4.9.1 Save Points
4.9.2 Batch Updates
4.9.3 Advanced SQL Types
4.10 Connection Management in Web and Enterprise Applications
Chapter 5: InternationalizationChapter 5: Internationalization
5.1 Locales
5.2 Number Formats
5.2.1 Currencies
5.3 Date and Time
5.4 Collation
5.4.1 Collation Strength
5.4.2 Decomposition
5.5 Message Formatting
5.5.1 Choice Formats
5.6 Text Files and Character Sets
5.6.1 Character Encoding of Source Files
5.7 Resource Bundles
5.7.1 Locating Resource Bundles
5.7.2 Property Files
5.7.3 Bundle Classes
5.8 A Complete Example
Chapter 6: Advanced SwingChapter 6: Advanced Swing
6.1 Lists
PDF by Landray transform