1. Trang chủ
  2. » Công Nghệ Thông Tin

java pocket guide

193 2,2K 0

Đ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

Thông tin cơ bản

Định dạng
Số trang 193
Dung lượng 2,21 MB

Nội dung

www.it-ebooks.info www.it-ebooks.info JavaPocket Guide www.it-ebooks.info www.it-ebooks.info JavaPocket Guide Robert Liguori and Patricia Liguori Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo www.it-ebooks.info JavaPocket Guide by Robert Liguori and Patricia Liguori Copyright © 2008 Robert Liguori and Patricia Liguori. All rights reserved. Printed in Canada. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/ institutional sales department: (800) 998-9938 or corporate@oreilly.com. Editor: Mike Loukides Production Editor: Rachel Monaghan Copyeditor: Loranah Dimant Proofreader: Rachel Monaghan Indexer: Julie Hawks Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Printing History: March 2008: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. The Pocket Guide series designations, Java Pocket Guide, the image of a Javan tiger, and related trade dress are trademarks of O’Reilly Media, Inc. Java™ and all Java-based trademarks and logos are trademarks or registered trademarks of SunMicrosystems, Inc., in the United States and other countries. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. 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 caps. While every precaution has been taken in the preparation of this book, the publisher and authors assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. ISBN: 978-0-596-51419-8 [TM] www.it-ebooks.info v Contents Preface xi Part I. Language Chapter 1: Naming Conventions 3 Class Names 3 Interface Names 3 Method Names 3 Instance and Static Variable Names 4 Parameter and Local Variables Names 4 Generic Type Parameter Names 4 Constant Names 5 Enumeration Names 5 Package Names 5 Acronyms 5 Chapter 2: Lexical Elements 6 Unicode and ASCII 6 Comments 8 Keywords 9 Identifiers 10 www.it-ebooks.info vi | Contents Separators 10 Operators 10 Literals 12 Escape Sequences 15 Unicode Currency Symbols 15 Chapter 3: Fundamental Types 17 Primitive Types 17 Literals for Primitive Types 18 Floating-Point Entities 20 Numeric Promotion of Primitive Types 21 Wrapper Classes 23 Autoboxing and Unboxing 24 Chapter 4: Reference Types 26 Comparing Reference Types to Primitive Types 26 Default Values 27 Conversion of Reference Types 28 Converting Between Primitives and Reference Types 29 Passing Reference Types into Methods 30 Comparing Reference Types 31 Copying Reference Types 33 Memory Allocation and Garbage Collection of Reference Types 35 Chapter 5: Object-Oriented Programming 36 Classes and Objects 36 Variable Length Argument Lists 42 Abstract Classes and Abstract Methods 43 www.it-ebooks.info Contents | vii Static Data Members, Static Methods, and Static Constants 44 Interfaces 46 Enumerations 46 Annotations Types 47 Chapter 6: Statements and Blocks 50 Expression Statements 50 Empty Statement 51 Blocks 51 Conditional Statements 51 Iteration Statements 53 Transfer of Control 54 Synchronized Statement 56 Assert Statement 56 Exception Handling Statements 57 Chapter 7: Exception Handling 58 The Exception Hierarchy 58 Checked/Unchecked Exceptions and Errors 59 Common Checked/Unchecked Exceptions and Errors 60 Exception Handling Keywords 62 The Exception Handling Process 65 Defining Your Own Exception Class 66 Printing Information About Exceptions 66 Chapter 8: Java Modifiers 69 Access Modifiers 70 Other (Non-Access) Modifiers 71 www.it-ebooks.info viii | Contents Part II. Platform Chapter 9: Java Platform, SE 75 Common Java SE API Libraries 75 Chapter 10: Development Basics 87 Java Runtime Environment 87 Java Development Kit 87 Java Program Structure 88 Command-Line Tools 90 Classpath 96 Chapter 11: Basic Input and Output 97 Standard Streams in, out, and err 97 Class Hierarchy for Basic Input and Output 98 File Reading and Writing 99 Socket Reading and Writing 101 Serialization 103 Zipping and Unzipping Files 104 File and Directory Handling 105 Chapter 12: Java Collections Framework 107 The Collection Interface 107 Implementations 107 Collection Framework Methods 109 Collections Class Algorithms 109 Algorithm Efficiencies 110 Comparator Interface 112 www.it-ebooks.info [...]... www.it-ebooks.info In Java, comments cannot be nested /* This is /* not permissible */ in Java */ Keywords Table 2-3 contains the Java keywords Two of them are reserved but not used by the Java language: const and goto These C++ keywords are included as Java keywords to generate better error messages if they are used in a Java program Java 5.0 introduced the enum keyword TIP Java keywords cannot be... lines just like this */ A Javadoc comment is processed by the Javadoc tool to generate API documentation in HTML format A Javadoc comment must begin with a forward slash, immediately followed by two asterisks, and end with an asterisk immediately followed by a forward slash You can find more information on the Javadoc tool at http:/ /java. sun.com/j2se/javadoc/ /** This is my Javadoc comment */ 8 | Chapter... the road, this pocket guide provides a quick reference to the standard features of the Java programming language and its platform This pocket guide provides you with the information you will need while developing or debugging your Java programs, including helpful programming examples, tables, figures, and lists It also contains supplemental information about things such as the new Java Scripting API,... Keywords www.it-ebooks.info | 9 Identifiers A Java identifier is the name that a programmer gives to a class, method, variable, etc Identifiers cannot have the same Unicode character sequence as any keyword, boolean or null literal Java identifiers are made up of Java letters A Java letter is a character for which Character.isJavaIdentifierStart(int) returns true Java letters from the ASCII character set... provided through the Java 6 Platform Book Structure This book is broken into two sections: language and platform Chapters 1 through 8 detail the Java programming language as derived from the Java Language Specification (JLS) Chapters 9 though 18 detail Java platform components and related topics xi www.it-ebooks.info Font Conventions Italic Denotes filenames, file extensions (such as java) , and directory... find more about it at http://www unicode.org/versions/Unicode5.0.0/ TIP Java comments, identifiers, and string literals are not limited to ASCII characters All other Java input elements are formed from ASCII characters The Unicode set version used by a specified version of the Java platform is documented in the class Character of the Java API 6 www.it-ebooks.info Printable ASCII Characters ASCII reserves... names that begin with java and javax are restricted and can be used only to provide conforming implementations to the Java class libraries Acronyms When using acronyms in names, only the first letter of the acronym should be uppercase and only when uppercase is appropriate public String getGpsVersion( ) { } Acronyms www.it-ebooks.info | 5 CHAPTER 2 CHAPTER 2 Lexical Elements Java source code consists... Chapter 1 for naming guidelines Separators Nine ASCII characters delimit program parts and are used as separators ( ), { }, and [ ] are used in pairs ( ) { } [ ] ; , Operators Operators perform operations on one, two, or three operands and return a result Operator types in Java include assignment, arithmetic, comparison, bitwise, increment/decrement, and class/object Table 2-4 contains the Java operators... include the Java primitive types and their corresponding wrapper classes/reference types Java 5.0 and beyond provide for automatic conversion between these primitive and reference types through autoboxing and unboxing; see the “Autoboxing and Unboxing” section, later in this chapter Numeric promotion is applied to primitive types where appropriate Primitive Types There are eight primitive types in Java; ... are included as Java keywords to generate better error messages if they are used in a Java program Java 5.0 introduced the enum keyword TIP Java keywords cannot be used as identifiers in a Java program Table 2-3 Java keywords abstract double int super assert else interface switch boolean enum long synchronized break extends native this byte final new throw case finally package throws catch float private . Media, Inc. The Pocket Guide series designations, Java Pocket Guide, the image of a Javan tiger, and related trade dress are trademarks of O’Reilly Media, Inc. Java and all Java- based trademarks. www.it-ebooks.info www.it-ebooks.info Java ™ Pocket Guide www.it-ebooks.info www.it-ebooks.info Java ™ Pocket Guide Robert Liguori and Patricia Liguori Beijing • Cambridge • Farnham • Köln • Paris • Sebastopol • Taipei • Tokyo www.it-ebooks.info Java ™ . lab, or even on the road, this pocket guide provides a quick refer- ence to the standard features of the Java programming lan- guage and its platform. This pocket guide provides you with the information

Ngày đăng: 24/04/2014, 15:22

Xem thêm