Transcription of Core Java® Volume II—Advanced Features
1 Core Java Volume II advanced FeaturesNinth EditionThis page intentionally left blank Core Java Volume II AdvancedFeaturesNinth EditionCay S. HorstmannGary CornellUpper Saddle River, NJ Boston Indianapolis San FranciscoNew York Toronto Montreal London Munich Paris MadridCapetown Sydney Tokyo Singapore Mexico CityMany of the designations used by manufacturers and sellers to distinguish their products are claimed astrademarks. 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 and Java are registered trademarks of Oracle and/or its affiliates.
2 Other names may be trademarks of theirrespective authors and publisher have taken care in the preparation of this book, but make no expressed or impliedwarranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidentalor consequential damages in connection with or arising out of the use of the information or programs document is provided for information purposes only and the contents hereof are subject to change withoutnotice. This document is not warranted to be error-free, nor subject to any other warranties or conditions, whetherexpressed orally or implied in law, including implied warranties and conditions of merchantability or fitness fora particular purpose.
3 We specifically disclaim any liability with respect to this document and no contractualobligations are formed either directly or indirectly by this document. This document may not be reproduced ortransmitted in any form or by any means, electronic or mechanical, for any purpose, without our prior 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, traininggoals, marketing focus, and branding interests. For more information, please Corporate and Government Sales(800) sales outside the United States, please contact:International us on the Web: of Congress Cataloging-in-Publication Data:Horstmann, Cay S.
4 , 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. 2013 '3 dc23 2012035397 Copyright 2013 Oracle and/or its affiliates. All rights Oracle Parkway, Redwood Shores, CA 94065 Printed in the United States of America. This publication is protected by copyright, and permission must beobtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmissionin any form or by any means, electronic, mechanical, photocopying, recording, or likewise.
5 To obtain permissionto 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) : 978-0-13-708160-8 ISBN-10: 0-13-708160-XText printed in the United States on recycled paper at Edwards Brothers Malloy in Ann Arbor, printing, September 2013xvPreface ..xixAcknowledgments ..1 Chapter 1: Streams and Files ..2 Streams .. and Writing Bytes .. Complete Stream Zoo .. Stream Filters .. Input and Output .. to Write Text Output.
6 To Read Text Input .. Objects in Text Format .. Sets .. and Writing Binary Data .. Files .. Archives .. Streams and Serialization .. the Object Serialization File Format .. the Default Serialization Mechanism .. Singletons and Typesafe Enumerations .. Serialization for Cloning .. with Files .. and Writing Files .. , Moving, and Deleting Files .. Files and Directories .. File Information .. over the Files in a Directory .. File Systems .. Files .. Buffer Data Structure .. Locking .. Expressions .. 2: XML ..94 Introducing XML .. Structure of an XML Document.
7 An XML Document .. XML Documents .. Type Definitions .. Schema .. Practical Example .. Information with XPath .. Namespaces .. Parsers .. the SAX Parser .. the StAX Parser .. XML Documents .. without Namespaces .. with Namespaces .. Documents .. Example: Generating an SVG File .. an XML Document with StAX .. Transformations .. 3: Networking ..185 Connecting to a Server .. Timeouts .. Addresses .. Servers .. Multiple Clients .. Sockets .. Web Data .. and URIs .. a URLC onnection to Retrieve Information .. Form Data .. E-Mail .. 4: Database Programming.
8 236 The Design of JDBC .. Driver Types .. Uses of JDBC .. Structured Query Language .. Configuration .. URLs .. JAR Files .. the Database .. the Driver Class .. to the Database .. SQL Statements .. Connections, Statements, and Result Sets .. SQL Exceptions .. a Database .. Execution .. Statements .. and Writing LOBs .. Escapes .. Results .. Autogenerated Keys .. and Updatable Result Sets .. Result Sets .. Result Sets .. Sets .. Row Sets .. Row Sets .. Points .. Updates .. SQL Types .. Management in Web and Enterprise Applications .. 5: Internationalization.
9 306 Locales .. Formats .. and Time .. Strength .. Formatting .. Formats .. Files and Character Sets .. Encoding of Source Files .. Bundles .. Resource Bundles .. Files .. Classes .. Complete Example .. 6: advanced Swing ..364 Lists .. JListComponent .. Models .. and Removing Values .. Values .. Simple Table .. Models .. with Rows and Columns .. Classes .. Table Columns .. Columns .. Rows .. Rows, Columns, and Cells .. Rows .. Rows .. and Displaying Columns .. Rendering and Editing .. the Header .. Editing .. Editors .. Trees .. Trees and Tree Paths.
10 Enumeration .. Nodes .. to Tree Events .. Tree Models .. Components .. Tracking in Text Components .. Input Fields .. Input .. on Loss of Focus .. Standard Formatters .. Formatters .. JSpinnerComponent .. HTML with the JEditorPane .. Indicators .. Bars .. Monitors .. the Progress of Input Streams .. Organizers and Decorators .. Panes .. Panes .. Panes and Internal Frames .. and Tiling .. Property Settings .. in Internal Frames .. Dragging .. 7: advanced AWT ..550 The Rendering Pipeline .. the Shape Classes .. Transformations .. and Composition.