Java in a Nutshell, 6th Edition

Book description

The latest edition of Java in a Nutshell is designed to help experienced Java programmers get the most out of Java 7 and 8, but it’s also a learning path for new developers. Chock full of examples that demonstrate how to take complete advantage of modern Java APIs and development best practices, the first section of this thoroughly updated book provides a fast-paced, no-fluff introduction to the Java programming language and the core runtime aspects of the Java platform.

The second section is a reference to core concepts and APIs that shows you how to perform real programming work in the Java environment.

  • Get up to speed on language details, including Java 8 changes
  • Learn object-oriented programming, using basic Java syntax
  • Explore generics, enumerations, annotations, and lambda expressions
  • Understand basic techniques used in object-oriented design
  • Examine concurrency and memory, and how they’re intertwined
  • Work with Java collections and handle common data formats
  • Delve into Java’s latest I/O APIs, including asynchronous channels
  • Use Nashorn to execute JavaScript on the Java Virtual Machine
  • Become familiar with development tools in OpenJDK

Publisher resources

View/Submit Errata

Table of contents

  1. Foreword
  2. Preface
    1. Changes in the Sixth Edition
    2. Contents of This Book
    3. Related Books
    4. Examples Online
    5. Conventions Used in This Book
    6. Request for Comments
    7. Safari® Books Online
    8. Acknowledgments
  3. I. Introducing Java
  4. 1. Introduction to the Java Environment
    1. The Language, the JVM, and the Ecosystem
      1. What Is the Java Language?
      2. What Is the JVM?
      3. What Is the Java Ecosystem?
    2. A Brief History of Java and the JVM
    3. The Lifecycle of a Java Program
      1. Frequently Asked Questions
    4. Java Security
    5. Comparing Java to Other Languages
      1. Java Compared to C
      2. Java Compared to C++
      3. Java Compared to PHP
      4. Java Compared to JavaScript
    6. Answering Some Criticisms of Java
      1. Overly Verbose
      2. Slow to Change
      3. Performance Problems
      4. Insecure
      5. Too Corporate
  5. 2. Java Syntax from the Ground Up
    1. Java Programs from the Top Down
    2. Lexical Structure
      1. The Unicode Character Set
      2. Case Sensitivity and Whitespace
      3. Comments
      4. Reserved Words
      5. Identifiers
      6. Literals
      7. Punctuation
    3. Primitive Data Types
      1. The boolean Type
      2. The char Type
      3. Integer Types
      4. Floating-Point Types
      5. Primitive Type Conversions
    4. Expressions and Operators
      1. Operator Summary
      2. Arithmetic Operators
      3. String Concatenation Operator
      4. Increment and Decrement Operators
      5. Comparison Operators
      6. Boolean Operators
      7. Bitwise and Shift Operators
      8. Assignment Operators
      9. The Conditional Operator
      10. The instanceof Operator
      11. Special Operators
    5. Statements
      1. Expression Statements
      2. Compound Statements
      3. The Empty Statement
      4. Labeled Statements
      5. Local Variable Declaration Statements
      6. The if/else Statement
      7. The switch Statement
      8. The while Statement
      9. The do Statement
      10. The for Statement
      11. The foreach Statement
      12. The break Statement
      13. The continue Statement
      14. The return Statement
      15. The synchronized Statement
      16. The throw Statement
      17. The try/catch/finally Statement
      18. The try-with-resources Statement
      19. The assert Statement
    6. Methods
      1. Defining Methods
      2. Method Modifiers
      3. Checked and Unchecked Exceptions
      4. Variable-Length Argument Lists
    7. Introduction to Classes and Objects
      1. Defining a Class
      2. Creating an Object
      3. Using an Object
      4. Object Literals
      5. Lambda Expressions
    8. Arrays
      1. Array Types
      2. Creating and Initializing Arrays
      3. Using Arrays
      4. Multidimensional Arrays
    9. Reference Types
      1. Reference Versus Primitive Types
      2. Manipulating Objects and Reference Copies
      3. Comparing Objects
      4. Boxing and Unboxing Conversions
    10. Packages and the Java Namespace
      1. Package Declaration
      2. Globally Unique Package Names
      3. Importing Types
      4. Importing Static Members
    11. Java File Structure
    12. Defining and Running Java Programs
    13. Summary
  6. 3. Object-Oriented Programming in Java
    1. Overview of Classes
      1. Basic OO Definitions
      2. Other Reference Types
      3. Class Definition Syntax
    2. Fields and Methods
      1. Field Declaration Syntax
      2. Class Fields
      3. Class Methods
      4. Instance Fields
      5. Instance Methods
      6. How the this Reference Works
    3. Creating and Initializing Objects
      1. Defining a Constructor
      2. Defining Multiple Constructors
      3. Invoking One Constructor from Another
      4. Field Defaults and Initializers
    4. Subclasses and Inheritance
      1. Extending a Class
      2. Superclasses, Object, and the Class Hierarchy
      3. Subclass Constructors
      4. Constructor Chaining and the Default Constructor
      5. Hiding Superclass Fields
      6. Overriding Superclass Methods
    5. Data Hiding and Encapsulation
      1. Access Control
      2. Data Accessor Methods
    6. Abstract Classes and Methods
      1. Reference Type Conversions
    7. Modifier Summary
  7. 4. The Java Type System
    1. Interfaces
      1. Defining an Interface
      2. Extending Interfaces
      3. Implementing an Interface
      4. Implementing Multiple Interfaces
      5. Default Methods
      6. Marker Interfaces
    2. Java Generics
      1. Introduction to Generics
      2. Generic Types and Type Parameters
      3. Diamond Syntax
      4. Type Erasure
      5. Wildcards
      6. Compile and Runtime Typing
    3. Enums and Annotations
      1. Enums
      2. Annotations
      3. Defining Custom Annotations
      4. Type Annotations
    4. Nested Types
      1. Static Member Types
      2. Nonstatic Member Classes
      3. Local Classes
      4. Lexical Scoping and Local Variables
      5. Anonymous Classes
      6. How Nested Types Work
    5. Lambda Expressions
      1. Lambda Expression Conversion
      2. Method References
      3. Functional Programming
    6. Conclusion
  8. 5. Introduction to Object-Oriented Design in Java
    1. Java Values
    2. Important Methods of java.lang.Object
      1. toString()
      2. equals()
      3. hashCode()
      4. Comparable::compareTo()
      5. clone()
    3. Aspects of Object-Oriented Design
      1. Constants
      2. Interfaces Versus Abstract Classes
      3. Instance Methods or Class Methods?
      4. Composition Versus Inheritance
      5. Field Inheritance and Accessors
      6. Singleton
    4. Exceptions and Exception Handling
    5. Safe Java Programming
  9. 6. Java’s Approach to Memory and Concurrency
    1. Basic Concepts of Java Memory Management
      1. Memory Leaks in Java
      2. Introducing Mark and Sweep
      3. The Basic Mark and Sweep Algorithm
    2. How the JVM Optimizes Garbage Collection
      1. Evacuation
    3. The HotSpot Heap
      1. Collecting the Old Generation
      2. Other Collectors
    4. Finalization
      1. Finalization Details
    5. Java’s Support for Concurrency
      1. Thread Lifecycle
      2. Visibility and Mutability
      3. Exclusion and Protecting State
      4. volatile
      5. Useful Methods of Thread
    6. Working with Threads
    7. Summary
  10. II. Working with the Java Platform
  11. 7. Programming and Documentation Conventions
    1. Naming and Capitalization Conventions
    2. Practical Naming
    3. Java Documentation Comments
      1. Structure of a Doc Comment
      2. Doc-Comment Tags
      3. Inline Doc-Comment Tags
      4. Cross-References in Doc Comments
      5. Doc Comments for Packages
    4. Conventions for Portable Programs
  12. 8. Working with Java Collections
    1. Introduction to Collections API
      1. The Collection Interface
      2. The Set Interface
      3. The List Interface
      4. The Map Interface
      5. The Queue and BlockingQueue Interfaces
      6. Adding elements to queues
      7. Removing elements from queues
      8. Querying
      9. Utility Methods
      10. Special-case collections
      11. Arrays and Helper Methods
    2. Lambda Expressions in the Java Collections
      1. Functional Approaches
      2. The Streams API
    3. Conclusion
  13. 9. Handling Common Data Formats
    1. Text
      1. Special Syntax for Strings
      2. String Immutability
      3. Regular Expressions
    2. Numbers and Math
      1. How Java Represents Integer Types
      2. Java and Floating-Point Numbers
      3. Java’s Standard Library of Mathematical Functions
    3. Java 8 Date and Time
      1. Introducing the Java 8 Date and Time API
      2. Queries
      3. Adjusters
      4. Legacy Date and Time
    4. Conclusion
  14. 10. File Handling and I/O
    1. Classic Java I/O
      1. Files
      2. Streams
      3. Readers and Writers
      4. try-with-resources Revisited
      5. Problems with Classic I/O
    2. Modern Java I/O
      1. Files
      2. Path
    3. NIO Channels and Buffers
      1. ByteBuffer
      2. Mapped Byte Buffers
    4. Async I/O
      1. Future-Based Style
      2. Callback-Based Style
      3. Watch Services and Directory Searching
    5. Networking
      1. HTTP
      2. TCP
      3. IP
  15. 11. Classloading, Reflection, and Method Handles
    1. Class Files, Class Objects, and Metadata
      1. Examples of Class Objects
      2. Class Objects and Metadata
    2. Phases of Classloading
      1. Loading
      2. Verification
      3. Preparation and Resolution
      4. Initialization
    3. Secure Programming and Classloading
    4. Applied Classloading
      1. Classloader Hierarchy
    5. Reflection
      1. When to Use Reflection
      2. How to Use Reflection
    6. Dynamic Proxies
    7. Method Handles
      1. MethodType
      2. Method Lookup
      3. Invoking Method Handles
  16. 12. Nashorn
    1. Introduction to Nashorn
      1. Non-Java Languages on the JVM
      2. Motivation
    2. Executing JavaScript with Nashorn
      1. Running from the Command Line
      2. Using the Nashorn Shell
      3. Scripting with jjs
    3. Nashorn and javax.script
      1. Introducing javax.script with Nashorn
    4. Advanced Nashorn
      1. Calling Java from Nashorn
      2. Nashorn’s JavaScript Language Extensions
      3. Under the Hood
    5. Conclusion
      1. Project Avatar
  17. 13. Platform Tools and Profiles
    1. Command-Line Tools
    2. VisualVM
    3. Java 8 Profiles
      1. Motivation
      2. Compact Profiles
    4. Conclusion
  18. Index

Product information

  • Title: Java in a Nutshell, 6th Edition
  • Author(s): Benjamin J Evans, David Flanagan
  • Release date: October 2014
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781449371326