www.it-ebooks.info www.it-ebooks.info Robert Liguori and Patricia Liguori Java 8 Pocket Guide www.it-ebooks.info Java 8 Pocket Guide by Robert Liguori and Patricia Liguori Copyright © 2014 Gliesian, LLC. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebasto‐ pol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://my.safaribookson line.com). For more information, contact our corporate/institutional sales de‐ partment: 800-998-9938 or corporate@oreilly.com. Editors: Mike Loukides and Meghan Blanchette Production Editor: Melanie Yarbrough Proofreader: Gillian McGarvey Indexer: WordCo Indexing Services Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Rebecca Demarest April 2014: First Edition Revision History for the First Edition: 2014-04-07: First release See http://oreilly.com/catalog/errata.csp?isbn=9781491900864 for release de‐ tails. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Java 8 Pocket Guide, the cover image of a Javan tiger, and related trade dress are trademarks of O’Reilly Media, Inc. 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-1-491-90086-4 [M] www.it-ebooks.info This book is dedicated to our beautiful, awesome-tastic daughter, Ashleigh. www.it-ebooks.info www.it-ebooks.info Table of Contents Preface xi Part I. Language Chapter 1: Naming Conventions 3 Class Names 3 Interface Names 3 Method Names 4 Instance and Static Variable Names 4 Parameter and Local Variable Names 4 Generic Type Parameter Names 4 Constant Names 5 Enumeration Names 5 Package Names 5 Annotation Names 6 Acronyms 6 Chapter 2: Lexical Elements 7 Unicode and ASCII 7 Comments 9 v www.it-ebooks.info Keywords 10 Identifiers 11 Separators 12 Operators 12 Literals 14 Escape Sequences 17 Unicode Currency Symbols 18 Chapter 3: Fundamental Types 21 Primitive Types 21 Literals for Primitive Types 22 Floating-Point Entities 23 Numeric Promotion of Primitive Types 26 Wrapper Classes 27 Autoboxing and Unboxing 28 Chapter 4: Reference Types 31 Comparing Reference Types to Primitive Types 32 Default Values 32 Conversion of Reference Types 34 Converting Between Primitives and Reference Types 35 Passing Reference Types into Methods 35 Comparing Reference Types 37 Copying Reference Types 40 Memory Allocation and Garbage Collection of Reference Types 41 Chapter 5: Object-Oriented Programming 43 Classes and Objects 43 Variable-Length Argument Lists 49 Abstract Classes and Abstract Methods 51 vi | Table of Contents www.it-ebooks.info Static Data Members, Static Methods, Static Constants, and Static Initializers 52 Interfaces 53 Enumerations 54 Annotation Types 55 Functional Interfaces 57 Chapter 6: Statements and Blocks 59 Expression Statements 59 Empty Statement 60 Blocks 60 Conditional Statements 60 Iteration Statements 62 Transfer of Control 64 Synchronized Statement 66 Assert Statement 66 Exception Handling Statements 67 Chapter 7: Exception Handling 69 The Exception Hierarchy 69 Checked/Unchecked Exceptions and Errors 70 Common Checked/Unchecked Exceptions and Errors 71 Exception Handling Keywords 74 The Exception Handling Process 78 Defining Your Own Exception Class 79 Printing Information About Exceptions 80 Chapter 8: Java Modifiers 83 Access Modifiers 84 Table of Contents | vii www.it-ebooks.info Other (Nonaccess) Modifiers 85 Part II. Platform Chapter 9: Java Platform, Standard Edition 89 Common Java SE API Libraries 89 Chapter 10: Development Basics 103 Java Runtime Environment 103 Java Development Kit 103 Java Program Structure 104 Command-Line Tools 106 Classpath 113 Chapter 11: Memory Management 115 Garbage Collectors 115 Memory Management Tools 117 Command-Line Options 118 Resizing the JVM Heap 121 Metaspace 121 Interfacing with the GC 122 Chapter 12: Basic Input and Output 125 Standard Streams in, out, and err 125 Class Hierarchy for Basic Input and Output 126 File Reading and Writing 127 Socket Reading and Writing 129 Serialization 131 Zipping and Unzipping Files 132 Chapter 13: New I/O API (NIO.2) 135 The Path Interface 135 viii | Table of Contents www.it-ebooks.info [...]... SP 48 0 64 @ 80 P 96 ' 112 p 33 ! 49 1 65 A 81 Q 97 a 113 q 34 " 50 2 66 B 82 R 98 b 114 r 35 # 51 3 67 C 83 S 99 C 115 S 36 $ 52 4 68 D 84 T 100 d 116 t 37 % 53 5 69 E 85 U 101 e 117 u 38 & 54 6 70 F 86 V 102 f 1 18 v 39 ' 55 7 71 G 87 W 103 g 119 w 40 ( 56 8 72 H 88 X 104 h 120 x 41 ) 57 9 73 I 89 Y 105 i 121 y 42 * 58 : 74 J 90 Z 106 j 122 z 43 + 59 ; 75 K 91 [ 107 k 123 { 44 , 60 < 76 L 92 \ 1 08 l... are considering pursuing this Java certification, you may also wish to consider acquiring OCA Java SE 7 Programmer I Study Guide (Exam 1Z0 -80 3) by Edward Finegan and Robert Liguori (McGraw-Hill Osborne Media, 2012) Java coverage in this book is representative through Java SE 8 However, the primary differences between this Java 8 Pocket Guide and the prior Java 7 Pocket Guide is the addition of the Date... symbols are present in the range of \u20A0– \u20CF (83 52– +83 99+) See Table 2 -8 for examples Table 2 -8 Currency symbols within range Name Symbol Decimal Unicode Franc sign ₣ 83 55 \u20A3 Lira sign ₤ 83 56 \u20A4 Mill sign ₥ 83 57 \u20A5 Rupee sign ₨ 83 60 \u20A8 Dong sign ₫ 83 63 \u20AB Euro sign € 83 64 \u20AC Drachma sign ₯ 83 67 \u20AF German penny sign ₰ 83 68 \u20B0 A number of currency symbols exist outside... (technical editor of the initial Java Pocket Guide) , our technical reviewer Ryan Cuprak, as well as the various members of the O’Reilly team, our family, and our friends We would also like to thank again all of those who participated with the original Java Pocket Guide and the Java 7 Pocket Guide Most importantly, we thank you for using the book as a reference guide and for loving Java Feel free to post a... O’Reilly Media, Inc 1005 Gravenstein Highway North Sebastopol, CA 95472 80 0-9 98- 99 38 (in the United States or Canada) 707 -82 9-0515 (international or local) 707 -82 9-0104 (fax) We have a web page for this book, where we list errata, examples, and any additional information You can access this page at http:// oreil.ly /java- 8- pocket- guide To comment or ask technical questions about this book, send email... Functional Interfaces Resources for λEs 179 179 182 182 184 Part III Appendixes A Fluent APIs 189 B Third-Party Tools 191 C UML Basics 201 Index 211 x | Table of Contents www.it-ebooks.info Preface Designed to be your companion, 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... Java, comments cannot be nested: /* This is /* not permissible */ in Java */ Keywords Table 2-3 contains the Java keywords Two of these, the const and goto keywords, are reserved but are not used by the Java language Java 5.0 introduced the enum keyword TIP Java keywords cannot be used as identifiers in a Java pro‐ gram Table 2-3 Java keywords abstract double int super assert else interface switch... first 1 28 characters being the same as those in the American Standard Code for In‐ formation Interchange (ASCII) character set Unicode provides a unique number for character, usable across all platforms, pro‐ grams, and languages Java SE 8 uses Unicode 6.2.0 and you can find more information about it in the online manual Java SE 7 uses Unicode 6.0.0 Java SE 6 and J2SE 5.0 use Unicode 4.0 TIP Java comments,... are reserved literals Identifiers A Java identifier is the name that a programmer gives to a class, method, variable, and so on 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 char‐ acter for which Character.isJavaIdentifierStart(int) returns true Java letters from the ASCII character... www.it-ebooks.info | 9 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 aster‐ isks, and end with an asterisk immediately followed by a forward slash (Oracle’s documentation page provides more information on the Javadoc tool): /** This is my Javadoc comment */ In Java, comments cannot . Osborne Media, 2012). Java coverage in this book is representative through Java SE 8. However, the primary differences between this Java 8 Pocket Guide and the prior Java 7 Pocket Guide is the addition. Modifiers 85 Part II. Platform Chapter 9: Java Platform, Standard Edition 89 Common Java SE API Libraries 89 Chapter 10: Development Basics 103 Java Runtime Environment 103 Java Development Kit 103 Java. www.it-ebooks.info www.it-ebooks.info Robert Liguori and Patricia Liguori Java 8 Pocket Guide www.it-ebooks.info Java 8 Pocket Guide by Robert Liguori and Patricia Liguori Copyright © 2014 Gliesian,