Cover image for Java in a Nutshell, 6th Edition

Book description

The sixth edition of Java in a Nutshell helps experienced Java programmers get the most out of Java 7 and 8, but it’s also a learning path for new developers. With examples rewritten to take full advantage of modern Java APIs and development best practices, this fully updated book brings you up to date and gets you ready to develop Java applications for the future.

Table of Contents

  1.  
  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
    9. Foreword
  3. I. Introducing Java
    1. 1. Introduction to the Java Environment
      1. The Language, The JVM & 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 & the JVM
      3. The Lifecycle of a Java Program
        1. Frequently Asked Questions About Java & program lifecycle
          1. What is bytecode?
          2. Is javac a compiler?
          3. Why is it called “bytecode”?
          4. Is Bytecode Optimized?
          5. Is Bytecode
          6. Is Java an interpreted language?
          7. Can other languages run on the JVM?
      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
    2. 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
        2. The
          1. String Literals
        3. Integer Types
        4. Floating-Point Types
        5. Primitive Type Conversions
      4. Expressions and Operators
        1. Operator Summary
          1. Precedence
          2. Associativity
          3. Operator Summary Table
          4. Operand number and type
          5. Return type
          6. Side effects
          7. Order of evaluation
        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
          1. The else if clause
        7. The switch Statement
        8. The while Statement
        9. The do Statement
        10. The for Statement
        11. The foreach Statement
          1. What foreach cannot do
        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
          1. try
          2. catch
          3. finally
        18. The try-with-resources Statement
        19. The assert Statement
          1. Enabling assertions
      6. Methods
        1. Defining Methods
        2. Method Modifiers
        3. Checked and Unchecked Exceptions
          1. Working With Checked Exceptions
        4. Variable-Length Argument Lists
      7. Classes and Objects Introduced
        1. Defining a Class
        2. Creating an Object
        3. Using an Object
        4. Object Literals
          1. String literals
          2. Type literals
          3. The null reference
        5. Lambda Expressions
      8. Arrays
        1. Array Types
          1. Array type widening conversions
          2. C compatibility syntax
        2. Creating and Initializing Arrays
          1. Array initializers
        3. Using Arrays
          1. Accessing array elements
          2. Array bounds
          3. Iterating arrays
          4. Copying arrays
          5. Array utilities
        4. Multidimensional Arrays
      9. Reference Types
        1. Reference vs. 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
          1. Naming conflicts and shadowing
        4. Importing Static Members
          1. Static member imports and overloaded methods
      11. Java File Structure
      12. Defining and Running Java Programs
      13. Summary
    3. 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
      3. Creating and Initializing Objects
        1. Defining a Constructor
        2. Defining Multiple Constructors
        3. Invoking One Constructor from Another
        4. Field Defaults and Initializers
          1. Initializer blocks
      4. Subclasses and Inheritance
        1. Extending a Class
          1. Final classes
        2. Superclasses, Object, and the Class Hierarchy
        3. Subclass Constructors
        4. Constructor Chaining and the Default Constructor
          1. The default constructor
        5. Hiding Superclass Fields
        6. Overriding Superclass Methods
          1. Overriding is not hiding
          2. Virtual method lookup
          3. Invoking an overridden method
      5. Data Hiding and Encapsulation
        1. Access Control
          1. Access to packages
          2. Access to classes
          3. Access to members
          4. Access control and inheritance
          5. Member access summary
        2. Data Accessor Methods
      6. Abstract Classes and Methods
        1. Reference Type Conversions
      7. Modifier Summary
    4. 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
          1. Backwards Compatibility
          2. 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
          1. Bounded Wildcards
          2. Array Covariance
          3. Generic Methods
          4. Using and Designing Generic Types
        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
          1. Features of static member types
        2. Nonstatic Member Classes
          1. Features of member classes
          2. Restrictions on member classes
          3. Syntax for member classes
          4. Scope versus inheritance
        3. Local Classes
          1. Features of local classes
          2. Restrictions on local classes
          3. Scope of a local class
        4. Lexical Scoping and Local Variables
        5. Anonymous Classes
          1. Restrictions on anonymous classes
        6. How Nested Types Work
          1. Nonstatic member class implementation
          2. Local and anonymous class implementation
      5. Lambda Expressions
        1. Lambda Expression Conversion
        2. Functional Programming
      6. Conclusion
    5. 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 vs. Abstract Classes
        3. Instance methods or class methods?
          1. A word about
        4. Composition vs Inheritance
        5. Field inheritance and accessors
        6. Singleton
      4. Exceptions and Exception Handling
      5. Safe Java Programming
    6. 6. Java’s Approach to Memory & Concurrency
      1. Basic Concepts of Java Memory Management
        1. Memory Leaks in Java
        2. Introducing Mark & Sweep
        3. The Basic Mark & Sweep algorithm
      2. How the JVM Optimizes Garbage Collection
        1. Evacuation
      3. The Hotspot Heap
        1. Collecting the old generation
        2. Other Collectors
          1. Concurrent Mark and Sweep
          2. G1
      4. Finalization
        1. Finalization Details
      5. Java’s support for Concurrency
        1. Thread lifecycle
        2. Visibility and Mutability
          1. Concurrent Safety
        3. Exclusion and protecting state
        4. Useful methods of
          1. and
          2. and
          3. Deprecated methods of
          4. ,
      6. Working with threads
      7. Summary
    7. 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
  4. About the Authors
  5. Copyright