Java A Beginner's Guide, 6th Edition PDF
Document Details
Uploaded by Deleted User
Herbert Schildt
Tags
Summary
This is a Java textbook, 6th edition, focusing on introductory programming concepts. It's written by Herbert Schildt, a leading authority on Java, C++, C, and C# languages. The book covers Java language and programming.
Full Transcript
® The Java Complete Eighth Edition Reference ™ About the Author Herbert Schildt is a leading authority on the Java, C++, C, and C# languages. His programming books have sold millions of copies worldwide and have been translated into all major foreign langua...
® The Java Complete Eighth Edition Reference ™ About the Author Herbert Schildt is a leading authority on the Java, C++, C, and C# languages. His programming 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, Swing: A Beginner’s Guide, and The Art of Java. Among his other bestsellers are C++: The Complete Reference™, C#: The Complete Reference™, and C: The Complete Reference™. Although interested in all facets of computing, his primary focus is computer languages, including compilers, interpreters, and robotic control languages. He also has an active interest in the standardization of languages. Schildt holds both graduate and undergraduate degrees from the University of Illinois. He can be reached at his consulting office at (217) 586-4683. His web site is www.HerbSchildt.com. About the Technical Editor Dr. Danny Coward has been a contributor to the Java Platforms since 1997. He was a founding member of the Java EE group while at Sun. He has served as a member of the Java Community Process Executive Committee and has been a leading contributor to all editions of the Java Platform—Java SE, Java ME, and Java EE—and established the original JavaFX team. ® The Java Complete Eighth Edition Reference™ Herbert Schildt New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto Copyright © 2011 by The McGraw-Hill Companies. All rights reserved. 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-0-07-160631-8 MHID: 0-07-160631-9 The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-160630-1, MHID: 0-07-160630-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 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 e-mail us at [email protected]. Trademarks: McGraw-Hill, the McGraw-Hill Publishing logo, Complete Reference™, and related trade dress are trademarks or registered trademarks of The McGraw-Hill Companies and/or its affiliates in the United States and other countries and may not be used without written permission. All other trademarks are the property of their respective owners. The McGraw-Hill Companies is not associated with any product or vendor mentioned in this book. Information has been obtained by Publisher from sources believed to be reliable. However, because of the possibility of human or mechanical error by our sources, Publisher, or others, Publisher does not guarantee to the accuracy, adequacy, or completeness of any information included in this work 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 information contained in this Work, and is not responsible for any errors or omissions. TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGrawHill”) 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’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 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, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. McGraw-Hill 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 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 has no responsibility for the content of any information accessed through the work. Under no circumstances shall McGraw-Hill 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. FREE SUBSCRIPTION GET YOUR TO ORACLE MAGAZINE Oracle Magazine is essential gear for today’s information technology professionals. Stay informed and increase your productivity with every issue of Oracle Magazine. Inside each free bimonthly issue you’ll get: t 6 QUPEBUFJOGPSNBUJPOPO0SBDMF%BUBCBTF 0SBDMF"QQMJDBUJPO4FSWFS 8FCEFWFMPQNFOU FOUFSQSJTFHSJEDPNQVUJOH EBUBCBTFUFDIOPMPHZ BOECVTJOFTTUSFOET t 5IJSEQBSUZOFXTBOEBOOPVODFNFOUT t 5FDIOJDBMBSUJDMFTPO0SBDMFBOEQBSUOFSQSPEVDUT UFDIOPMPHJFT BOEPQFSBUJOHFOWJSPONFOUT t %FWFMPQNFOUBOEBENJOJTUSBUJPOUJQT t 3FBMXPSMEDVTUPNFSTUPSJFT If there are other Oracle users at your location who would like to receive their own subscription to Three easy ways to subscribe: Oracle Magazine, please photo- copy this form and pass it along. 1 Web 7JTJUPVS8FCTJUFBU oracle.com/oraclemagazine :PVMMGJOEBTVCTDSJQUJPOGPSNUIFSF QMVTNVDINPSF 2 Fax $PNQMFUFUIFRVFTUJPOOBJSFPOUIFCBDLPGUIJTDBSE BOEGBYUIFRVFTUJPOOBJSFTJEFPOMZUP+1.847.763.9638 3 Mail $PNQMFUFUIFRVFTUJPOOBJSFPOUIFCBDLPGUIJTDBSE BOENBJMJUUP P.O. Box 1263, Skokie, IL 60076-8263 Copyright © 2008, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Want your own FREE subscription? To receive a free subscription to Oracle Magazine, you must fill out the entire card, sign it, and date it (incomplete cards cannot be processed or acknowledged). You can also fax your application to +1.847.763.9638. Or subscribe at our Web site at oracle.com/oraclemagazine Yes, please send me a FREE subscription Oracle Magazine. No. From time to time, Oracle Publishing allows our partners exclusive access to our e-mail addresses for special promo- tions and announcements. To be included in this program, x please check this circle. If you do not wish to be included, you signature (required) date will only receive notices about your subscription via e-mail. name title Oracle Publishing allows sharing of our postal mailing list with selected third parties. If you prefer your mailing address not to company e-mail address be included in this program, please check this circle. If at any time you would like to be removed from either mailing list, please contact Customer Service at +1.847.763.9635 or send an e-mail to [email protected]. street/p.o. box If you opt in to the sharing of information, Oracle may also provide you with e-mail related to Oracle products, services, and events. If you want to completely unsubscribe from any e-mail communication from Oracle, please send an e-mail to: city/state/zip or postal code telephone [email protected] with the following in the subject line: REMOVE [your e-mail address]. For complete information on Oracle Publishing’s privacy practices, please visit oracle.com/html/privacy/html country fax Would you like to receive your free subscription in digital format instead of print if it becomes available? Yes No YOU MUST ANSWER ALL 10 QUESTIONS BELOW. 1 WHAT IS THE PRIMARY BUSINESS ACTIVITY 3 WHAT IS YOUR CURRENT PRIMARY OPERATING o 18 Minicomputer o 05 Hibernate o 17 SQL OF YOUR FIRM AT THIS LOCATION? (check PLATFORM (check all that apply) o 19 Intel x86(32) o 06 J++/J# o 18 Visual Basic one only) o 20 Intel x86(64) o 07 Java o 98 Other o 01 Digital Equipment Corp UNIX/VAX/VMS o 21 Network Computer o 08 JSP o 01 Aerospace and Defense Manufacturing o 02 HP UNIX o 22 Symmetric Multiprocessing o 09.NET o 02 Application Service Provider o 03 IBM AIX o 23 Workstation Services o 10 Perl o 03 Automotive Manufacturing o 04 IBM UNIX o 04 Chemicals o 05 Linux (Red Hat) SERVICES o 11 PHP o 05 Media and Entertainment o 06 Linux (SUSE) o 24 Consulting o 12 PL/SQL o 06 Construction/Engineering o 07 Linux (Oracle Enterprise) o 25 Education/Training o 07 Consumer Sector/Consumer Packaged o 08 Linux (other) o 26 Maintenance 10 WHAT ORACLE PRODUCTS ARE IN USE AT YOUR Goods o 09 Macintosh o 27 Online Database SITE? (check all that apply) o 08 Education o 10 MVS o 28 Support o 09 Financial Services/Insurance o 11 Netware o 29 Technology-Based Training ORACLE DATABASE o 10 Health Care o 12 Network Computing o 30 Other o 01 Oracle Database 11g o 11 High Technology Manufacturing, OEM o 13 SCO UNIX 99 o None of the Above o 02 Oracle Database 10 g o 12 Industrial Manufacturing o 14 Sun Solaris/SunOS o 03 Oracle9 i Database o 13 Independent Software Vendor o 15 Windows o 04 Oracle Embedded Database o 14 Life Sciences (biotech, pharmaceuticals) o 16 Other UNIX 6 WHAT IS YOUR COMPANY’S SIZE? (Oracle Lite, Times Ten, Berkeley DB) o 15 Natural Resources o 98 Other (check one only) o 05 Other Oracle Database Release o 16 Oil and Gas 99 o None of the Above o 01 More than 25,000 Employees ORACLE FUSION MIDDLEWARE o 17 Professional Services o 02 10,001 to 25,000 Employees o 06 Oracle Application Server o 18 Public Sector (government) o 03 5,001 to 10,000 Employees o 07 Oracle Portal o 19 Research 4 DO YOU EVALUATE, SPECIFY, RECOMMEND, OR AUTHORIZE THE PURCHASE OF ANY OF o 04 1,001 to 5,000 Employees o 08 Oracle Enterprise Manager o 20 Retail/Wholesale/Distribution o 05 101 to 1,000 Employees o 09 Oracle BPEL Process Manager o 21 Systems Integrator, VAR/VAD THE FOLLOWING? (check all that apply) o 06 Fewer than 100 Employees o 10 Oracle Identity Management o 22 Telecommunications o 01 Hardware o 11 Oracle SOA Suite o 23 Travel and Transportation o 02 Business Applications (ERP, CRM, etc.) o 12 Oracle Data Hubs o 24 Utilities (electric, gas, sanitation, water) o 03 Application Development Tools 7 DURING THE NEXT 12 MONTHS, HOW MUCH o 98 Other Business and Services _________ o 04 Database Products DO YOU ANTICIPATE YOUR ORGANIZATION ORACLE DEVELOPMENT TOOLS o 05 Internet or Intranet Products WILL SPEND ON COMPUTER HARDWARE, o 13 Oracle JDeveloper o 06 Other Software SOFTWARE, PERIPHERALS, AND SERVICES FOR o 14 Oracle Forms 2 WHICH OF THE FOLLOWING BEST DESCRIBES o 07 Middleware Products YOUR LOCATION? (check one only) o 15 Oracle Reports YOUR PRIMARY JOB FUNCTION? 99 o None of the Above o 16 Oracle Designer (check one only) o 01 Less than $10,000 o 17 Oracle Discoverer o 02 $10,000 to $49,999 o 18 Oracle BI Beans CORPORATE MANAGEMENT/STAFF o 03 $50,000 to $99,999 5 IN YOUR JOB, DO YOU USE OR PLAN TO PUR- o 19 Oracle Warehouse Builder o 01 Executive Management (President, Chair, o 04 $100,000 to $499,999 CHASE ANY OF THE FOLLOWING PRODUCTS? o 20 Oracle WebCenter CEO, CFO, Owner, Partner, Principal) o 05 $500,000 to $999,999 (check all that apply) o 21 Oracle Application Express o 02 Finance/Administrative Management o 06 $1,000,000 and Over (VP/Director/ Manager/Controller, SOFTWARE ORACLE APPLICATIONS Purchasing, Administration) o 01 CAD/CAE/CAM o 22 Oracle E-Business Suite o 03 Sales/Marketing Management o 02 Collaboration Software 8 WHAT IS YOUR COMPANY’S YEARLY SALES o 23 PeopleSoft Enterprise (VP/Director/Manager) o 03 Communications REVENUE? (check one only) o 24 JD Edwards EnterpriseOne o 04 Computer Systems/Operations o 04 Database Management o 25 JD Edwards World Management o 05 File Management o 01 $500, 000, 000 and above o 26 Oracle Fusion (CIO/VP/Director/Manager MIS/IS/IT, Ops) o 06 Finance o 02 $100, 000, 000 to $500, 000, 000 o 27 Hyperion IS/IT STAFF o 07 Java o 03 $50, 000, 000 to $100, 000, 000 o 28 Siebel CRM o 05 Application Development/Programming o 08 Multimedia Authoring o 04 $5, 000, 000 to $50, 000, 000 Management ORACLE SERVICES o 09 Networking o 05 $1, 000, 000 to $5, 000, 000 o 28 Oracle E-Business Suite On Demand o 06 Application Development/Programming o 10 Programming o 29 Oracle Technology On Demand Staff o 11 Project Management o 30 Siebel CRM On Demand o 07 Consulting o 12 Scientific and Engineering 9 WHAT LANGUAGES AND FRAMEWORKS DO o 31 Oracle Consulting o 08 DBA/Systems Administrator o 13 Systems Management YOU USE? (check all that apply) o 32 Oracle Education o 09 Education/Training o 14 Workflow o 33 Oracle Support o 10 Technical Support Director/Manager o 01 Ajax o 13 Python HARDWARE o 98 Other o 11 Other Technical Management/Staff o 02 C o 14 Ruby/Rails o 98 Other o 15 Macintosh 99 o None of the Above 08014004 o 03 C++ o 15 Spring o 16 Mainframe o 04 C# o 16 Struts o 17 Massively Parallel Processing Contents at a Glance Part I The Java Language 1 The History and Evolution of Java 3 2 An Overview of Java 17 3 Data Types, Variables, and Arrays 35 4 Operators 61 5 Control Statements 81 6 Introducing Classes 109 7 A Closer Look at Methods and Classes 129 8 Inheritance 161 9 Packages and Interfaces 187 10 Exception Handling 207 11 Multithreaded Programming 227 12 Enumerations, Autoboxing, and Annotations (Metadata) 259 13 I/O, Applets, and Other Topics 289 14 Generics 325 Part II The Java Library 15 String Handling 371 16 Exploring java.lang 397 17 java.util Part 1: The Collections Framework 453 18 java.util Part 2: More Utility Classes 525 19 Input/Output: Exploring java.io 581 20 Exploring NIO 629 21 Networking 667 22 The Applet Class 687 23 Event Handling 707 24 Introducing the AWT: Working with Windows, Graphics, and Text 735 25 Using AWT Controls, Layout Managers, and Menus 773 26 Images 829 27 The Concurrency Utilities 861 28 Regular Expressions and Other Packages 909 v vi Java: The Complete Reference, Eighth Edition Part III Software Development Using Java 29 Java Beans 933 30 Introducing Swing 945 31 Exploring Swing 965 32 Servlets 993 Part IV Applying Java 33 Financial Applets and Servlets 1019 34 Creating a Download Manager in Java 1053 Appendix Using Java’s Documentation Comments 1079 Index 1087 Contents Preface...................................................xxix 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 Changed the Internet................................. 8 Java Applets.............................................. 8 Security................................................. 9 Portability............................................... 9 Java’s Magic: The Bytecode..................................... 9 Servlets: Java on the Server Side................................ 10 The Java Buzzwords.......................................... 10 Simple................................................. 11 Object-Oriented......................................... 11 Robust................................................. 11 Multithreaded........................................... 12 Architecture-Neutral...................................... 12 Interpreted and High Performance......................... 12 Distributed............................................. 12 Dynamic................................................ 13 The Evolution of Java......................................... 13 Java SE 7............................................... 14 A Culture of Innovation....................................... 16 Chapter 2 An Overview of Java.........................................17 Object-Oriented Programming................................. 17 Two Paradigms.......................................... 17 Abstraction............................................. 18 The Three OOP Principles................................ 18 A First Simple Program....................................... 23 Entering the Program.................................... 23 vii viii Java: The Complete Reference, Eighth Edition Compiling the Program.................................. 23 A Closer Look at the First Sample Program................... 24 A Second Short Program...................................... 26 Two Control Statements....................................... 28 The if Statement........................................ 28 The for Loop........................................... 29 Using Blocks of Code......................................... 30 Lexical Issues............................................... 32 Whitespace............................................. 32 Identifiers.............................................. 32 Literals................................................ 32 Comments............................................. 32 Separators.............................................. 33 The Java Keywords....................................... 33 The Java Class Libraries....................................... 34 Chapter 3 Data Types, Variables, and Arrays..............................35 Java Is a Strongly Typed Language.............................. 35 The Primitive Types.......................................... 35 Integers.................................................... 36 byte................................................... 36 short.................................................. 37 int.................................................... 37 long................................................... 37 Floating-Point Types.......................................... 38 float................................................... 38 double................................................. 38 Characters.................................................. 39 Booleans................................................... 40 A Closer Look at Literals...................................... 41 Integer Literals.......................................... 41 Floating-Point Literals.................................... 42 Boolean Literals......................................... 43 Character Literals....................................... 43 String Literals........................................... 43 Variables................................................... 44 Declaring a Variable..................................... 44 Dynamic Initialization.................................... 45 The Scope and Lifetime of Variables........................ 45 Type Conversion and Casting.................................. 48 Java’s Automatic Conversions.............................. 48 Casting Incompatible Types............................... 48 Automatic Type Promotion in Expressions....................... 49 The Type Promotion Rules................................ 50 Arrays..................................................... 51 One-Dimensional Arrays.................................. 51 Contents ix Multidimensional Arrays.................................. 54 Alternative Array Declaration Syntax........................ 58 A Few Words About Strings.................................... 58 A Note to C/C++ Programmers About Pointers................... 59 Chapter 4 Operators.................................................61 Arithmetic Operators......................................... 61 The Basic Arithmetic Operators............................ 62 The Modulus Operator................................... 63 Arithmetic Compound Assignment Operators................ 63 Increment and Decrement................................ 64 The Bitwise Operators........................................ 66 The Bitwise Logical Operators............................. 67 The Left Shift........................................... 69 The Right Shift.......................................... 70 The Unsigned Right Shift................................. 72 Bitwise Operator Compound Assignments................... 73 Relational Operators......................................... 74 Boolean Logical Operators.................................... 75 Short-Circuit Logical Operators............................ 76 The Assignment Operator..................................... 77 The ? Operator.............................................. 77 Operator Precedence......................................... 78 Using Parentheses........................................... 79 Chapter 5 Control Statements..........................................81 Java’s Selection Statements.................................... 81 if..................................................... 81 switch................................................. 84 Iteration Statements.......................................... 89 while.................................................. 89 do-while............................................... 90 for.................................................... 93 The For-Each Version of the for Loop....................... 97 Nested Loops.......................................... 102 Jump Statements........................................... 102 Using break........................................... 102 Using continue......................................... 106 Chapter 6 Introducing Classes........................................109 Class Fundamentals......................................... 109 The General Form of a Class.............................. 109 A Simple Class......................................... 110 Declaring Objects........................................... 113 A Closer Look at new.................................... 113 Assigning Object Reference Variables.......................... 115 Introducing Methods........................................ 115 Adding a Method to the Box Class......................... 116 x Java: The Complete Reference, Eighth Edition Returning a Value...................................... 118 Adding a Method That Takes Parameters................... 119 Constructors............................................... 121 Parameterized Constructors.............................. 123 The this Keyword........................................... 124 Instance Variable Hiding................................. 125 Garbage Collection......................................... 125 The finalize( ) Method...................................... 125 A Stack Class............................................... 126 Chapter 7 A Closer Look at Methods and Classes.........................129 Overloading Methods....................................... 129 Overloading Constructors................................ 132 Using Objects as Parameters.................................. 134 A Closer Look at Argument Passing............................ 136 Returning Objects.......................................... 138 Recursion................................................. 139 Introducing Access Control................................... 141 Understanding static........................................ 145 Introducing final........................................... 146 Arrays Revisited............................................ 147 Introducing Nested and Inner Classes.......................... 149 Exploring the String Class.................................... 152 Using Command-Line Arguments............................. 154 Varargs: Variable-Length Arguments........................... 155 Overloading Vararg Methods............................. 158 Varargs and Ambiguity.................................. 159 Chapter 8 Inheritance...............................................161 Inheritance Basics.......................................... 161 Member Access and Inheritance.......................... 163 A More Practical Example................................ 164 A Superclass Variable Can Reference a Subclass Object........ 166 Using super................................................ 167 Using super to Call Superclass Constructors................. 167 A Second Use for super.................................. 170 Creating a Multilevel Hierarchy............................... 171 When Constructors Are Called................................ 174 Method Overriding......................................... 175 Dynamic Method Dispatch................................... 178 Why Overridden Methods?............................... 179 Applying Method Overriding............................. 180 Using Abstract Classes....................................... 181 Using final with Inheritance.................................. 184 Using final to Prevent Overriding......................... 184 Using final to Prevent Inheritance......................... 185 The Object Class............................................ 185 Contents xi Chapter 9 Packages and Interfaces.....................................187 Packages.................................................. 187 Defining a Package..................................... 188 Finding Packages and CLASSPATH........................ 188 A Short Package Example................................ 189 Access Protection........................................... 190 An Access Example..................................... 191 Importing Packages......................................... 194 Interfaces................................................. 196 Defining an Interface................................... 196 Implementing Interfaces................................. 197 Nested Interfaces....................................... 200 Applying Interfaces..................................... 201 Variables in Interfaces................................... 204 Interfaces Can Be Extended.............................. 205 Chapter 10 Exception Handling........................................207 Exception-Handling Fundamentals............................ 207 Exception Types............................................ 208 Uncaught Exceptions........................................ 209 Using try and catch......................................... 210 Displaying a Description of an Exception................... 212 Multiple catch Clauses....................................... 212 Nested try Statements....................................... 214 throw..................................................... 216 throws.................................................... 217 finally..................................................... 218 Java’s Built-in Exceptions..................................... 220 Creating Your Own Exception Subclasses....................... 221 Chained Exceptions......................................... 224 Three New JDK 7 Exception Features.......................... 225 Using Exceptions........................................... 226 Chapter 11 Multithreaded Programming.................................227 The Java Thread Model...................................... 228 Thread Priorities....................................... 229 Synchronization........................................ 229 Messaging............................................. 230 The Thread Class and the Runnable Interface............... 230 The Main Thread........................................... 231 Creating a Thread.......................................... 232 Implementing Runnable................................. 233 Extending Thread...................................... 235 Choosing an Approach.................................. 236 Creating Multiple Threads................................... 236 Using isAlive( ) and join( )................................... 238 Thread Priorities........................................... 240 xii Java: The Complete Reference, Eighth Edition Synchronization............................................ 241 Using Synchronized Methods............................. 241 The synchronized Statement............................. 243 Interthread Communication.................................. 245 Deadlock.............................................. 249 Suspending, Resuming, and Stopping Threads................... 251 Suspending, Resuming, and Stopping Threads Using Java 1.1 and Earlier............................................ 251 The Modern Way of Suspending, Resuming, and Stopping Threads..................................... 253 Obtaining A Thread’s State................................... 256 Using Multithreading........................................ 257 Chapter 12 Enumerations, Autoboxing, and Annotations (Metadata)...........259 Enumerations.............................................. 259 Enumeration Fundamentals.............................. 259 The values( ) and valueOf( ) Methods...................... 262 Java Enumerations Are Class Types........................ 263 Enumerations Inherit Enum.............................. 265 Another Enumeration Example........................... 267 Type Wrappers............................................. 268 Character............................................. 269 Boolean.............................................. 269 The Numeric Type Wrappers............................. 269 Autoboxing................................................ 270 Autoboxing and Methods................................ 271 Autoboxing/Unboxing Occurs in Expressions............... 272 Autoboxing/Unboxing Boolean and Character Values........ 274 Autoboxing/Unboxing Helps Prevent Errors................ 274 A Word of Warning..................................... 275 Annotations (Metadata)..................................... 275 Annotation Basics...................................... 276 Specifying a Retention Policy............................. 276 Obtaining Annotations at Run Time by Use of Reflection...... 277 The AnnotatedElement Interface......................... 282 Using Default Values.................................... 282 Marker Annotations..................................... 284 Single-Member Annotations.............................. 285 The Built-In Annotations................................ 286 Some Restrictions...................................... 288 Chapter 13 I/O, Applets, and Other Topics...............................289 I/O Basics................................................. 289 Streams............................................... 290 Byte Streams and Character Streams....................... 290 The Predefined Streams................................. 292 Contents xiii Reading Console Input...................................... 293 Reading Characters..................................... 293 Reading Strings........................................ 294 Writing Console Output..................................... 296 The PrintWriter Class........................................ 296 Reading and Writing Files.................................... 297 Automatically Closing a File.................................. 303 Applet Fundamentals........................................ 307 The transient and volatile Modifiers............................ 309 Using instanceof............................................ 310 strictfp.................................................... 312 Native Methods............................................. 312 Problems with Native Methods................................ 316 Using assert................................................ 316 Assertion Enabling and Disabling Options.................. 319 Static Import............................................... 319 Invoking Overloaded Constructors Through this( )............... 321 Chapter 14 Generics.................................................325 What Are Generics?......................................... 326 A Simple Generics Example.................................. 326 Generics Work Only with Objects.......................... 330 Generic Types Differ Based on Their Type Arguments......... 330 How Generics Improve Type Safety........................ 330 A Generic Class with Two Type Parameters...................... 332 The General Form of a Generic Class........................... 334 Bounded Types............................................. 334 Using Wildcard Arguments................................... 337 Bounded Wildcards..................................... 339 Creating a Generic Method................................... 344 Generic Constructors................................... 346 Generic Interfaces.......................................... 347 Raw Types and Legacy Code.................................. 349 Generic Class Hierarchies.................................... 352 Using a Generic Superclass............................... 352 A Generic Subclass...................................... 354 Run-Time Type Comparisons Within a Generic Hierarchy..... 355 Casting............................................... 357 Overriding Methods in a Generic Class..................... 358 Type Inference with Generics................................. 359 Erasure................................................... 361 Bridge Methods........................................ 362 Ambiguity Errors........................................... 364 Some Generic Restrictions................................... 365 Type Parameters Can’t Be Instantiated..................... 365 xiv Java: The Complete Reference, Eighth Edition Restrictions on Static Members............................ 366 Generic Array Restrictions............................... 366 Generic Exception Restriction............................ 367 Part II The Java Library Chapter 15 String Handling...........................................371 The String Constructors..................................... 372 String Length.............................................. 374 Special String Operations.................................... 374 String Literals.......................................... 374 String Concatenation................................... 374 String Concatenation with Other Data Types................ 375 String Conversion and toString( )......................... 376 Character Extraction........................................ 377 charAt( ).............................................. 377 getChars( )............................................ 377 getBytes( )............................................ 378 toCharArray( )......................................... 378 String Comparison.......................................... 378 equals( ) and equalsIgnoreCase( )......................... 378 regionMatches( )....................................... 379 startsWith( ) and endsWith( )............................. 380 equals( ) Versus ==...................................... 380 compareTo( ).......................................... 381 Searching Strings........................................... 382 Modifying a String.......................................... 384 substring( )............................................ 384 concat( ).............................................. 385 replace( )............................................. 385 trim( )................................................ 385 Data Conversion Using valueOf( )............................. 386 Changing the Case of Characters Within a String................. 387 Additional String Methods................................... 387 StringBuffer............................................... 389 StringBuffer Constructors................................ 389 length( ) and capacity( )................................. 389 ensureCapacity( )...................................... 390 setLength( )........................................... 390 charAt( ) and setCharAt( )............................... 390 getChars( )............................................ 391 append( )............................................. 391 insert( )............................................... 392 reverse( )............................................. 392 delete( ) and deleteCharAt( )............................. 393 Contents xv replace( )............................................. 393 substring( )............................................ 394 Additional StringBuffer Methods.......................... 394 StringBuilder.............................................. 395 Chapter 16 Exploring java.lang.........................................397 Primitive Type Wrappers..................................... 398 Number.............................................. 398 Double and Float....................................... 398 Understanding isInfinite( ) and isNaN( )................... 402 Byte, Short, Integer, and Long............................ 403 Character............................................. 411 Additions to Character for Unicode Code Point Support...... 414 Boolean.............................................. 414 Void...................................................... 416 Process................................................... 416 Runtime.................................................. 417 Memory Management................................... 418 Executing Other Programs............................... 420 ProcessBuilder............................................. 421 System.................................................... 423 Using currentTimeMillis( ) to Time Program Execution....... 425 Using arraycopy( )...................................... 425 Environment Properties................................. 426 Object.................................................... 427 Using clone( ) and the Cloneable Interface..................... 427 Class...................................................... 429 ClassLoader............................................... 433 Math..................................................... 433 Trigonometric Functions................................. 433 Exponential Functions.................................. 434 Rounding Functions.................................... 434 Miscellaneous Math Methods............................. 435 StrictMath................................................. 436 Compiler.................................................. 436 Thread, ThreadGroup, and Runnable.......................... 436 The Runnable Interface................................. 437 Thread............................................... 437 ThreadGroup.......................................... 439 ThreadLocal and InheritableThreadLocal...................... 444 Package................................................... 444 RuntimePermission......................................... 445 Throwable................................................. 445 SecurityManager............................................ 445 StackTraceElement.......................................... 446 xvi Java: The Complete Reference, Eighth Edition Enum..................................................... 447 ClassValue................................................. 448 The CharSequence Interface................................. 448 The Comparable Interface................................... 448 The Appendable Interface................................... 449 The Iterable Interface....................................... 449 The Readable Interface...................................... 449 The AutoCloseable Interface................................. 449 The Thread.UncaughtExceptionHandler Interface............... 450 The java.lang Subpackages................................... 450 java.lang.annotation.................................... 450 java.lang.instrument.................................... 450 java.lang.invoke........................................ 451 java.lang.management................................... 451 java.lang.ref............................................ 451 java.lang.reflect......................................... 451 Chapter 17 java.util Part 1: The Collections Framework.....................453 Collections Overview........................................ 454 JDK 5 Changed the Collections Framework...................... 455 Generics Fundamentally Changed the Collections Framework.. 455 Autoboxing Facilitates the Use of Primitive Types............ 456 The For-Each Style for Loop.............................. 456 The Collection Interfaces.................................... 456 The Collection Interface................................. 457 The List Interface...................................... 459 The Set Interface....................................... 459 The SortedSet Interface................................. 460 The NavigableSet Interface............................... 461 The Queue Interface.................................... 462 The Deque Interface.................................... 463 The Collection Classes....................................... 465 The ArrayList Class..................................... 466 The LinkedList Class.................................... 469 The HashSet Class...................................... 470 The LinkedHashSet Class................................ 472 The TreeSet Class....................................... 472 The PriorityQueue Class................................. 473 The ArrayDeque Class................................... 474 The EnumSet Class..................................... 475 Accessing a Collection via an Iterator........................... 476 Using an Iterator....................................... 477 The For-Each Alternative to Iterators....................... 479 Storing User-Defined Classes in Collections...................... 480 The RandomAccess Interface................................. 482 Contents xvii Working with Maps.......................................... 482 The Map Interfaces..................................... 482 The Map Classes........................................ 487 Comparators............................................... 492 Using a Comparator.................................... 492 The Collection Algorithms................................... 495 Arrays.................................................... 501 Why Generic Collections?.................................... 505 The Legacy Classes and Interfaces............................. 508 The Enumeration Interface.............................. 508 Vector................................................ 509 Stack................................................. 513 Dictionary............................................. 515 Hashtable............................................. 516 Properties............................................. 519 Using store( ) and load( )................................ 522 Parting Thoughts on Collections.............................. 524 Chapter 18 java.util Part 2: More Utility Classes...........................525 StringTokenizer............................................ 525 BitSet..................................................... 527 Date...................................................... 530 Calendar.................................................. 531 GregorianCalendar......................................... 534 TimeZone................................................. 536 SimpleTimeZone........................................... 537 Locale.................................................... 538 Random.................................................. 539 Observable................................................ 541 The Observer Interface.................................. 541 An Observer Example................................... 542 Timer and TimerTask....................................... 544 Currency.................................................. 547 Formatter................................................. 548 The Formatter Constructors.............................. 548 The Formatter Methods................................. 549 Formatting Basics....................................... 549 Formatting Strings and Characters......................... 551 Formatting Numbers.................................... 551 Formatting Time and Date............................... 552 The %n and %% Specifiers.............................. 554 Specifying a Minimum Field Width........................ 555 Specifying Precision..................................... 556 Using the Format Flags.................................. 557 Justifying Output....................................... 558 The Space, +, 0, and ( Flags.............................. 558 xviii Java: The Complete Reference, Eighth Edition The Comma Flag....................................... 559 The # Flag............................................. 560 The Uppercase Option.................................. 560 Using an Argument Index................................ 560 Closing a Formatter..................................... 562 The Java printf( ) Connection............................ 562 Scanner............................................... 563 The Scanner Constructors............................... 563 Scanning Basics........................................ 564 Some Scanner Examples................................. 567 Setting Delimiters...................................... 570 Other Scanner Features................................. 572 The ResourceBundle, ListResourceBundle, and PropertyResourceBundle Classes............................ 573 Miscellaneous Utility Classes and Interfaces..................... 577 The java.util Subpackages.................................... 578 java.util.concurrent, java.util.concurrent.atomic, and java.util.concurrent.locks........................... 578 java.util.jar............................................ 578 java.util.logging........................................ 578 java.util.prefs.......................................... 578 java.util.regex.......................................... 579 java.util.spi............................................ 579 java.util.zip............................................ 579 Chapter 19 Input/Output: Exploring java.io..............................581 The I/O Classes and Interfaces................................ 581 File....................................................... 582 Directories............................................ 585 Using FilenameFilter.................................... 586 The listFiles( ) Alternative................................ 587 Creating Directories.................................... 588 The AutoCloseable, Closeable, and Flushable Interfaces........... 588 I/O Exceptions............................................. 588 Two Ways to Close a Stream................................... 589 The Stream Classes.......................................... 590 The Byte Streams........................................... 590 InputStream........................................... 591 OutputStream......................................... 591 FileInputStream........................................ 592 FileOutputStream...................................... 594 ByteArrayInputStream................................... 596 ByteArrayOutputStream................................. 598 Filtered Byte Streams.................................... 599 Buffered Byte Streams................................... 599 SequenceInputStream................................... 603 PrintStream........................................... 605 Contents xix DataOutputStream and DataInputStream................... 607 RandomAccessFile...................................... 609 The Character Streams...................................... 610 Reader............................................... 610 Writer................................................ 610 FileReader............................................ 612 FileWriter............................................. 613 CharArrayReader....................................... 614 CharArrayWriter....................................... 615 BufferedReader........................................ 616 BufferedWriter......................................... 618 PushbackReader....................................... 618 PrintWriter............................................ 619 The Console Class.......................................... 620 Serialization............................................... 622 Serializable............................................ 622 Externalizable......................................... 623 ObjectOutput.......................................... 623 ObjectOutputStream.................................... 624 ObjectInput........................................... 625 ObjectInputStream..................................... 625 A Serialization Example................................. 626 Stream Benefits............................................ 628 Chapter 20 Exploring NIO............................................629 The NIO Classes............................................ 629 NIO Fundamentals.......................................... 630 Buffers............................................... 630 Channels.............................................. 631 Charsets and Selectors................................... 633 Enhancements Added to NIO by JDK 7......................... 634 The Path Interface...................................... 634 The Files Class......................................... 635 The Paths Class........................................ 638 The File Attribute Interfaces.............................. 638 The FileSystem, FileSystems, and FileStore Classes............ 640 Using the NIO System....................................... 640 Use NIO for Channel-Based I/O.......................... 640 Use NIO for Stream-Based I/O........................... 649 Use NIO for Path and File System Operations............... 652 Pre-JDK 7 Channel-Based Examples............................ 659 Read a File, Pre-JDK 7................................... 660 Write to a File, Pre-JDK 7................................. 663 Chapter 21 Networking...............................................667 Networking Basics.......................................... 667 The Networking Classes and Interfaces......................... 668 xx Java: The Complete Reference, Eighth Edition InetAddress................................................ 669 Factory Methods....................................... 669 Instance Methods....................................... 670 Inet4Address and Inet6Address............................... 671 TCP/IP Client Sockets....................................... 671 URL...................................................... 675 URLConnection............................................ 676 HttpURLConnection........................................ 679 The URI Class.............................................. 681 Cookies................................................... 681 TCP/IP Server Sockets....................................... 681 Datagrams................................................. 682 DatagramSocket........................................ 682 DatagramPacket........................................ 683 A Datagram Example.................................... 684 Chapter 22 The Applet Class..........................................687 Two Types of Applets........................................ 687 Applet Basics............................................... 687 The Applet Class....................................... 688 Applet Architecture......................................... 690 An Applet Skeleton......................................... 691 Applet Initialization and Termination...................... 692 Overriding update( ).................................... 693 Simple Applet Display Methods............................... 693 Requesting Repainting....................................... 695 A Simple Banner Applet................................. 697 Using the Status Window..................................... 699 The HTML APPLET Tag..................................... 699 Passing Parameters to Applets................................. 701 Improving the Banner Applet............................. 702 getDocumentBase( ) and getCodeBase( )....................... 704 AppletContext and showDocument( ).......................... 704 The AudioClip Interface..................................... 706 The AppletStub Interface.................................... 706 Outputting to the Console................................... 706 Chapter 23 Event Handling............................................707 Two Event Handling Mechanisms.............................. 707 The Delegation Event Model................................. 708 Events................................................ 708 Event Sources.......................................... 708 Event Listeners......................................... 709 Event Classes............................................... 709 The ActionEvent Class................................... 711 The AdjustmentEvent Class.............................. 711 The ComponentEvent Class.............................. 712 Contents xxi The ContainerEvent Class................................ 712 The FocusEvent Class................................... 713 The InputEvent Class................................... 713 The ItemEvent Class.................................... 714 The KeyEvent Class......................................... 715 The MouseEvent Class................................... 716 The MouseWheelEvent Class............................. 717 The TextEvent Class..................................... 718 The WindowEvent Class................................. 718 Sources of Events........................................... 719 Event Listener Interfaces..................................... 720 The ActionListener Interface............................. 721 The AdjustmentListener Interface......................... 721 The ComponentListener Interface........................ 721 The ContainerListener Interface.......................... 721 The FocusListener Interface.............................. 721 The ItemListener Interface............................... 721 The KeyListener Interface............................... 722 The MouseListener Interface............................. 722 The MouseMotionListener Interface....................... 722 The MouseWheelListener Interface........................ 722 The TextListener Interface............................... 722 The WindowFocusListener Interface....................... 723 The WindowListener Interface............................ 723 Using the Delegation Event Model............................. 723 Handling Mouse Events................................. 723 Handling Keyboard Events............................... 726 Adapter Classes............................................. 729 Inner Classes............................................... 731 Anonymous Inner Classes................................ 732 Chapter 24 Introducing the AWT: Working with Windows, Graphics, and Text...735 AWT Classes............................................... 736 Window Fundamentals...................................... 738 Component........................................... 738 Container............................................. 739 Panel................................................. 739 Window............................................... 739 Frame................................................ 739 Canvas................................................ 739 Working with Frame Windows................................. 739 Setting the Window’s Dimensions......................... 740 Hiding and Showing a Window........................... 740 Setting a Window’s Title................................. 740 Closing a Frame Window................................. 740 Creating a Frame Window in an Applet......................... 741 Handling Events in a Frame Window....................... 742 xxii Java: The Complete Reference, Eighth Edition Creating a Windowed Program................................ 747 Displaying Information Within a Window....................... 749 Working with Graphics...................................... 749 Drawing Lines......................................... 749 Drawing Rectangles..................................... 750 Drawing Ellipses and Circles.............................. 751 Drawing Arcs.......................................... 752 Drawing Polygons...................................... 753 Sizing Graphics........................................ 754 Working with Color......................................... 755 Color Methods......................................... 755 Setting the Current Graphics Color........................ 756 A Color Demonstration Applet............................ 756 Setting the Paint Mode...................................... 757 Working with Fonts......................................... 759 Determining the Available Fonts.......................... 760 Creating and Selecting a Font............................. 762 Obtaining Font Information.............................. 764 Managing Text Output Using FontMetrics....................... 764 Displaying Multiple Lines of Text.......................... 766 Centering Text......................................... 767 Multiline Text Alignment................................ 768 Chapter 25 Using AWT Controls, Layout Managers, and Menus...............773 Control Fundamentals....................................... 773 Adding and Removing Controls........................... 774 Responding to Controls................................. 774 The HeadlessException.................................. 774 Labels.................................................... 775 Using Buttons.............................................. 776 Handling Buttons...................................... 776 Applying Check Boxes....................................... 779 Handling Check Boxes.................................. 780 CheckboxGroup............................................ 782 Choice Controls............................................ 783 Handling Choice Lists................................... 784 Using Lists................................................. 786 Handling Lists......................................... 787 Managing Scroll Bars........................................ 788 Handling Scroll Bars.................................... 790 Using a TextField........................................... 792 Handling a TextField.................................... 793 Using a TextArea........................................... 794 Understanding Layout Managers.............................. 796 FlowLayout............................................ 797 BorderLayout.......................................... 798 Using Insets........................................... 800 Contents xxiii GridLayout............................................ 801 CardLayout............................................ 802 GridBagLayout......................................... 805 Menu Bars and Menus....................................... 810 Dialog Boxes............................................... 816 FileDialog................................................. 820 Handling Events by Extending AWT Components................ 822 Extending Button...................................... 823 Extending Checkbox.................................... 824 Extending a Check Box Group............................ 825 Extending Choice...................................... 826 Extending List......................................... 826 Extending Scrollbar..................................... 827 A Word About Overriding paint( )............................. 828 Chapter 26 Images..................................................829 File Formats............................................... 829 Image Fundamentals: Creating, Loading, and Displaying.......... 830 Creating an Image Object................................ 830 Loading an Image...................................... 830 Displaying an Image.................................... 831 ImageObserver............................................. 832 Double Buffering........................................... 833 MediaTracker.............................................. 836 ImageProducer............................................. 839 MemoryImageSource................................... 839 ImageConsumer............................................ 841 PixelGrabber.......................................... 841 ImageFilter................................................ 844 CropImageFilter....................................... 844 RGBImageFilter........................................ 845 Cell Animation............................................. 857 Additional Imaging Classes................................... 860 Chapter 27 The Concurrency Utilities...................................861 The Concurrent API Packages................................ 862 java.util.concurrent..................................... 862 java.util.concurrent.atomic............................... 863 java.util.concurrent.locks................................ 863 Using Synchronization Objects................................ 863 Semaphore............................................ 863 CountDownLatch....................................... 869 CyclicBarrier........................................... 871 Exchanger............................................ 873 Phaser.................................................... 875 Using an Executor.......................................... 882 A Simple Executor Example.............................. 883 Using Callable and Future............................... 885 xxiv Java: The Complete Reference, Eighth Edition The TimeUnit Enumeration.................................. 888 The Concurrent Collections.................................. 889 Locks..................................................... 889 Atomic Operations.......................................... 892 Parallel Programming via the Fork/Join Framework.............. 893 The Main Fork/Join Classes.............................. 894 The Divide-and-Conquer Strategy......................... 897 A Simple First Fork/Join Example......................... 898 Understanding the Impact of the Level of Parallelism......... 900 An Example that Uses RecursiveTask.................... 903 Executing a Task Asynchronously.......................... 905 Cancelling a Task....................................... 906 Determining a Task’s Completion Status.................... 906 Restarting a Task....................................... 906 Things to Explore...................................... 906 Some Fork/Join Tips.................................... 908 The Concurrency Utilities Versus Java’s Traditional Approach...... 908 Chapter 28 Regular Expressions and Other Packages.......................909 The Core Java API Packages.................................. 909 Regular Expression Processing................................ 911 Pattern............................................... 911 Matcher.............................................. 912 Regular Expression Syntax............................... 913 Demonstrating Pattern Matching.......................... 913 Two Pattern-Matching Options............................ 919 Exploring Regular Expressions............................ 919 Reflection................................................. 919 Remote Method Invocation (RMI)............................. 923 A Simple Client/Server Application Using RMI.............. 923 Text Formatting............................................ 927 DateFormat Class....................................... 927 SimpleDateFormat Class................................. 929 Part III Software Development Using Java Chapter 29 Java Beans...............................................933 What Is a Java Bean?......................................... 933 Advantages of Java Beans..................................... 934 Introspection.............................................. 934 Design Patterns for Properties............................ 934 Design Patterns for Events............................... 936 Methods and Design Patterns............................. 936 Using the BeanInfo Interface............................. 936 Bound and Constrained Properties............................ 937 Persistence................................................ 937 Customizers............................................... 937 Contents xxv The Java Beans API......................................... 938 Introspector........................................... 940 PropertyDescriptor..................................... 940 EventSetDescriptor..................................... 940 MethodDescriptor...................................... 940 A Bean Example............................................ 940 Chapter 30 Introducing Swing.........................................945 The Origins of Swing........................................ 945 Swing Is Built on the AWT.................................... 946 Two Key Swing Features...................................... 946 Swing Components Are Lightweight....................... 946 Swing Supports a Pluggable Look and Feel.................. 946 The MVC Connection....................................... 947 Components and Containers................................. 948 Components........................................... 948 Containers............................................ 949 The Top-Level Container Panes........................... 949 The Swing Packages......................................... 950 A Simple Swing Application.................................. 950 Event Handling............................................ 954 Create a Swing Applet....................................... 957 Painting in Swing........................................... 959 Painting Fundamentals.................................. 960 Compute the Paintable Area.............................. 961 A Paint Example....................................... 961 Chapter 31 Exploring Swing...........................................965 JLabel and ImageIcon....................................... 965 JTextField................................................. 967 The Swing Buttons.......................................... 969 JButton............................................... 969 JToggleButton......................................... 971 Check Boxes........................................... 973 Radio Buttons.......................................... 975 JTabbedPane............................................... 977 JList...................................................... 981 JComboBox................................................ 984 Trees..................................................... 986 JTable.................................................... 990 Continuing Your Exploration of Swing.......................... 992 Chapter 32 Servlets..................................................993 Background............................................... 993 The Life Cycle of a Servlet.................................... 994 Servlet Development Options................................. 994 Using Tomcat.............................................. 995 xxvi Java: The Complete Reference, Eighth Edition A Simple Servlet............................................ 996 Create and Compile the Servlet Source Code................ 997 Start Tomcat........................................... 998 Start a Web Browser and Request the Servlet................ 998 The Servlet API............................................. 998 The javax.servlet Package.................................... 998 The Servlet Interface.................................... 999 The ServletConfig Interface............................. 1000 The ServletContext Interface............................ 1000 The ServletRequest Interface............................ 1000 The ServletResponse Interface........................... 1000 The GenericServlet Class................................ 1002 The ServletInputStream Class............................ 1002 The ServletOutputStream Class.......................... 1002 The Servlet Exception Classes............................ 1002 Reading Servlet Parameters.................................. 1002 The javax.servlet.http Package............................... 1004 The HttpServletRequest Interface........................ 1004 The HttpServletResponse Interface....................... 1005 The HttpSession Interface.............................. 1006 The HttpSessionBindingListener Interface................. 1006 The Cookie Class...................................... 1007 The HttpServlet Class.................................. 1008 The HttpSessionEvent Class............................. 1009 The HttpSessionBindingEvent Class...................... 1010 Handling HTTP Requests and Responses...................... 1010 Handling HTTP GET Requests.......................... 1010 Handling HTTP POST Requests......................... 1012 Using Cookies.....................................