Pro Java 8 Programming, Third Edition

Book description

Pro Java 8 Programming covers the core Java development kit and the finer points of the core standard edition (SE) and development kit version 8. You'll discover the particulars of working with the Java language and APIs to develop applications in many different contexts.

You will also delve into more advanced topics like lambda expressions, closures, new i/o (NIO.2), enums, generics, XML, metadata and the Swing APIs for GUI design and development. By the end of the book, you’ll be fully prepared to take advantage of Java's ease of development, and able to create powerful, sophisticated Java applications.

Table of contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Going Inside Java
    1. Java’s Architecture
    2. The Java Virtual Machine
      1. Different JVM Implementations
      2. The JVM As a Runtime Execution Environment
      3. The Runtime Data Areas of the JVM
      4. The Garbage Collector
      5. The JVM: Loading, Linking, and Initializing
      6. Bytecode Execution
    3. The Java Class File Format
    4. The Java Programming Language and APIs
      1. The Java Programming Language
      2. The Java APIs
    5. Java Utility Tools: Making the Most of the JVM
      1. The Java Compiler
      2. The Java Interpreter
      3. The Java Class Disassembler
    6. Summary
  12. Chapter 2: Designing Libraries, Classes, and Methods
    1. Library Design
      1. Package Design
    2. Class Design
      1. Loose Coupling
      2. Strong Cohesion
      3. Encapsulation
      4. Immutable Objects
      5. Overriding Object Methods
    3. Method Design
      1. Passing Parameters
      2. Method Naming
      3. Avoiding Code Duplication
      4. Variable Arguments
      5. Using Exceptions
      6. Assertions
      7. Enumerations
    4. Summary
  13. Chapter 3: Lambdas and Other Java 8 Features
    1. Lambda Expression Concepts
    2. Analyzing the Example
    3. Functional Interface Methods
    4. Default Methods
      1. Multiple Inheritance Ambiguity
    5. Streams
      1. Optional
      2. Parallel Streams
    6. Improved Date/Time Handling In Java 8
      1. Date/Time Support Before Java 8
    7. Date and Time API
      1. Basic Classes
      2. Converting Date and Time Values
      3. Parsing and Formatting
      4. Method Naming Conventions
    8. Summary
  14. Chapter 4: Using Threads in Your Applications
    1. Threading in Java
    2. Creating Threads
    3. Disadvantages of Using Threads
      1. Slow Initial Startup
      2. Resource Utilization
      3. Increased Complexity
      4. Sharing Resources
    4. Thread Management
    5. Understanding the Problem
    6. Synchronizing the Use of Shared Resources
    7. Nested Calls to Synchronized Methods and Code Blocks
    8. Synchronized Blocks vs. Methods
      1. Deadlocks
      2. High-Level Synchronization
      3. Lock Ordering
    9. Thread Priorities
    10. Daemon Threads
    11. Adding Threads to an Application
    12. Controlling Threads
    13. Starting a Thread
    14. Making a Thread “Sleep”
    15. Suspending a Thread
    16. Resuming a Thread
    17. Stopping a Thread
    18. Interrupting a Thread
    19. Completing DownloadManager
    20. Deprecated Methods in Thread
    21. DownloadFiles
    22. ThreadGroup
    23. Uncaught Exceptions
    24. Voluntarily Relinquishing the Processor
    25. Concurrency Utilities
    26. Summary
  15. Chapter 5: Using Stream APIs and Collections
    1. The Evolution of Collections
      1. Java 2/Java 1.2
      2. Java 5/Java 1.5
      3. Java 7/Java 1.7
    2. Collection Classes and Interfaces
      1. Collection
      2. List
      3. ListIterator
      4. ArrayList
      5. LinkedList
      6. Vector
      7. Stack
      8. Set
      9. HashSet
      10. Constructors
      11. LinkedHashSet
      12. TreeSet
      13. EnumSet
      14. Map
      15. HashMap
      16. LinkedHashMap
      17. TreeMap
      18. EnumMap
      19. IdentityHashMap
      20. WeakHashMap
      21. ConcurrentHashMap
      22. CopyOnWriteArrayList and CopyOnWriteArraySet
      23. Queue
      24. PriorityQueue
      25. PriorityBlockingQueue
      26. ArrayBlockingQueue
      27. LinkedBlockingQueue
      28. ConcurrentLinkedQueue
      29. SynchronousQueue
      30. DelayQueue
    3. Tips on Using Collections
      1. Shallow vs. Deep Copies
      2. Referencing an Interface Instead of an Implementation
    4. Streams API
      1. Anatomy of a Stream
      2. Intermediate Operation Pipelining
      3. Some Other Intermediate Operation Methods
      4. Terminal Operations
      5. Parallel Streams
    5. Summary
  16. Chapter 6: Using Layout Managers
    1. Layout Managers and GUI Construction
    2. CardLayout
      1. Constructing a CardLayout
      2. Child Component Sizes
      3. Child Component Locations
      4. Resizing Behavior
      5. Container Size
    3. FlowLayout
      1. Constructing a FlowLayout
      2. Constraints
      3. Child Component Sizes
      4. Child Component Locations
      5. Resizing Behavior
      6. Container Size
    4. GridLayout
      1. Constructing a GridLayout
      2. Constraints
      3. Child Component Sizes
      4. Child Component Locations
      5. Resizing Behavior
      6. Container Size
    5. BorderLayout
      1. Constructing a BorderLayout
      2. Constraints
      3. Child Component Sizes
      4. Child Component Locations
      5. Resizing Behavior
      6. Container Size
    6. GridBagLayout
      1. Constructing a GridBagLayout
      2. Constraints
      3. Child Component Sizes
      4. Child Component Locations
      5. Resizing Behavior
      6. Container Size
    7. BoxLayout
      1. Alignment Values, Ascents, and Descents
      2. Constructing a BoxLayout
      3. Constraints
      4. Child Component Sizes
      5. Child Component Locations
      6. Resizing Behavior
      7. Container Size
      8. Swing’s Box Class
    8. Guidelines for Using Layout Managers
      1. Combining Layout Managers
      2. Absolute Positioning Without a Layout Manager
      3. Invisible Components
      4. Specifying an Index When Adding a Component
    9. Creating Your Own Layout Manager
      1. LayoutManager2 Methods
      2. LayoutManager Methods
      3. Using a Custom Layout Manager
    10. Summary
  17. Chapter 7: Using Swing’s JTable
    1. The Data Model
    2. Using JScrollPane with JTable
    3. JTable’s Column-Oriented Design
    4. Table Resizing
    5. Column Resizing
      1. AUTO_RESIZE_OFF
      2. AUTO_RESIZE_NEXT_COLUMN
      3. AUTO_RESIZE_SUBSEQUENT_COLUMNS
      4. AUTO_RESIZE_LAST_COLUMN
      5. AUTO_RESIZE_ALL_COLUMNS
    6. Cell Rendering
      1. Creating Custom Renderers
      2. JTable’s Default Renderers
    7. Editing Table Cells
      1. Cell Editors
    8. Table Selection Settings
      1. Combining Row, Column, and Cell Selection Modes
      2. List Selection Modes
      3. Selection Mode Combinations
      4. Setting Selections Programmatically
    9. Table Headers
      1. Multiline Column Headers
      2. Adding Table Header Tool Tips
      3. Creating Row Headers
    10. Sorting Table Rows
    11. Adding and Removing Table Rows
    12. Displaying a Particular Table Row
    13. Summary
  18. Chapter 8: Using Swing’s JTree
    1. JTree Terminology
    2. Creating a JTree
      1. TreeModel
      2. Creating Tree Nodes
      3. Nodes Without Children: Leaf or Branch?
      4. MutableTreeNode
      5. DefaultMutableTreeNode
      6. Creating DefaultMutableTreeNode Instances
      7. Using DefaultMutableTreeNode
      8. Obtaining a List of Nodes
    3. TreePath
    4. TreeModelListener
      1. treeNodesChanged()
      2. treeNodesInserted()
      3. treeNodesRemoved()
      4. treeStructureChanged()
    5. TreeModelEvent
      1. getTreePath(), getPath()
      2. getChildren()
      3. getChildIndices()
    6. DefaultTreeModel
    7. Rendering Tree Nodes
      1. Creating a Custom Renderer
    8. Editing Tree Nodes
      1. DefaultTreeCellEditor and DefaultCellEditor
      2. DefaultTreeCellEditor Behavior
      3. Creating a Custom Editor
      4. Limiting Edits to Certain Nodes
    9. Customizing Branch Node Handles
    10. Line Style with the Java/Metal Look and Feel
    11. Node Selection
      1. Selection Modes
      2. TreeSelectionListener
      3. TreeSelectionEvent
      4. getPaths(), getPath()
      5. isAddedPath()
      6. getNewLeadSelectionPath(), getOldLeadSelectionPath()
      7. Selection Methods in JTree
    12. Collapsing and Expanding Nodes
      1. Detecting Collapses and Expansions
      2. TreeExpansionListener
      3. TreeWillExpandListener
    13. Summary
  19. Chapter 9: Adding Cut-and-Paste Functionality
    1. Clipboards: Where Cut and Copied Data Is Stored
      1. Using the System Clipboard
      2. Using Clipboard
      3. Using Transferable
      4. Using ClipboardOwner
      5. Using DataFlavor
    2. Storing and Retrieving Serialized Java Objects
    3. Transferring Between Java and Native Applications
    4. Writing Arbitrary Binary Data
    5. Summary
  20. Chapter 10: Adding Drag-and-Drop Functionality
    1. Introducing Drag-and-Drop Operation Types
    2. Using the Predefined Cursors
    3. Performing File Selection Drops from Native Applications
      1. Adding Drop Support
      2. Adding Drag Support
    4. Performing Local Transfers
    5. Performing Link/Reference Operations
    6. Transferring Between Java and Native Applications
    7. Transferring Text Data
      1. Transferring Text Between Java and Native Applications
      2. Creating a New Transferable for Text Data
    8. Customizing Standard Component Behavior
      1. TransferHandler
    9. Summary
  21. Chapter 11: Printing
    1. Locating Print Services
      1. DocFlavor
      2. Choosing the Right Printer
      3. AttributeSet
      4. Attribute
      5. Attribute Roles
      6. Interfaces and Implementations
      7. Printer Selection via User Interface
    2. Creating a Print Job
    3. Defining the Document to Print
    4. Initiating Printing
    5. Monitoring and Controlling a Print Job
      1. Monitoring Attribute Changes
      2. Canceling a Print Job
    6. Introducing Service-Formatted Printing
      1. Support Classes
      2. Sample Printing Application
    7. Summary
  22. Chapter 12: Introducing JDBC
    1. SQL Standards and JDBC Versions
    2. JDBC Drivers
      1. Driver Types
    3. Obtaining a Database Connection
      1. JDBC URL Formats
      2. Connection
      3. Obtaining Connections from a DataSource (2.x Optional Package)
      4. DatabaseMetaData
      5. Statement
      6. ParameterMetaData
    4. JDBC Data Types
      1. ARRAY
      2. BLOB, CLOB
      3. DATALINK
      4. DATE, TIME, TIMESTAMP
      5. DISTINCT
      6. STRUCT
      7. REF
      8. JAVA_OBJECT
      9. OTHER
    5. ResultSet
      1. Forward-Only vs. Scrollable (Scrollability Type)
      2. Read-Only vs. Updatable (Concurrency Mode)
      3. Update Sensitivity
      4. Holdability
      5. Selecting ResultSet Properties
      6. Performance Hints
      7. Using ResultSet
    6. ResultSetMetaData
    7. RowSet
      1. JdbcRowSet
      2. CachedRowSet
    8. Transactions
      1. Savepoints
      2. Read-Only Transactions
    9. Connection Pooling
      1. Pooling Properties
    10. Errors and Warnings
      1. SQLException
      2. SQLWarning
    11. Debugging
    12. Releasing Resources
    13. Summary
  23. Chapter 13: Internationalizing Your Applications
    1. Locales
    2. Resource Bundles
      1. Creating a ResourceBundle
    3. Locale-Sensitive Formatting and Parsing
      1. Formatting and Parsing Dates
      2. Formatting and Parsing Times
      3. Formatting and Parsing Numeric Values
    4. MessageFormat
      1. Specifying a Locale
      2. Specifying a Format Object
    5. ChoiceFormat
    6. Using Formatter and String’s format() Method
    7. Parsing Text Data
      1. BreakIterator
    8. Text Comparisons and Sorting
      1. Collator Strength
      2. Decomposition Mode
    9. Internationalizing an Application
    10. Changing the Locale at Runtime
    11. native2ascii
    12. Summary
  24. Chapter 14: Using XML
    1. XML vs. HTML
      1. Describing the Data
      2. Well-Formed Documents
    2. When and Why to Use XML
    3. Creating an XML Document
      1. Root Elements
      2. Components of an XML Document
    4. Parsing and Validation
      1. Parsing with the DOM Implementation in JAXP
      2. Text
      3. EntityReference
      4. DocumentFragment
      5. DocumentType
      6. Notation
    5. Traversing a Document with DOM
    6. Editing Documents with DOM
      1. Creating and Adding New Nodes
      2. Creating a New Document
    7. Transforming XML Documents
    8. Performing an XSL Transformation
      1. Introducing XPath
      2. Creating and Using Additional Templates
    9. Summary
  25. Chapter 15: Adding Annotations
    1. Using Annotations
      1. Override
      2. FunctionalInterface
      3. SuppressWarnings
    2. Creating Custom Annotations
      1. Target
      2. Retention
      3. Documented
      4. Inherited
      5. Repeatable
    3. Replacing External Metadata
    4. Summary
  26. Index

Product information

  • Title: Pro Java 8 Programming, Third Edition
  • Author(s): Brett Spell
  • Release date: May 2015
  • Publisher(s): Apress
  • ISBN: 9781484206416