Java™: A Beginner’s Guide, pps

649 210 0
Java™: A Beginner’s Guide, pps

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / Front Matter Blind Folio FM:ii P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 01, 2005 10:22:50 AM Color profile: Generic CMYK printer profile Composite Default screen TEAM LinG Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / Front Matter Blind Folio FM:i Java ™ : A Beginner’s Guide, Third Edition P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 01, 2005 10:22:50 AM Color profile: Generic CMYK printer profile Composite Default screen TEAM LinG Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / Front Matter Blind Folio FM:ii P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 01, 2005 10:22:50 AM Color profile: Generic CMYK printer profile Composite Default screen This page intentionally left blank. TEAM LinG Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / Front Matter Blind Folio FM:iii Java ™ : A Beginner’s Guide, Third Edition Herbert Schildt McGraw-Hill/Osborne New York Chicago San Francisco Lisbon London Madrid Mexico City Milan New Delhi San Juan Seoul Singapore Sydney Toronto P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 01, 2005 10:22:50 AM Color profile: Generic CMYK printer profile Composite Default screen TEAM LinG Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / Front Matter Blind Folio FM:iv P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 01, 2005 10:22:50 AM Color profile: Generic CMYK printer profile Composite Default screen Copyright © 2005 by The McGraw-Hill Companies. All rights reserved. Manufactured in the United States of America. Except as permitted under the United States Copyright Act of 976, 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. 0-07-146650-9 The material in this eBook also appears in the print version of this title: 0-07-2231890-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. For more information, please contact George Hoare, Special Sales, at george_hoare@mcgraw-hill.com or (212) 904-4069. TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) 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. DOI: 10.1036/0071466509 TEAM LinG Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / Front Matter Blind Folio FM:ii P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 01, 2005 10:22:50 AM Color profile: Generic CMYK printer profile Composite Default screen  Want to learn more? We hope you enjoy this McGraw-Hill eBook! If you’d like more information about this book, its author, or related books and websites, please click here. TEAM LinG About the Author Herbert Schildt is the world’s leading programming author. He is an authority on the C, C++, Java, and C# languages, and he is a master Windows programmer. His programming books have sold more than 3 million copies worldwide and have been translated into all major languages. He is the author of numerous bestsellers, including Java: The Complete Reference, C++: The Complete Reference, C: The Complete Reference, and C#: The Complete Reference, and he is the co-author of The Art of Java. 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. Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / Front Matter Blind Folio FM:v P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 01, 2005 10:22:50 AM Color profile: Generic CMYK printer profile Composite Default screen Copyright © 2005 The McGraw-Hill Companies. Click here for terms of use. TEAM LinG Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / 1 Blind Folio FM:vii Contents at a Glance 1 Java Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 Introducing Data Types and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3 Program Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 4 Introducing Classes, Objects, and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 5 More Data Types and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 6 A Closer Look at Methods and Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 7 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 8 Packages and Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 9 Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333 10 Using I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365 11 Multithreaded Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407 12 Enumerations, Autoboxing, and Static Import . . . . . . . . . . . . . . . . . . . . . . . . . . 447 13 Generics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 14 Applets, Events, and Miscellaneous Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525 vii P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 01, 2005 10:22:50 AM Color profile: Generic CMYK printer profile Composite Default screen TEAM LinG Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / Front Matter Blind Folio FM:viii A Answers to Mastery Checks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557 B Using Java’s Documentation Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613 viii Java: A Beginner’s Guide P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 08, 2005 9:02:59 AM Color profile: Generic CMYK printer profile Composite Default screen TEAM LinG Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / 1 Blind Folio FM:ix ix Contents PREFACE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix 1 Java Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 The Origins of Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 How Java Relates to C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 How Java Relates to C# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Java’s Contribution to the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Java Applets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Java’s Magic: The Bytecode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 The Java Buzzwords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Encapsulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 Obtaining the Java Development Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 A First Simple Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Entering the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Compiling the Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 The First Sample Program Line by Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 P:\010Comp\Begin8\189-0\fm.vp Tuesday, March 01, 2005 10:22:50 AM Color profile: Generic CMYK printer profile Composite Default screen For more information about this title, click here TEAM LinG [...]... what sort of operations can be applied to that data To support the principles of object-oriented programming, all OOP languages, including Java, have three traits in common: encapsulation, polymorphism, and inheritance Let’s examine each 9 1 Java Fundamentals Java: A Beginner’s Guide Encapsulation Encapsulation is a programming mechanism that binds together code and the data it manipulates, and that... incorporate new features, Java has continually been at the forefront of computer language design One reason for this is the culture of innovation and change that came to surround Java As a result, Java has gone through several upgrades—some relatively small, others more significant The first major update to Java was version 1.1 The features added by Java 1.1 were more substantial than the small increase... Variable-length arguments (varargs) ● Static import ● Metadata (annotations) This is not a list of minor tweaks or incremental upgrades Each item in the list represents a significant addition to the Java language Some, such as generics, the enhanced for, and varargs, introduce new syntax elements Others, such as autoboxing and auto-unboxing, alter the semantics of the language Metadata adds an entirely... the areas of security and portability Prior to Java, cyberspace was effectively closed to half of the entities that now live there As you will see, Java addresses those concerns and, in doing so, has defined a new form of program: the applet Java Fundamentals CRITICAL SKILL 5 Java Applets An applet is a special kind of Java program that is designed to be transmitted over the Internet and automatically... system.) Java answers these concerns by providing a firewall between a networked application and your computer TEAM LinG 6 Module 1: Java Fundamentals When using a Java-compatible web browser, it is possible to safely download Java applets without fear of viral infection The way that Java achieves this is by confining a Java program to the Java execution environment and not allowing it access to other parts... preceding upgrades to Java have been, none compares in scale, size, and scope to that of J2SE 5 It has fundamentally reshaped the Java world! TEAM LinG Preface xxi J2SE 5: The Second Java Revolution Java 2 Platform Standard Edition, version 5 (J2SE 5) marks the beginning of the second Java revolution J2SE 5 adds many new features to Java that fundamentally change the character of the language, increasing both... Objects are instances of a class Thus, a class is essentially a set of plans that specify how to build an object The code and data that constitute a class are called members of the class Specifically, the data defined by the class are referred to as member variables or instance variables The code that operates on that data is referred to as member methods or just methods Method is Java’s term for a subroutine... structured programming techniques, programs are typically organized around code This approach can be thought of as “code acting on data.” Object-oriented programs work the other way around They are organized around data, with the key principle being “data controlling access to code.” In an object-oriented language, you define the data and the routines that are permitted to act on that data Thus, a data type... by a Java-compatible Web browser Furthermore, an applet is downloaded on demand, just like an image, sound file, or video clip The important difference is that an applet is an intelligent program, not just an animation or media file In other words, an applet is a program that can react to user input and dynamically change—not just run the same animation or sound over and over As exciting as applets are,... focus of Java to switch from consumer electronics to Internet programming So, while it was the desire for an architecture-neutral programming language that provided the initial spark, it was the Internet that ultimately led to Java’s large-scale success 3 1 Java Fundamentals Java: A Beginner’s Guide How Java Relates to C and C++ Java is directly related to both C and C++ Java inherits its syntax from . 0-07-2231890-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. Default screen TEAM LinG Begin8 / Java: A Beginner’s Guide, 3rd Ed/ Schildt / 3189-0 / Front Matter Blind Folio FM:xiv xiv Java: A Beginner’s Guide Java’s Class Library Is Contained in Packages. the essentials of Java programming. It is important to state at the outset that this book is just a starting point. Java is more than just the elements that define the language. Java also includes

Ngày đăng: 29/06/2014, 18:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan