www.finebook.ir www.finebook.ir Java 8 Pocket Guide Robert Liguori and Patricia Liguori www.finebook.ir 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 This book is dedicated to our beautiful, awesome-tastic daughter, Ashleigh. www.finebook.ir www.finebook.ir 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.finebook.ir 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.finebook.ir 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.finebook.ir 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.finebook.ir