Java大学教程-第七版.pdf带书签
本书是为全英文版本。 《Java大学教程》,原名《Java How to Program 7th Edition》,作者:(美)Harvey M.Deitel、Paul J.Deitel。本资源是为 PDF 格式,大小 3.9 MB,带书签方便读者阅读。 内容简介: Java经过多年发展,现在已经真正成长为严格的、主流的开发语言。本书的作者是国际知名的教育专家H.M.Deitel和P.J.Deitel。全书通过Deitel特有的“活代码”方式,详细讲解了如何使用Java开发数据库应用程序、多媒体应用程序、网络应用程序。本书还介绍了软件工程知识、界面设计知识、调试技巧、性能提示等方面的内容。另外,本书还配有实验手册,它提供了一个优秀的学习环境,学生们可以用所学概念解决精心设计的各种问题。教师也能更好地评估学生对教材的理解程度。该实验手册也可以作为开放式实验、家庭作业以及自学用。本书的读者对象是各类编程人员,计算机相关专业的本科生和研究生。 目录: Copyright................................................................................................ ..... 1 Deitel® Series Page..................................................................................... 5 Preface........................................................................................................ 8 Before You Begin....................................................................................... 21 Chapter 1. Introduction to Computers, the Internet and the Web.............. 28 Section 1.1. Introduction.............................................................................................................................................................. 29 Section 1.2. What Is a Computer?................................................................................................................................................ 31 Section 1.3. Computer Organization............................................................................................................................................ 31 Section 1.4. Early Operating Systems.......................................................................................................................................... 32 Section 1.5. Personal, Distributed and Client/Server Computing............................................................................................... 33 Section 1.6. The Internet and the World Wide Web..................................................................................................................... 33 Section 1.7. Machine Languages, Assembly Languages and High-Level Languages................................................................... 34 Section 1.8. History of C and C++................................................................................................................................................ 35 Section 1.9. History of Java.......................................................................................................................................................... 36 Section 1.10. Java Class Libraries................................................................................................................................................ 36 Section 1.11. Fortran, COBOL, Pascal and Ada............................................................................................................................ 37 Section 1.12. BASIC, Visual Basic, Visual C++, C# and .NET...................................................................................................... 38 Section 1.13. Typical Java Development Environment................................................................................................................ 38 Section 1.14. Notes about Java and Java How to Program, 7/e................................................................................................... 42 Section 1.15. Test-Driving a Java Application............................................................................................................................. 43 Section 1.16. Software Engineering Case Study: Introduction to Object Technology and the UML........................................... 47 Section 1.17. Web 2.0.................................................................................................................................................................... 52 Section 1.18. Software Technologies............................................................................................................................................ 53 Section 1.19. Wrap-Up.................................................................................................................................................................. 54 Section 1.20. Web Resources....................................................................................................................................................... 55 Summary...................................................................................................................................................................................... 57 Terminology................................................................................................................................................................................. 60 Self-Review Exercises................................................................................................................................................................... 61 Answers to Self-Review Exercises............................................................................................................................................... 62 Exercises....................................................................................................................................................................................... 62 Chapter 2. Introduction to Java Applications............................................ 64 Section 2.1. Introduction.............................................................................................................................................................. 65 Section 2.2. A First Program in Java: Printing a Line of Text..................................................................................................... 65 Section 2.3. Modifying Our First Java Program.......................................................................................................................... 72 Section 2.4. Displaying Text with printf...................................................................................................................................... 75 Section 2.5. Another Java Application: Adding Integers............................................................................................................. 76 Section 2.6. Memory Concepts..................................................................................................................................................... 81 Section 2.7. Arithmetic................................................................................................................................................................ 82 Section 2.8. Decision Making: Equality and Relational Operators............................................................................................. 85 Section 2.9. (Optional) Software Engineering Case Study: Examining the Requirements Document...................................... 90 Section 2.10. Wrap-Up............................................................................................................................................................... 100 Summary.................................................................................................................................................................................... 100 Terminology............................................................................................................................................................................... 103 Self-Review Exercises................................................................................................................................................................. 104 Answers to Self-Review Exercises.............................................................................................................................................. 105 Exercises..................................................................................................................................................................................... 107 Chapter 3. Introduction to Classes and Objects......................................... 111 Section 3.1. Introduction............................................................................................................................................................ 112 Section 3.2. Classes, Objects, Methods and Instance Variables................................................................................................. 112 Section 3.3. Declaring a Class with a Method and Instantiating an Object of a Class............................................................... 114 Section 3.4. Declaring a Method with a Parameter.................................................................................................................... 118 Section 3.5. Instance Variables, set Methods and get Methods.................................................................................................. 121 Section 3.6. Primitive Types vs. Reference Types....................................................................................................................... 126 Section 3.7. Initializing Objects with Constructors.................................................................................................................... 127 Section 3.8. Floating-Point Numbers and Type double............................................................................................................. 130 Section 3.9. (Optional) GUI and Graphics Case Study: Using Dialog Boxes............................................................................. 135 Section 3.10. (Optional) Software Engineering Case Study: Identifying the Classes in a Requirements Document............... 138 Section 3.11. Wrap-Up................................................................................................................................................................ 146 Summary.................................................................................................................................................................................... 146 Terminology................................................................................................................................................................................ 149 Self-Review Exercises................................................................................................................................................................. 150 Answers to Self-Review Exercises.............................................................................................................................................. 151 Exercises..................................................................................................................................................................................... 152 Chapter 4. Control Statements: Part 1...................................................... 154 Section 4.1. Introduction............................................................................................................................................................ 155 Section 4.2. Algorithms.............................................................................................................................................................. 155 Section 4.3. Pseudocode............................................................................................................................................................. 156 Section 4.4. Control Structures.................................................................................................................................................. 156 Section 4.5. if Single-Selection Statement................................................................................................................................. 159 Section 4.6. if...else Double-Selection Statement...................................................................................................................... 160 Section 4.7. while Repetition Statement.................................................................................................................................... 165 Section 4.8. Formulating Algorithms: Counter-Controlled Repetition..................................................................................... 166 Section 4.9. Formulating Algorithms: Sentinel-Controlled Repetition...................................................................................... 171 Section 4.10. Formulating Algorithms: Nested Control Statements.......................................................................................... 179 Section 4.11. Compound Assignment Operators....................................................................................................................... 184 Section 4.12. Increment and Decrement Operators................................................................................................................... 185 Section 4.13. Primitive Types..................................................................................................................................................... 188 Section 4.14. (Optional) GUI and Graphics Case Study: Creating Simple Drawings................................................................ 188 Section 4.15. (Optional) Software Engineering Case Study: Identifying Class Attributes......................................................... 193 Section 4.16. Wrap-Up................................................................................................................................................................ 197 Summary.................................................................................................................................................................................... 198 Terminology............................................................................................................................................................................... 203 Self-Review Exercises................................................................................................................................................................ 204 Answers to Self-Review Exercises............................................................................................................................................. 206 Exercises..................................................................................................................................................................................... 207 Chapter 5. Control Statements: Part 2...................................................... 213 Section 5.1. Introduction............................................................................................................................................................ 214 Section 5.2. Essentials of Counter-Controlled Repetition.......................................................................................................... 214 Section 5.3. for Repetition Statement........................................................................................................................................ 216 Section 5.4. Examples Using the for Statement........................................................................................................................ 220 Section 5.5. do...while Repetition Statement............................................................................................................................ 225 Section 5.6. switch Multiple-Selection Statement...................................................................................................................... 226 Section 5.7. break and continue Statements............................................................................................................................. 234 Section 5.8. Logical Operators................................................................................................................................................... 236 Section 5.9. Structured Programming Summary....................................................................................................................... 242 Section 5.10. (Optional) GUI and Graphics Case Study: Drawing Rectangles and Ovals......................................................... 247 Section 5.11. (Optional) Software Engineering Case Study: Identifying Objects’ States and Activities................................... 250 Section 5.12. Wrap-Up............................................................................................................................................................... 254 Summary.................................................................................................................................................................................... 255 Terminology............................................................................................................................................................................... 259 Self-Review Exercises................................................................................................................................................................ 260 Answers to Self-Review Exercises.............................................................................................................................................. 261 Exercises..................................................................................................................................................................................... 262 Chapter 6. Methods: A Deeper Look........................................................ 266 Section 6.1. Introduction............................................................................................................................................................ 267 Section 6.2. Program Modules in Java...................................................................................................................................... 268 Section 6.3. static Methods, static Fields and Class Math......................................................................................................... 269 Section 6.4. Declaring Methods with Multiple Parameters....................................................................................................... 272 Section 6.5. Notes on Declaring and Using Methods................................................................................................................. 276 Section 6.6. Method-Call Stack and Activation Records............................................................................................................ 277 Section 6.7. Argument Promotion and Casting......................................................................................................................... 278 Section 6.8. Java API Packages.................................................................................................................................................. 279 Section 6.9. Case Study: Random-Number Generation............................................................................................................. 281 Section 6.10. Case Study: A Game of Chance (Introducing Enumerations).............................................................................. 287 Section 6.11. Scope of Declarations............................................................................................................................................ 291 Section 6.12. Method Overloading............................................................................................................................................ 294 Section 6.13. (Optional) GUI and Graphics Case Study: Colors and Filled Shapes.................................................................. 297 Section 6.14. (Optional) Software Engineering Case Study: Identifying Class Operations...................................................... 300 Section 6.15. Wrap-Up............................................................................................................................................................... 307 Summary.................................................................................................................................................................................... 308 Terminology................................................................................................................................................................................ 311 Self-Review Exercises................................................................................................................................................................. 312 Answers to Self-Review Exercises.............................................................................................................................................. 314 Exercises..................................................................................................................................................................................... 316 Chapter 7. Arrays.................................................................................... 322 Section 7.1. Introduction............................................................................................................................................................ 323 Section 7.2. Arrays..................................................................................................................................................................... 323 Section 7.3. Declaring and Creating Arrays............................................................................................................................... 325 Section 7.4. Examples Using Arrays.......................................................................................................................................... 326 Section 7.5. Case Study: Card Shuffling and Dealing Simulation.............................................................................................. 335 Section 7.6. Enhanced for Statement........................................................................................................................................ 339 Section 7.7. Passing Arrays to Methods.................................................................................................................................... 340 Section 7.8. Case Study: Class GradeBook Using an Array to Store Grades............................................................................. 344 Section 7.9. Multidimensional Arrays....................................................................................................................................... 349 Section 7.10. Case Study: Class GradeBook Using a Two-Dimensional Array.......................................................................... 353 Section 7.11. Variable-Length Argument Lists.......................................................................................................................... 359 Section 7.12. Using Command-Line Arguments....................................................................................................................... 360 Section 7.13. (Optional) GUI and Graphics Case Study: Drawing Arcs..................................................................................... 362 Section 7.14. (Optional) Software Engineering Case Study: Collaboration Among Objects..................................................... 365 Section 7.15. Wrap-Up................................................................................................................................................................ 373 Summary.................................................................................................................................................................................... 374 Terminology............................................................................................................................................................................... 376 Self-Review Exercises................................................................................................................................................................. 377 Answers to Self-Review Exercises............................................................................................................................................. 378 Exercises..................................................................................................................................................................................... 378 Special Section: Building Your Own Computer........................................................................................................................ 388 Chapter 8. Classes and Objects: A Deeper Look....................................... 395 Section 8.1. Introduction........................................................................................................................................................... 396 Section 8.2. Time Class Case Study........................................................................................................................................... 397 Section 8.3. Controlling Access to Members............................................................................................................................. 401 Section 8.4. Referring to the Current Object’s Members with the this Reference.................................................................... 402 Section 8.5. Time Class Case Study: Overloaded Constructors................................................................................................. 404 Section 8.6. Default and No-Argument Constructors................................................................................................................ 409 Section 8.7. Notes on Set and Get Methods............................................................................................................................... 410 Section 8.8. Composition............................................................................................................................................................ 411 Section 8.9. Enumerations......................................................................................................................................................... 414 Section 8.10. Garbage Collection and Method finalize............................................................................................................... 417 Section 8.11. static Class Members............................................................................................................................................ 418 Section 8.12. static Import......................................................................................................................................................... 423 Section 8.13. final Instance Variables........................................................................................................................................ 424 Section 8.14. Software Reusability............................................................................................................................................ 426 Section 8.15. Data Abstraction and Encapsulation................................................................................................................... 427 Section 8.16. Time Class Case Study: Creating Packages.......................................................................................................... 429 Section 8.17. Package Access..................................................................................................................................................... 434 Section 8.18. (Optional) GUI and Graphics Case Study: Using Objects with Graphics............................................................ 436 Section 8.19. (Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System................. 439 Section 8.20. Wrap-Up.............................................................................................................................................................. 445 Summary.................................................................................................................................................................................... 445 Terminology............................................................................................................................................................................... 448 Self-Review Exercise.................................................................................................................................................................. 449 Answers to Self-Review Exercise............................................................................................................................................... 450 Exercises..................................................................................................................................................................................... 450 Chapter 9. Object-Oriented Programming: Inheritance.......................... 454 Section 9.1. Introduction............................................................................................................................................................ 455 Section 9.2. Superclasses and Subclasses.................................................................................................................................. 456 Section 9.3. protected Members................................................................................................................................................ 458 Section 9.4. Relationship between Superclasses and Subclasses.............................................................................................. 459 Section 9.5. Constructors in Subclasses.................................................................................................................................... 483 Section 9.6. Software Engineering with Inheritance................................................................................................................. 489 Section 9.7. Object Class............................................................................................................................................................ 490 Section 9.8. (Optional) GUI and Graphics Case Study: Displaying Text and Images Using Labels......................................... 492 Section 9.9. Wrap-Up................................................................................................................................................................ 494 Summary.................................................................................................................................................................................... 495 Terminology............................................................................................................................................................................... 496 Self-Review Exercises................................................................................................................................................................ 496 Answers to Self-Review Exercises.............................................................................................................................................. 497 Exercises..................................................................................................................................................................................... 497 Chapter 10. Object-Oriented Programming: Polymorphism.................... 498 Section 10.1. Introduction.......................................................................................................................................................... 499 Section 10.2. Polymorphism Examples..................................................................................................................................... 501 Section 10.3. Demonstrating Polymorphic Behavior................................................................................................................. 502 Section 10.4. Abstract Classes and Methods............................................................................................................................. 505 Section 10.5. Case Study: Payroll System Using Polymorphism............................................................................................... 507 Section 10.6. final Methods and Classes.................................................................................................................................... 522 Section 10.7. Case Study: Creating and Using Interfaces........................................................................................................... 523 Section 10.8. (Optional) GUI and Graphics Case Study: Drawing with Polymorphism........................................................... 535 Section 10.9. (Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System....................... 537 Section 10.10. Wrap-Up............................................................................................................................................................. 545 Summary.................................................................................................................................................................................... 545 Terminology............................................................................................................................................................................... 547 Self-Review Exercises................................................................................................................................................................ 548 Answers to Self-Review Exercises............................................................................................................................................. 548 Exercises..................................................................................................................................................................................... 548 Chapter 11. GUI Components: Part 1........................................................ 550 Section 11.1. Introduction........................................................................................................................................................... 551 Section 11.2. Simple GUI-Based Input/Output with JOptionPane............................................................................................ 552 Section 11.3. Overview of Swing Components........................................................................................................................... 555 Section 11.4. Displaying Text and Images in a Window............................................................................................................. 558 Section 11.5. Text Fields and an Introduction to Event Handling with Nested Classes............................................................ 563 Section 11.6. Common GUI Event Types and Listener Interfaces............................................................................................. 569 Section 11.7. How Event Handling Works................................................................................................................................. 572 Section 11.8. JButton.................................................................................................................................................................. 573 Section 11.9. Buttons That Maintain State................................................................................................................................. 577 Section 11.10. JComboBox and Using an Anonymous Inner Class for Event Handling........................................................... 583 Section 11.11. JList...................................................................................................................................................................... 587 Section 11.12. Multiple-Selection Lists...................................................................................................................................... 589 Section 11.13. Mouse Event Handling........................................................................................................................................ 592 Section 11.14. Adapter Classes.................................................................................................................................................... 597 Section 11.15. JPanel Subclass for Drawing with the Mouse..................................................................................................... 600 Section 11.16. Key-Event Handling............................................................................................................................................ 604 Section 11.17. Layout Managers................................................................................................................................................. 607 Section 11.18. Using Panels to Manage More Complex Layouts................................................................................................. 617 Section 11.19. JTextArea............................................................................................................................................................. 618 Section 11.20. Wrap-Up.............................................................................................................................................................. 621 Summary.................................................................................................................................................................................... 622 Terminology............................................................................................................................................................................... 628 Self-Review Exercises................................................................................................................................................................ 630 Answers to Self-Review Exercises.............................................................................................................................................. 631 Exercises..................................................................................................................................................................................... 631 Chapter 12. Graphics and Java 2D™........................................................ 636 Section 12.1. Introduction.......................................................................................................................................................... 637 Section 12.2. Graphics Contexts and Graphics Objects............................................................................................................. 639 Section 12.3. Color Control........................................................................................................................................................ 640 Section 12.4. Font Control......................................................................................................................................................... 647 Section 12.5. Drawing Lines, Rectangles and Ovals................................................................................................................... 653 Section 12.6. Drawing Arcs........................................................................................................................................................ 657 Section 12.7. Drawing Polygons and Polylines.......................................................................................................................... 660 Section 12.8. Java 2D API.......................................................................................................................................................... 663 Section 12.9. Wrap-Up............................................................................................................................................................... 670 Summary.................................................................................................................................................................................... 670 Terminology............................................................................................................................................................................... 672 Self-Review Exercises................................................................................................................................................................. 673 Answers to Self-Review Exercises.............................................................................................................................................. 674 Exercises..................................................................................................................................................................................... 674 Chapter 13. Exception Handling.............................................................. 679 Section 13.1. Introduction.......................................................................................................................................................... 680 Section 13.2. Exception-Handling Overview............................................................................................................................. 681 Section 13.3. Example: Divide by Zero without Exception Handling........................................................................................ 682 Section 13.4. Example: Handling ArithmeticExceptions and InputMismatchExceptions....................................................... 684 Section 13.5. When to Use Exception Handling........................................................................................................................ 689 Section 13.6. Java Exception Hierarchy.................................................................................................................................... 690 Section 13.7. finally Block.......................................................................................................................................................... 693 Section 13.8. Stack Unwinding.................................................................................................................................................. 697 Section 13.9. printStackTrace, getStackTrace and getMessage................................................................................................. 699 Section 13.10. Chained Exceptions............................................................................................................................................. 701 Section 13.11. Declaring New Exception Types.......................................................................................................................... 703 Section 13.12. Preconditions and Postconditions...................................................................................................................... 704 Section 13.13. Assertions............................................................................................................................................................ 705 Section 13.14. Wrap-Up............................................................................................................................................................. 706 Summary.................................................................................................................................................................................... 707 Terminology................................................................................................................................................................................ 710 Self-Review Exercises................................................................................................................................................................. 710 Answers to Self-Review Exercises............................................................................................................................................... 711 Exercises..................................................................................................................................................................................... 712 Chapter 14. Files and Streams.................................................................. 713 Section 14.1. Introduction........................................................................................................................................................... 714 Section 14.2. Data Hierarchy...................................................................................................................................................... 715 Section 14.3. Files and Streams.................................................................................................................................................. 717 Section 14.4. Class File............................................................................................................................................................... 719 Section 14.5. Sequential-Access Text Files................................................................................................................................ 723 Section 14.6. Object Serialization.............................................................................................................................................. 739 Section 14.7. Additional java.io Classes..................................................................................................................................... 748 Section 14.8. Opening Files with JFileChooser......................................................................................................................... 750 Section 14.9. Wrap-Up............................................................................................................................................................... 754 Summary.................................................................................................................................................................................... 754 Terminology............................................................................................................................................................................... 756 Self-Review Exercises................................................................................................................................................................. 757 Answers to Self-Review Exercises.............................................................................................................................................. 759 Exercises..................................................................................................................................................................................... 760 Chapter 15. Recursion............................................................................. 764 Section 15.1. Introduction.......................................................................................................................................................... 765 Section 15.2. Recursion Concepts.............................................................................................................................................. 766 Section 15.3. Example Using Recursion: Factorials................................................................................................................... 767 Section 15.4. Example Using Recursion: Fibonacci Series......................................................................................................... 770 Section 15.5. Recursion and the Method-Call Stack................................................................................................................... 773 Section 15.6. Recursion vs. Iteration.......................................................................................................................................... 774 Section 15.7. Towers of Hanoi.................................................................................................................................................... 776 Section 15.8. Fractals.................................................................................................................................................................. 779 Section 15.9. Recursive Backtracking........................................................................................................................................ 790 Section 15.10. Wrap-Up............................................................................................................................................................. 790 Section 15.11. Internet and Web Resources............................................................................................................................... 791 Summary.................................................................................................................................................................................... 792 Terminology............................................................................................................................................................................... 794 Self-Review Exercises................................................................................................................................................................. 794 Answers to Self-Review Exercises.............................................................................................................................................. 795 Exercises..................................................................................................................................................................................... 795 Chapter 16. Searching and Sorting.......................................................... 800 Section 16.1. Introduction.......................................................................................................................................................... 801 Section 16.2. Searching Algorithms.......................................................................................................................................... 802 Section 16.3. Sorting Algorithms................................................................................................................................................ 811 Section 16.4. Invariants............................................................................................................................................................. 826 Section 16.5. Wrap-Up............................................................................................................................................................... 827 Summary.................................................................................................................................................................................... 828 Terminology............................................................................................................................................................................... 829 Self-Review Exercises................................................................................................................................................................ 830 Answers to Self-Review Exercises............................................................................................................................................. 830 Exercises.................................................................................................................................................................................... 830 Chapter 17. Data Structures..................................................................... 833 Section 17.1. Introduction.......................................................................................................................................................... 834 Section 17.2. Type-Wrapper Classes for Primitive Types........................................................................................................... 835 Section 17.3. Autoboxing and Auto-Unboxing.......................................................................................................................... 835 Section 17.4. Self-Referential Classes........................................................................................................................................ 836 Section 17.5. Dynamic Memory Allocation................................................................................................................................ 837 Section 17.6. Linked Lists........................................................................................................................................................... 837 Section 17.7. Stacks.................................................................................................................................................................... 848 Section 17.8. Queues.................................................................................................................................................................. 852 Section 17.9. Trees...................................................................................................................................................................... 854 Section 17.10. Wrap-Up.............................................................................................................................................................. 861 Summary.................................................................................................................................................................................... 861 Terminology............................................................................................................................................................................... 863 Self-Review Exercises................................................................................................................................................................ 864 Answers to Self-Review Exercises............................................................................................................................................. 865 Exercises.................................................................................................................................................................................... 866 Chapter 18. Generics............................................................................... 886 Section 18.1. Introduction.......................................................................................................................................................... 887 Section 18.2. Motivation for Generic Methods......................................................................................................................... 888 Section 18.3. Generic Methods: Implementation and Compile-Time Translation................................................................... 890 Section 18.4. Additional Compile-Time Translation Issues: Methods That Use a Type Parameter as the Return Type......... 893 Section 18.5. Overloading Generic Methods............................................................................................................................. 896 Section 18.6. Generic Classes..................................................................................................................................................... 897 Section 18.7. Raw Types............................................................................................................................................................. 907 Section 18.8. Wildcards in Methods That Accept Type Parameters........................................................................................... 911 Section 18.9. Generics and Inheritance: Notes.......................................................................................................................... 915 Section 18.10. Wrap-Up............................................................................................................................................................. 916 Section 18.11. Internet and Web Resources............................................................................................................................... 916 Summary.................................................................................................................................................................................... 916 Terminology................................................................................................................................................................................ 919 Self-Review Exercises................................................................................................................................................................. 919 Answers to Self-Review Exercises.............................................................................................................................................. 919 Exercises.................................................................................................................................................................................... 920 Chapter 19. Collections............................................................................ 921 Section 19.1. Introduction.......................................................................................................................................................... 922 Section 19.2. Collections Overview............................................................................................................................................ 923 Section 19.3. Class Arrays.......................................................................................................................................................... 924 Section 19.4. Interface Collection and Class Collections............................................................................................................ 927 Section 19.5. Lists...................................................................................................................................................................... 928 Section 19.6. Collections Algorithms......................................................................................................................................... 939 Section 19.7. Stack Class of Package java.util............................................................................................................................ 952 Section 19.8. Class PriorityQueue and Interface Queue............................................................................................................. 955 Section 19.9. Sets........................................................................................................................................................................ 956 Section 19.10. Maps.................................................................................................................................................................... 959 Section 19.11. Properties Class................................................................................................................................................... 964 Section 19.12. Synchronized Collections.................................................................................................................................... 967 Section 19.13. Unmodifiable Collections................................................................................................................................... 967 Section 19.14. Abstract Implementations.................................................................................................................................. 968 Section 19.15. Wrap-Up............................................................................................................................................................. 968 Summary.................................................................................................................................................................................... 969 Terminology............................................................................................................................................................................... 972 Self-Review Exercises................................................................................................................................................................. 973 Answers to Self-Review Exercises.............................................................................................................................................. 973 Exercises..................................................................................................................................................................................... 974 Chapter 20. Introduction to Java Applets................................................ 976 Section 20.1. Introduction.......................................................................................................................................................... 977 Section 20.2. Sample Applets Provided with the JDK............................................................................................................... 977 Section 20.3. Simple Java Applet: Drawing a String................................................................................................................. 982 Section 20.4. Applet Life-Cycle Methods.................................................................................................................................. 987 Section 20.5. Initializing an Instance Variable with Method init.............................................................................................. 988 Section 20.6. Sandbox Security Model...................................................................................................................................... 990 Section 20.7. Internet and Web Resources............................................................................................................................... 990 Section 20.8. Wrap-Up............................................................................................................................................................... 991 Summary.................................................................................................................................................................................... 991 Terminology............................................................................................................................................................................... 993 Self-Review Exercise.................................................................................................................................................................. 993 Answers to Self-Review Exercise............................................................................................................................................... 993 Exercises...................................................................................................................................