
Core Java Volume II–Advanced Features Eleventh Edition This page intentionally left blank Core Java Volume II–Advanced Features Eleventh Edition Cay S. Horstmann Boston • Columbus • New York • San Francisco • Amsterdam • Cape Town Dubai • London • Madrid • Milan • Munich • Paris • Montreal • Toronto • Delhi • Mexico City São Paulo • Sydney • Hong Kong • Seoul • Singapore • Taipei • Tokyo The author 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. For information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at [email protected] or (800) 382-3419. For government sales inquiries, please contact [email protected]. For questions about sales outside the United States, please contact [email protected]. Visit us on the Web: informit.com Library of Congress Preassigned Control Number: 2018963595 Copyright © 2019 Pearson Education Inc. Portions copyright © 1996-2013 Oracle and/or its affiliates. All Rights Reserved. Oracle America Inc. does not make any representations or warranties as to the accuracy, adequacy or completeness of any information contained in this work, and is not responsible for any errors or omissions. Microsoft and/or its respective suppliers make no representations about the suitability of the information contained in the documents and related graphics published as part of the services for any purpose. All such documents and related graphics are provided "as is" without warranty of any kind. Microsoft and/or its respective suppliers hereby disclaim all warranties and conditions with regard to this information, including all warranties and conditions of merchantability, whether express, implied or statutory, fitness for a particular purpose, title and non-infringement. In no event shall Microsoft and/or its respective suppliers be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of information available from the services. The documents and related graphics contained herein could include technical inaccuracies or typographical errors. Changes are periodically added to the information herein. Microsoft and/or its respective suppliers may make improvements and/or changes in the product(s) and/or the program(s) described herein at any time. Partial screen shots may be viewed in full within the software version specified. Microsoft® Windows®, and Microsoft Office® are registered trademarks of the Microsoft Corporation in the U.S.A. and other countries. This book is not sponsored or endorsed by or affiliated with the Microsoft Corporation. All rights reserved. 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. For information regarding permissions, request forms and the appropriate contacts within the Pearson Education Global Rights & Permissions Department, please visit www.pearsoned.com/permissions/. ISBN-13: 978-0-13-516631-4 ISBN-10: 0-13-516631-4 1 19 Contents Preface ........................................................................................................... xv Acknowledgments ......................................................................................... xxi Chapter 1: Streams ........................................................................................ 1 1.1 From Iterating to Stream Operations ................................................. 2 1.2 Stream Creation ................................................................................... 5 1.3 The filter, map, and flatMap Methods ................................................... 11 1.4 Extracting Substreams and Combining Streams ............................. 12 1.5 Other Stream Transformations ......................................................... 14 1.6 Simple Reductions .............................................................................. 15 1.7 The Optional Type ............................................................................. 16 1.7.1 Getting an Optional Value .................................................. 17 1.7.2 Consuming an Optional Value ............................................ 17 1.7.3 Pipelining Optional Values .................................................. 18 1.7.4 How Not to Work with Optional Values ........................... 19 1.7.5 Creating Optional Values .................................................... 20 1.7.6 Composing Optional Value Functions with flatMap ........... 21 1.7.7 Turning an Optional into a Stream .................................... 22 1.8 Collecting Results ............................................................................... 25 1.9 Collecting into Maps .......................................................................... 30 1.10 Grouping and Partitioning ................................................................ 34 1.11 Downstream Collectors ..................................................................... 36 1.12 Reduction Operations ........................................................................ 41 1.13 Primitive Type Streams ..................................................................... 43 1.14 Parallel Streams .................................................................................. 48 Chapter 2: Input and Output ........................................................................ 55 2.1 Input/Output Streams ........................................................................ 56 2.1.1 Reading and Writing Bytes .................................................. 56 2.1.2 The Complete Stream Zoo ................................................. 59 v vi Contents 2.1.3 Combining Input/Output Stream Filters ............................ 63 2.1.4 Text Input and Output ......................................................... 68 2.1.5 How to Write Text Output .................................................. 68 2.1.6 How to Read Text Input ...................................................... 70 2.1.7 Saving Objects in Text Format ............................................ 72 2.1.8 Character Encodings ............................................................. 75 2.2 Reading and Writing Binary Data .................................................... 78 2.2.1 The DataInput and DataOutput interfaces ................................... 78 2.2.2 Random-Access Files ............................................................ 80 2.2.3 ZIP Archives .......................................................................... 85 2.3 Object Input/Output Streams and Serialization ............................. 88 2.3.1 Saving and Loading Serializable Objects ........................... 88 2.3.2 Understanding the Object Serialization File Format .................................................................................... 93 2.3.3 Modifying the Default Serialization Mechanism ............. 100 2.3.4 Serializing Singletons and Typesafe Enumerations ........ 102 2.3.5 Versioning ............................................................................ 103 2.3.6 Using Serialization for Cloning ......................................... 106 2.4 Working with Files ........................................................................... 109 2.4.1 Paths ..................................................................................... 109 2.4.2 Reading and Writing Files ................................................. 112 2.4.3 Creating Files and Directories ........................................... 113 2.4.4 Copying, Moving, and Deleting Files ............................... 114 2.4.5 Getting File Information ..................................................... 116 2.4.6 Visiting Directory Entries ................................................... 118 2.4.7 Using Directory Streams .................................................... 120 2.4.8 ZIP File Systems .................................................................. 123 2.5 Memory-Mapped Files ..................................................................... 124 2.5.1 Memory-Mapped File Performance .................................. 125 2.5.2 The Buffer Data Structure .................................................. 132 2.6 File Locking ....................................................................................... 134 2.7 Regular Expressions ......................................................................... 137 2.7.1 The Regular Expression Syntax ......................................... 137 2.7.2 Matching a String ............................................................... 142 2.7.3 Finding Multiple Matches .................................................. 145 Contents vii 2.7.4 Splitting along Delimiters .................................................
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages180 Page
-
File Size-