Learning Java
Java is the preferred language for many of today's leading-edge technologies - everything from smartphones and game consoles to robots, massive enterprise systems, and supercomputers. If you're new to Java, the fourth edition of this bestselling guide provides an example-driven introduction to the lOURTH EDITIONLearning javaPatrick Niemeyer and Daniel leuckORE|LLY°Beijing· Cambridge. Farnham:Kdln· Sebastopol· TokyoLearning Java, Fourth Editionby Patrick Niemeyer and Daniel LeuckCopyright O 2013 Patrick Niemeyer, Daniel Leuck. All rights reservedPrinted in the united states of americaPublished by o reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472OReilly books may be purchased for educational, business, or sales promotional use. Online editions arealsoavailableformosttitles(http://my.safaribooksonline.com).Formoreinformation,contactourcorporateinstitutionalsalesdepartment800-998-9938orcorporate@oreilly.comEditors: Mike Loukides and Meghan blanchetteIndexer: BIM Publishing Services, IncProduction Editor: Rachel SteelyCover Designer: Randy comerCopyeditor: Gillian McgarveyInterior Designer: David FutatoProofreader: Rachel monaghanustrators: robert romano and rebecca demarestJune 2013Fourth editionRevision history for the Fourth Edition:2013-06-06: First releaseSeehttp://oreilly.com/catalog/errata.csp?isbn=9781449319243forreleasedetailsNutshell Handbook, the Nutshell Handbooklogo, and the O Reilly logo are registered trademarks ofO ReillyMedia, Inc. Learning Java, Fourth Edition, the image of a Bengal tigress and her cubs, and related trade dressare trademarks of O Reilly Media, Inc.Many of the designations used by manufacturers and sellers to distinguish their products are claimed atrademarks. Where those designations appear in this book, and O Reilly Media, Inc, was aware of a trademark claim, the designations have been printed in caps or initial capsWhile every precaution has been taken in the preparation of this book, the publisher and authors assumeno responsibility for errors or omissions, or for damages resulting from the use of the information containedhereinISBN:978-1-449-31924-3Table of contentsPreface1. A Modern Language.Enter javaJavas originsGrowing upAⅤ irtual machine22347Java Compared with Other LanguagesSafety of design10Simplify, Simplify, Simplify10Type Safety and Method Binding11Incremental DevelopmentDynamic Memory Management13Error Handling14treads14Scalability15Safety of ImplementationThe VerifierClass loaders18Security managersApplication and User-Level Security19A Java Road Map20The Past: Java 1.0-Java 1.620The Present: Java 721The Future23Availability232. A First Application25Java Tools and environment25Configuring Eclipse and Creating a ProjectImporting the Learning Java Examples28Hellojava29Classes32The main( Method33Classes and objects34Variables and Class Types34Hellocomponent35InheritanceThe j Component Class37Relationships and Finger Pointing38Package and Imports39The paint Component( MethodHellojava2 The Sequel41Instance variables43ConstructorsEvents45The repaint( MethodInterfacesHelloJava3: The Button Strikes49Method Overloading51Components52Containers52Layout53Subclassing and subtypes54More Events and Interfaces54Color CommentaryStatic members55arrays56Our Color methods56HelloJava4: Netscapes Revenge58reads60The Thread class61The Runnable interface61Starting the Thread62Running Code in the Thread62Exceptions63yncnronization3. Tools of the trade春·。JDK Environment67The java VM68Table of contentsRunning Java ApplicationsSystem propertie70The Classpath70apThe java compile72JAR Files74File CompressionThe jar Utility75The pack200 UtilityPolicy files78The Default Security ManagerThe policytool Utility79Using a Policy File with the Default Security Manager814. The Java Language…Text Encoding83Comments84Javadoc Comments8586Primitive types87Reference Types91A Word About Strings93Statements and expressions93Statements94Expressions100Exceptions104Exceptions and Error classes105Exception Handling107Bubbling UpStack traces110Checked and Unchecked Exceptions111rowing Exceptionsy Creep115The finally clause116Try with ResourcesPerformance issues119assertions119Enabling and Disabling Assertions120Using Assertions121arrays122array types123Array Creation and Initialization123Table of Contents IIsing arrays125Anonymous arrays127Multidimensional arrays127Inside arrays1295. Objects in Java131Classes132Accessing Fields and Methods133Static Members135Methods138Local variables139Shadowing139Static Methods140Initializing Local variables141Argument Passing and References142Wrappers for Primitive Types144Autoboxing and Unboxing of Primitives146Variable-Length Argument Lists147Method Overloading148Object Creation149Constructors150Working with Overloaded Constructors151Static and Nonstatic Initializer blocks153Object Destruction154Garbage Collection154Finalization155Weak and soft references155Enumerations156Enum values158Customizing enumerations1586. Relationships among classes,,161Subclassing and inheritance161Shadowed Variable163Overriding methods165Special References: this and super172Casting172Using Superclass Constructors174Full Disclosure: Constructors and initialization175Abstract methods and Classes176InterfacesInterfaces as callbacks179Table of contentsInterface Variables180Subinterfaces181Packages and Compilation Units182Compilation Units182Package Names183Class visibility183Importing classes184Visibility of variables and methods186Basic access modifiers186Subclasses and visibility188Interfaces and visibility189Arrays and the class hierarchy189ArraystoreException190Inner classes190Inner Classes as Adapters192Inner Classes Within methods1947. Working with Objects and Classes.201The Object Class201Equality and equivalence202Hashcode203Cloning Objects203The Class class206Reflection208Modifiers and Security211Accessing Fields212Accessing methods213Accessing constructors215What about arrays?216Accessing Generic Type Information216Accessing annotation Data217Dynamic Interface Adapters217What Is Reflection Good For218Annotations219USing annotations220Standard annotations221The apt to2228. Generics223Containers: Building a Better Mousetrap224Can Containers be fixed?224Enter generics225Table of contentsⅶiTalking About tyypes228There Is No spoon229Erasure230Raw Types231Parameterized Type Relationships232Why Isnt a List< Date> a List
用户评论