Core Java, Volume II—Advanced Features, Tenth Edition

Book description

Core Java® has long been recognized as the leading, no-nonsense tutorial and reference for experienced programmers who want to write robust Java code for real-world applications. Now, Core Java®, Volume II—Advanced Features, Tenth Edition, has been extensively updated to reflect the most eagerly awaited and innovative version of Java in years: Java SE 8. Rewritten and reorganized to illuminate powerful new Java features, idioms, and best practices for enterprise and desktop development, it contains hundreds of up-to-date example programs—all carefully crafted for easy understanding and practical applicability.

Writing for serious programmers solving real-world problems, Cay Horstmann deepens your understanding of today’s Java language and library. In this second of two updated volumes, he offers in-depth coverage of advanced topics including the new Streams API and date/time/calendar library, advanced Swing, security, code processing, and more. This guide will help you

  • Use the new Streams library to process collections more flexibly and efficiently

  • Efficiently access files and directories, read/write binary or text data, and serialize objects

  • Work with Java SE 8’s regular expression package

  • Make the most of XML in Java: parsing, validation, XPath, document generation, XSL, and more

  • Efficiently connect Java programs to network services

  • Program databases with JDBC 4.2

  • Elegantly overcome date/time programming complexities with the new java.time API

  • Write internationalized programs with localized dates/times, numbers, text, and GUIs

  • Process code with the scripting API, compiler API, and annotation processors

  • Enforce security via class loaders, bytecode verification, security managers, permissions, user authentication, digital signatures, code signing, and encryption

  • Master advanced Swing components for lists, tables, trees, text, and progress indicators

  • Produce high-quality drawings with the Java 2D API

  • Use JNI native methods to leverage code in other languages

  • If you’re an experienced programmer moving to Java SE 8, Core Java®, Tenth Edition, is the reliable, practical, and complete guide to the Java platform that has been trusted by developers for over twenty years.

    Look for the companion volume, Core Java®, Volume I—Fundamentals, Tenth Edition (ISBN-13: 978-0-13-417730-4), for foundational coverage of Java 8 language concepts, UI programming, objects, generics, collections, lambda expressions, concurrency, functional programming, and more.

    Table of contents

    1. About This E-Book
    2. Title Page
    3. Copyright Page
    4. Contents
    5. Preface
    6. Acknowledgments
    7. Chapter 1: The Java SE 8 Stream Library
      1. 1.1 From Iterating to Stream Operations
      2. 1.2 Stream Creation
      3. 1.3 The filter, map, and flatMap Methods
      4. 1.4 Extracting Substreams and Concatenating Streams
      5. 1.5 Other Stream Transformations
      6. 1.6 Simple Reductions
      7. 1.7 The Optional Type
        1. 1.7.1 How to Work with Optional Values
        2. 1.7.2 How Not to Work with Optional Values
        3. 1.7.3 Creating Optional Values
        4. 1.7.4 Composing Optional Value Functions with flatMap
      8. 1.8 Collecting Results
      9. 1.9 Collecting into Maps
      10. 1.10 Grouping and Partitioning
      11. 1.11 Downstream Collectors
      12. 1.12 Reduction Operations
      13. 1.13 Primitive Type Streams
      14. 1.14 Parallel Streams
    8. Chapter 2: Input and Output
      1. 2.1 Input/Output Streams
        1. 2.1.1 Reading and Writing Bytes
        2. 2.1.2 The Complete Stream Zoo
        3. 2.1.3 Combining Input/Output Stream Filters
      2. 2.2 Text Input and Output
        1. 2.2.1 How to Write Text Output
        2. 2.2.2 How to Read Text Input
        3. 2.2.3 Saving Objects in Text Format
        4. 2.2.4 Character Encodings
      3. 2.3 Reading and Writing Binary Data
        1. 2.3.1 The DataInput and DataOutput interfaces
        2. 2.3.2 Random-Access Files
        3. 2.3.3 ZIP Archives
      4. 2.4 Object Input/Output Streams and Serialization
        1. 2.4.1 Saving and Loading Serializable Objects
        2. 2.4.2 Understanding the Object Serialization File Format
        3. 2.4.3 Modifying the Default Serialization Mechanism
        4. 2.4.4 Serializing Singletons and Typesafe Enumerations
        5. 2.4.5 Versioning
        6. 2.4.6 Using Serialization for Cloning
      5. 2.5 Working with Files
        1. 2.5.1 Paths
        2. 2.5.2 Reading and Writing Files
        3. 2.5.3 Creating Files and Directories
        4. 2.5.4 Copying, Moving, and Deleting Files
        5. 2.5.5 Getting File Information
        6. 2.5.6 Visiting Directory Entries
        7. 2.5.7 Using Directory Streams
        8. 2.5.8 ZIP File Systems
      6. 2.6 Memory-Mapped Files
        1. 2.6.1 Memory-Mapped File Performance
        2. 2.6.2 The Buffer Data Structure
        3. 2.6.3 File Locking
      7. 2.7 Regular Expressions
    9. Chapter 3: XML
      1. 3.1 Introducing XML
        1. 3.1.1 The Structure of an XML Document
      2. 3.2 Parsing an XML Document
      3. 3.3 Validating XML Documents
        1. 3.3.1 Document Type Definitions
        2. 3.3.2 XML Schema
        3. 3.3.3 A Practical Example
      4. 3.4 Locating Information with XPath
      5. 3.5 Using Namespaces
      6. 3.6 Streaming Parsers
        1. 3.6.1 Using the SAX Parser
        2. 3.6.2 Using the StAX Parser
      7. 3.7 Generating XML Documents
        1. 3.7.1 Documents without Namespaces
        2. 3.7.2 Documents with Namespaces
        3. 3.7.3 Writing Documents
        4. 3.7.4 An Example: Generating an SVG File
        5. 3.7.5 Writing an XML Document with StAX
      8. 3.8 XSL Transformations
    10. Chapter 4: Networking
      1. 4.1 Connecting to a Server
        1. 4.1.1 Using Telnet
        2. 4.1.2 Connecting to a Server with Java
        3. 4.1.3 Socket Timeouts
        4. 4.1.4 Internet Addresses
      2. 4.2 Implementing Servers
        1. 4.2.1 Server Sockets
        2. 4.2.2 Serving Multiple Clients
        3. 4.2.3 Half-Close
      3. 4.3 Interruptible Sockets
      4. 4.4 Getting Web Data
        1. 4.4.1 URLs and URIs
        2. 4.4.2 Using a URLConnection to Retrieve Information
        3. 4.4.3 Posting Form Data
      5. 4.5 Sending E-Mail
    11. Chapter 5: Database Programming
      1. 5.1 The Design of JDBC
        1. 5.1.1 JDBC Driver Types
        2. 5.1.2 Typical Uses of JDBC
      2. 5.2 The Structured Query Language
      3. 5.3 JDBC Configuration
        1. 5.3.1 Database URLs
        2. 5.3.2 Driver JAR Files
        3. 5.3.3 Starting the Database
        4. 5.3.4 Registering the Driver Class
        5. 5.3.5 Connecting to the Database
      4. 5.4 Working with JDBC Statements
        1. 5.4.1 Executing SQL Statements
        2. 5.4.2 Managing Connections, Statements, and Result Sets
        3. 5.4.3 Analyzing SQL Exceptions
        4. 5.4.4 Populating a Database
      5. 5.5 Query Execution
        1. 5.5.1 Prepared Statements
        2. 5.5.2 Reading and Writing LOBs
        3. 5.5.3 SQL Escapes
        4. 5.5.4 Multiple Results
        5. 5.5.5 Retrieving Autogenerated Keys
      6. 5.6 Scrollable and Updatable Result Sets
        1. 5.6.1 Scrollable Result Sets
        2. 5.6.2 Updatable Result Sets
      7. 5.7 Row Sets
        1. 5.7.1 Constructing Row Sets
        2. 5.7.2 Cached Row Sets
      8. 5.8 Metadata
      9. 5.9 Transactions
        1. 5.9.1 Programming Transactions with JDBC
        2. 5.9.2 Save Points
        3. 5.9.3 Batch Updates
      10. 5.10 Advanced SQL Types
      11. 5.11 Connection Management in Web and Enterprise Applications
    12. Chapter 6: The Date and Time API
      1. 6.1 The Time Line
      2. 6.2 Local Dates
      3. 6.3 Date Adjusters
      4. 6.4 Local Time
      5. 6.5 Zoned Time
      6. 6.6 Formatting and Parsing
      7. 6.7 Interoperating with Legacy Code
    13. Chapter 7: Internationalization
      1. 7.1 Locales
      2. 7.2 Number Formats
      3. 7.3 Currencies
      4. 7.4 Date and Time
      5. 7.5 Collation and Normalization
      6. 7.6 Message Formatting
        1. 7.6.1 Formatting Numbers and Dates
        2. 7.6.2 Choice Formats
      7. 7.7 Text Input and Output
        1. 7.7.1 Text Files
        2. 7.7.2 Line Endings
        3. 7.7.3 The Console
        4. 7.7.4 Log Files
        5. 7.7.5 The UTF-8 Byte Order Mark
        6. 7.7.6 Character Encoding of Source Files
      8. 7.8 Resource Bundles
        1. 7.8.1 Locating Resource Bundles
        2. 7.8.2 Property Files
        3. 7.8.3 Bundle Classes
      9. 7.9 A Complete Example
    14. Chapter 8: Scripting, Compiling, and Annotation Processing
      1. 8.1 Scripting for the Java Platform
        1. 8.1.1 Getting a Scripting Engine
        2. 8.1.2 Script Evaluation and Bindings
        3. 8.1.3 Redirecting Input and Output
        4. 8.1.4 Calling Scripting Functions and Methods
        5. 8.1.5 Compiling a Script
        6. 8.1.6 An Example: Scripting GUI Events
      2. 8.2 The Compiler API
        1. 8.2.1 Compiling the Easy Way
        2. 8.2.2 Using Compilation Tasks
        3. 8.2.3 An Example: Dynamic Java Code Generation
      3. 8.3 Using Annotations
        1. 8.3.1 An Introduction into Annotations
        2. 8.3.2 An Example: Annotating Event Handlers
      4. 8.4 Annotation Syntax
        1. 8.4.1 Annotation Interfaces
        2. 8.4.2 Annotations
        3. 8.4.3 Annotating Declarations
        4. 8.4.4 Annotating Type Uses
        5. 8.4.5 Annotating this
      5. 8.5 Standard Annotations
        1. 8.5.1 Annotations for Compilation
        2. 8.5.2 Annotations for Managing Resources
        3. 8.5.3 Meta-Annotations
      6. 8.6 Source-Level Annotation Processing
        1. 8.6.1 Annotation Processors
        2. 8.6.2 The Language Model API
        3. 8.6.3 Using Annotations to Generate Source Code
      7. 8.7 Bytecode Engineering
        1. 8.7.1 Modifying Class Files
        2. 8.7.2 Modifying Bytecodes at Load Time
    15. Chapter 9: Security
      1. 9.1 Class Loaders
        1. 9.1.1 The Class Loading Process
        2. 9.1.2 The Class Loader Hierarchy
        3. 9.1.3 Using Class Loaders as Namespaces
        4. 9.1.4 Writing Your Own Class Loader
        5. 9.1.5 Bytecode Verification
      2. 9.2 Security Managers and Permissions
        1. 9.2.1 Permission Checking
        2. 9.2.2 Java Platform Security
        3. 9.2.3 Security Policy Files
        4. 9.2.4 Custom Permissions
        5. 9.2.5 Implementation of a Permission Class
      3. 9.3 User Authentication
        1. 9.3.1 The JAAS Framework
        2. 9.3.2 JAAS Login Modules
      4. 9.4 Digital Signatures
        1. 9.4.1 Message Digests
        2. 9.4.2 Message Signing
        3. 9.4.3 Verifying a Signature
        4. 9.4.4 The Authentication Problem
        5. 9.4.5 Certificate Signing
        6. 9.4.6 Certificate Requests
        7. 9.4.7 Code Signing
      5. 9.5 Encryption
        1. 9.5.1 Symmetric Ciphers
        2. 9.5.2 Key Generation
        3. 9.5.3 Cipher Streams
        4. 9.5.4 Public Key Ciphers
    16. Chapter 10: Advanced Swing
      1. 10.1 Lists
        1. 10.1.1 The JList Component
        2. 10.1.2 List Models
        3. 10.1.3 Inserting and Removing Values
        4. 10.1.4 Rendering Values
      2. 10.2 Tables
        1. 10.2.1 A Simple Table
        2. 10.2.2 Table Models
        3. 10.2.3 Working with Rows and Columns
          1. 10.2.3.1 Column Classes
          2. 10.2.3.2 Accessing Table Columns
          3. 10.2.3.3 Resizing Columns
          4. 10.2.3.4 Resizing Rows
          5. 10.2.3.5 Selecting Rows, Columns, and Cells
          6. 10.2.3.6 Sorting Rows
          7. 10.2.3.7 Filtering Rows
          8. 10.2.3.8 Hiding and Displaying Columns
        4. 10.2.4 Cell Rendering and Editing
          1. 10.2.4.1 Rendering Cells
          2. 10.2.4.2 Rendering the Header
          3. 10.2.4.3 Editing Cells
          4. 10.2.4.4 Custom Editors
      3. 10.3 Trees
        1. 10.3.1 Simple Trees
        2. 10.3.2 Editing Trees and Tree Paths
        3. 10.3.3 Node Enumeration
        4. 10.3.4 Rendering Nodes
        5. 10.3.5 Listening to Tree Events
        6. 10.3.6 Custom Tree Models
      4. 10.4 Text Components
        1. 10.4.1 Change Tracking in Text Components
        2. 10.4.2 Formatted Input Fields
          1. 10.4.2.1 Integer Input
          2. 10.4.2.2 Behavior on Loss of Focus
          3. 10.4.2.3 Filters
          4. 10.4.2.4 Verifiers
          5. 10.4.2.5 Other Standard Formatters
          6. 10.4.2.6 Custom Formatters
        3. 10.4.3 The JSpinner Component
        4. 10.4.4 Displaying HTML with the JEditorPane
      5. 10.5 Progress Indicators
        1. 10.5.1 Progress Bars
        2. 10.5.2 Progress Monitors
        3. 10.5.3 Monitoring the Progress of Input Streams
      6. 10.6 Component Organizers and Decorators
        1. 10.6.1 Split Panes
        2. 10.6.2 Tabbed Panes
        3. 10.6.3 Desktop Panes and Internal Frames
          1. 10.6.3.1 Displaying Internal Frames
          2. 10.6.3.2 Cascading and Tiling
          3. 10.6.3.3 Vetoing Property Settings
          4. 10.6.3.4 Dialogs in Internal Frames
          5. 10.6.3.5 Outline Dragging
        4. 10.6.4 Layers
    17. Chapter 11: Advanced AWT
      1. 11.1 The Rendering Pipeline
      2. 11.2 Shapes
        1. 11.2.1 The Shape Class Hierarchy
        2. 11.2.2 Using the Shape Classes
      3. 11.3 Areas
      4. 11.4 Strokes
      5. 11.5 Paint
      6. 11.6 Coordinate Transformations
      7. 11.7 Clipping
      8. 11.8 Transparency and Composition
      9. 11.9 Rendering Hints
      10. 11.10 Readers and Writers for Images
        1. 11.10.1 Obtaining Readers and Writers for Image File Types
        2. 11.10.2 Reading and Writing Files with Multiple Images
      11. 11.11 Image Manipulation
        1. 11.11.1 Constructing Raster Images
        2. 11.11.2 Filtering Images
      12. 11.12 Printing
        1. 11.12.1 Graphics Printing
        2. 11.12.2 Multiple-Page Printing
        3. 11.12.3 Print Preview
        4. 11.12.4 Print Services
        5. 11.12.5 Stream Print Services
        6. 11.12.6 Printing Attributes
      13. 11.13 The Clipboard
        1. 11.13.1 Classes and Interfaces for Data Transfer
        2. 11.13.2 Transferring Text
        3. 11.13.3 The Transferable Interface and Data Flavors
        4. 11.13.4 Building an Image Transferable
        5. 11.13.5 Transferring Java Objects via the System Clipboard
        6. 11.13.6 Using a Local Clipboard to Transfer Object References
      14. 11.14 Drag and Drop
        1. 11.14.1 Data Transfer Support in Swing
        2. 11.14.2 Drag Sources
        3. 11.14.3 Drop Targets
      15. 11.15 Platform Integration
        1. 11.15.1 Splash Screens
        2. 11.15.2 Launching Desktop Applications
        3. 11.15.3 The System Tray
    18. Chapter 12: Native Methods
      1. 12.1 Calling a C Function from a Java Program
      2. 12.2 Numeric Parameters and Return Values
      3. 12.3 String Parameters
      4. 12.4 Accessing Fields
        1. 12.4.1 Accessing Instance Fields
        2. 12.4.2 Accessing Static Fields
      5. 12.5 Encoding Signatures
      6. 12.6 Calling Java Methods
        1. 12.6.1 Instance Methods
        2. 12.6.2 Static Methods
        3. 12.6.3 Constructors
        4. 12.6.4 Alternative Method Invocations
      7. 12.7 Accessing Array Elements
      8. 12.8 Handling Errors
      9. 12.9 Using the Invocation API
      10. 12.10 A Complete Example: Accessing the Windows Registry
        1. 12.10.1 Overview of the Windows Registry
        2. 12.10.2 A Java Platform Interface for Accessing the Registry
        3. 12.10.3 Implementation of Registry Access Functions as Native Methods
    19. Index
    20. Code Snippets

    Product information

    • Title: Core Java, Volume II—Advanced Features, Tenth Edition
    • Author(s): Cay S. Horstmann
    • Release date: December 2016
    • Publisher(s): Pearson
    • ISBN: 9780134177878