O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java Pocket Guide, 4th Edition

Book Description

Any time you need quick answers for developing or debugging Java programs, this pocket guide is the ideal reference to standard features of the Java programming language and its platform. You’ll find helpful programming examples, tables, figures, and lists fast—including Java 9 features such as modular source code and the new JShell interactive command-line REPL. It’s a handy companion, whether you’re in the office, in the lab, or on the road.

This book also provides material to help you prepare for the Oracle Certified Associate Java Programmer exam.

  • Quickly find Java language details, such as naming conventions, types, statements and blocks, and object-oriented programming
  • Get details on the Java SE platform, including development basics, memory management, concurrency, and generics
  • Use new features in Java 9, including modular source code and JShell
  • Browse through information on basic input/output, NIO 2.0, the Java collections framework, and the Java Scripting API
  • Get supplemental references to fluent APIs, third-party tools, and basics of the Unified Modeling Language (UML)

Table of Contents

  1. Preface
    1. Book Structure
    2. Conventions Used in This Book
    3. O’Reilly Safari
    4. How to Contact Us
    5. Acknowledgments
  2. I. Language
  3. 1. Naming Conventions
    1. Acronyms
    2. Annotation Names
    3. Class Names
    4. Constant Names
    5. Enumeration Names
    6. Generic Type Parameter Names
    7. Instance and Static Variable Names
    8. Interface Names
    9. Method Names
    10. Package Names
    11. Module Names
    12. Parameter and Local Variable Names
  4. 2. Lexical Elements
    1. Unicode and ASCII
      1. Printable ASCII Characters
      2. Nonprintable ASCII Characters
    2. Compact Strings
    3. Comments
    4. Keywords
    5. Identifiers
    6. Separators
    7. Operators
    8. Literals
      1. Boolean Literals
      2. Character Literals
      3. Integer Literals
      4. Floating-Point Literals
      5. String Literals
      6. Null Literals
    9. Escape Sequences
    10. Unicode Currency Symbols
  5. 3. Fundamental Types
    1. Primitive Types
    2. Literals for Primitive Types
    3. Floating-Point Entities
      1. Operations Involving Special Entities
    4. Numeric Promotion of Primitive Types
      1. Unary Numeric Promotion
      2. Binary Numeric Promotion
      3. Special Cases for Conditional Operators
    5. Wrapper Classes
    6. Autoboxing and Unboxing
      1. Autoboxing
      2. Unboxing
  6. 4. Reference Types
    1. Comparing Reference Types to Primitive Types
    2. Default Values
      1. Instance and Local Variable Objects
      2. Arrays
    3. Conversion of Reference Types
      1. Widening Conversions
      2. Narrowing Conversions
    4. Converting Between Primitives and Reference Types
    5. Passing Reference Types into Methods
    6. Comparing Reference Types
      1. Using the Equality Operators
      2. Using the equals() Method
      3. Comparing Strings
      4. Comparing Enumerations
    7. Copying Reference Types
      1. Copying a Reference to an Object
      2. Cloning Objects
    8. Memory Allocation and Garbage Collection of Reference Types
  7. 5. Object-Oriented Programming
    1. Classes and Objects
      1. Class Syntax
      2. Instantiating a Class (Creating an Object)
      3. Data Members and Methods
      4. Accessing Data Members and Methods in Objects
      5. Overloading
      6. Overriding
      7. Constructors
      8. Superclasses and Subclasses
      9. The this Keyword
    2. Variable-Length Argument Lists
    3. Abstract Classes and Abstract Methods
      1. Abstract Classes
      2. Abstract Methods
    4. Static Data Members, Static Methods, Static Constants, and Static Initializers
      1. Static Data Members
      2. Static Methods
      3. Static Constants
      4. Static Initializers
    5. Interfaces
    6. Enumerations
    7. Annotation Types
      1. Built-in Annotations
      2. Developer-Defined Annotations
    8. Functional Interfaces
  8. 6. Statements and Blocks
    1. Expression Statements
    2. Empty Statement
    3. Blocks
    4. Conditional Statements
      1. The if Statement
      2. The if else Statement
      3. The if else if Statement
      4. The switch Statement
    5. Iteration Statements
      1. The for Loop
      2. The Enhanced for Loop
      3. The while Loop
      4. The do while Loop
    6. Transfer of Control
      1. The break Statement
      2. The continue Statement
      3. The return Statement
    7. Synchronized Statement
    8. Assert Statement
    9. Exception Handling Statements
  9. 7. Exception Handling
    1. The Exception Hierarchy
    2. Checked/Unchecked Exceptions and Errors
      1. Checked Exceptions
      2. Unchecked Exceptions
      3. Errors
    3. Common Checked/Unchecked Exceptions and Errors
      1. Common Checked Exceptions
      2. Common Unchecked Exceptions
      3. Common Errors
    4. Exception Handling Keywords
      1. The throw Keyword
      2. The try/catch/finally Keywords
      3. The try-catch Statement
      4. The try-finally Statement
      5. The try-catch-finally Statement
      6. The try-with-resources Statement
      7. The multi-catch Clause
    5. The Exception Handling Process
    6. Defining Your Own Exception Class
    7. Printing Information About Exceptions
      1. The getMessage() Method
      2. The toString() Method
      3. The printStackTrace() Method
  10. 8. Java Modifiers
    1. Access Modifiers
    2. Other (Nonaccess) Modifiers
    3. Modifiers Encoding
  11. II. Platform
  12. 9. Java Platform, Standard Edition
    1. Common Java SE API Libraries
      1. Language and Utility Libraries
      2. Base Libraries
      3. Integration Libraries
      4. Miscellaneous User Interface Libraries
      5. JavaFX User Interface Library
      6. Remote Method Invocation (RMI) and CORBA Libraries
      7. Security Libraries
      8. Extensible Markup Language (XML) Libraries
  13. 10. Development Basics
    1. Java Runtime Environment
    2. Java Development Kit
    3. Java Program Structure
    4. Command-Line Tools
      1. Java Compiler
      2. Java Interpreter
      3. Java Program Packager
      4. JAR File Execution
    5. Classpath
  14. 11. Memory Management
    1. Garbage Collectors
      1. Serial Collector
      2. Parallel Collector
      3. Parallel Compacting Collector
      4. Concurrent Mark-Sweep Collector
      5. Garbage-First (G1) Collector
    2. Memory Management Tools
    3. Command-Line Options
    4. Resizing the JVM Heap
    5. Metaspace
    6. Interfacing with the GC
      1. Explicit Garbage Collection
      2. Finalization
  15. 12. Basic Input and Output
    1. Standard Streams in, out, and err
    2. Class Hierarchy for Basic Input and Output
    3. File Reading and Writing
      1. Reading Character Data from a File
      2. Reading Binary Data from a File
      3. Writing Character Data to a File
      4. Writing Binary Data to a File
    4. Socket Reading and Writing
      1. Reading Character Data from a Socket
      2. Reading Binary Data from a Socket
      3. Writing Character Data to a Socket
      4. Writing Binary Data to a Socket
    5. Serialization
      1. Serialize
      2. Deserialize
    6. Zipping and Unzipping Files
      1. Compressing and Uncompressing GZIP Files
  16. 13. New I/O API (NIO.2)
    1. The Path Interface
    2. The Files Class
    3. Additional Features
  17. 14. Concurrency
    1. Creating Threads
      1. Extending the Thread Class
      2. Implementing the Runnable Interface
    2. Thread States
    3. Thread Priorities
    4. Common Methods
    5. Synchronization
    6. Concurrent Utilities
      1. Executors
      2. Concurrent Collections
      3. Synchronizers
      4. Timing Utility
  18. 15. Java Collections Framework
    1. The Collection Interface
    2. Implementations
    3. Collection Framework Methods
    4. Collections Class Algorithms
    5. Algorithm Efficiencies
    6. Comparator Functional Interface
    7. Convenience Factory Methods
  19. 16. Generics Framework
    1. Generic Classes and Interfaces
    2. Constructors with Generics
    3. Substitution Principle
    4. Type Parameters, Wildcards, and Bounds
    5. The Get and Put Principle
    6. Generic Specialization
    7. Generic Methods in Raw Types
  20. 17. The Java Scripting API
    1. Scripting Languages
    2. Script Engine Implementations
      1. Embedding Scripts into Java
      2. Invoking Methods of Scripting Languages
      3. Accessing and Controlling Java Resources from Scripts
    3. Setting Up Scripting Languages and Engines
      1. Scripting Language Setup
      2. Scripting Engine Setup
      3. Scripting Engine Validation
  21. 18. Date and Time API
    1. Legacy Interoperability
    2. Regional Calendars
    3. ISO Calendar
      1. Machine Interface
      2. Durations and Periods
      3. JDBC and XSD Mapping
      4. Formatting
  22. 19. Lambda Expressions
    1. λEs Basics
      1. λEs Syntax and Example
      2. Method and Constructor References
    2. Specific-Purpose Functional Interfaces
    3. General-Purpose Functional Interfaces
    4. Resources for λEs
      1. Tutorials
      2. Community Resources
  23. 20. JShell: the Java Shell
    1. Getting Started
    2. Snippets
      1. Modifiers
      2. Flow Control Statements
      3. Package Declarations
    3. Using JShell
      1. Primary Expressions
      2. Dependencies
      3. Statements and Code Blocks
      4. Method and Class Declarations
      5. Viewing, Deleting, and Modifying Snippets
      6. Saving, Loading, and State
    4. JShell Features
      1. Scratch Variables
      2. Tab Auto-Complete
      3. Forward Referencing
      4. Checked Exceptions
      5. Hierarchy and Scope
    5. Summary of JShell Commands
  24. 21. Java Module System
    1. Project Jigsaw
    2. Java Modules
      1. Automatic Modules
      2. Unnamed Modules
      3. Accessibility
    3. Compiling Modules
    4. Modular JDK
    5. jdeps
      1. Identifying Dependencies
      2. Identifying Undocumented JDK Internal Dependencies
    6. Defining a Module
    7. Exporting a Package
    8. Declaring Dependencies
    9. Transitive Dependencies
    10. Defining Service Providers
      1. Defining Service API
      2. Implementing Service API
      3. Using Service Providers
    11. jlink
  25. III. Appendixes
  26. A. Fluent APIs
  27. B. Third-Party Tools
    1. Development, CM, and Test Tools
    2. Libraries
    3. Integrated Development Environments
    4. Web Application Platforms
    5. Scripting Languages Compatible with JSR-223
  28. C. UML Basics
    1. Class Diagrams
      1. Name
      2. Attributes
      3. Operations
      4. Visibility
    2. Object Diagrams
    3. Graphical Icon Representation
      1. Classes, Abstract Classes, and Interfaces
      2. Notes
      3. Packages
    4. Connectors
    5. Multiplicity Indicators
    6. Role Names
    7. Class Relationships
      1. Association
      2. Direct Association
      3. Composition Association
      4. Aggregation Association
      5. Temporary Association
      6. Generalization
      7. Realization
    8. Sequence Diagrams
      1. Participant (1)
      2. Found Message (2)
      3. Synchronous Message (3)
      4. Return Call (4)
      5. Asynchronous Message (5)
      6. Message to Self (6)
      7. Lifeline (7)
      8. Activation Bar (8)
  29. Index