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

OCP Java SE 8 Programmer II Exam Guide (Exam 1Z0-809), 7th Edition

Book Description

A Complete, Integrated Study System for OCP Exam 1Z0-809

Study for the OCP Java SE 8 Programmer II exam using this effective exam preparation guide from Oracle Press. Written by a team of experts, including two developers of the original exam, OCP Java SE 8 Programmer II Exam Guide (Exam 1Z0-809) offers comprehensive coverage of every subject on the test and lays out essential Java programming skills. Throughout, step-by-step exercises; self-tests; and “Exam Watch,” “Inside the Exam,” and “On the Job” sections highlight salient points and aid in learning. In all, the book and accompanying digital content feature more than 350 practice questions that mirror those on the live test in tone, format, and content.

Clearly explains every topic on Exam 1Z0-809, including:
•Declarations, access control, and enums
•Object orientation
•Assertions and exceptions
•Dates, times, locales, and resource bundles
•I/O and NIO
•Generics and collections
•Inner classes
•Lambda expressions and functional interfaces
•Streams
•Threads
•Concurrency
•JDBC

Electronic content includes:
•170 practice exam questions
•Fully customizable test engine
•Secured book PDF

For questions regarding content or to report errata, e-mailhep_customer-service@mheducation.com.

Table of Contents

  1. Cover
  2. Title Page
  3. Copyright Page
  4. Dedication
  5. Contents
  6. Acknowledgments
  7. Preface
  8. Introduction
  9. 1 Declarations, Access Control, and Enums
    1. Java Class Design and Object Orientation: A Refresher
    2. Define Classes and Interfaces (OCP Objectives 1.2, 2.1, and 2.2)
      1. Class Declarations and Modifiers
      2. Exercise 1-1: Creating an Abstract Superclass and Concrete Subclass
    3. Use Interfaces (OCP Objective 2.5)
      1. Declaring an Interface
      2. Declaring Interface Constants
      3. Declaring default Interface Methods
      4. Declaring static Interface Methods
    4. Declare Class Members (OCP Objectives 1.2, 1.6, 2.1, and 2.2)
      1. Access Modifiers
      2. Nonaccess Member Modifiers
      3. Constructor Declarations
      4. Variable Declarations
    5. Declare and Use enums (OCP Objective 2.4)
      1. Declaring enums
    6. Certification Summary
    7. Two-Minute Drill
    8. Q&A Self Test
      1. Self Test Answers
  10. 2 Object Orientation
    1. Encapsulation (OCP Objective 1.1)
    2. Inheritance and Polymorphism (OCP Objectives 1.2 and 1.3)
      1. The Evolution of Inheritance
      2. IS-A and HAS-A Relationships
    3. Polymorphism (OCP Objective 1.3)
    4. Overriding/Overloading (OCP Objectives 1.2, 1.3, and 2.5)
      1. Overridden Methods
      2. Overloaded Methods
    5. Casting (OCP Objectives 1.2 and 1.3)
    6. Implementing an Interface (OCP Objective 2.5)
      1. Java 8—Now with Multiple Inheritance!
    7. Legal Return Types (OCP Objectives 1.2 and 1.3)
      1. Return Type Declarations
      2. Returning a Value
    8. Constructors and Instantiation (OCP Objectives 1.2 and 1.3)
      1. Constructor Basics
      2. Constructor Chaining
      3. Rules for Constructors
      4. Determine Whether a Default Constructor Will Be Created
      5. Overloaded Constructors
    9. Singleton Design Pattern (OCP Objective 1.5)
      1. What Is a Design Pattern?
      2. Problem
      3. Solution
      4. Benefits
    10. Immutable Classes (OCP Objective 1.5)
    11. Initialization Blocks (OCP Objective 1.6)
    12. Statics (OCP Objective 1.6)
      1. Static Variables and Methods
    13. Certification Summary
    14. Two-Minute Drill
    15. Q&A Self Test
      1. Self Test Answers
  11. 3 Assertions and Java Exceptions
    1. Working with the Assertion Mechanism (OCP Objective 6.5)
      1. Assertions Overview
      2. Using Assertions
      3. Using Assertions Appropriately
    2. Working with Exception Handling (OCP Objectives 6.1, 6.2, 6.3, and 6.4)
      1. Use the try Statement with multi-catch and finally Clauses
      2. AutoCloseable Resources with a try-with-resources Statement
    3. Certification Summary
    4. Two-Minute Drill
    5. Q&A Self Test
      1. Self Test Answers
  12. 4 Dates, Times, Locales, and Resource Bundles
    1. Dates, Times, and Locales (OCP Objectives 7.1, 7.2, 7.3, and 12.1)
      1. Working with Dates and Times
      2. The java.time.* Classes for Dates and Times
    2. Properties Files (OCP Objective 12.2)
    3. Resource Bundles (OCP Objectives 12.1, 12.2, and 12.3)
      1. Java Resource Bundles
      2. Default Locale
      3. Choosing the Right Resource Bundle
    4. Certification Summary
    5. Two-Minute Drill
    6. Q&A Self Test
      1. Self Test Answers
  13. 5 I/O and NIO
    1. File Navigation and I/O (OCP Objectives 8.1 and 8.2)
      1. Creating Files Using the File Class
      2. Using FileWriter and FileReader
      3. Using FileInputStream and FileOutputStream
      4. Combining I/O Classes
      5. Working with Files and Directories
      6. The java.io.Console Class
    2. Files, Path, and Paths (OCP Objectives 9.1 and 9.2)
      1. Creating a Path
      2. Creating Files and Directories
      3. Copying, Moving, and Deleting Files
      4. Retrieving Information about a Path
      5. Normalizing a Path
      6. Resolving a Path
      7. Relativizing a Path
    3. File and Directory Attributes (OCP Objective 9.2)
      1. Reading and Writing Attributes the Easy Way
      2. Types of Attribute Interfaces
      3. Working with BasicFileAttributes
      4. Working with DosFileAttributes
      5. Working with PosixFileAttributes
      6. Reviewing Attributes
    4. DirectoryStream (OCP Objectives 9.2 and 9.3)
      1. FileVisitor
      2. PathMatcher
      3. WatchService
    5. Serialization (Objective 8.2)
      1. Working with ObjectOutputStream and ObjectInputStream
      2. Object Graphs
      3. Using writeObject and readObject
      4. How Inheritance Affects Serialization
      5. Serialization Is Not for Statics
    6. Certification Summary
    7. Two-Minute Drill
    8. Q&A Self Test
      1. Self Test Answers
  14. 6 Generics and Collections
    1. Override hashCode(), equals(), and toString() (OCP Objective 1.4)
      1. The toString() Method
      2. Overriding equals()
      3. Overriding hashCode()
    2. Collections Overview (OCP Objective 3.2)
      1. So What Do You Do with a Collection?
      2. Key Interfaces and Classes of the Collections Framework
      3. List Interface
      4. Set Interface
      5. Map Interface
      6. Queue Interface
    3. Using Collections (OCP Objectives 2.6, 3.2, and 3.3)
      1. ArrayList Basics
      2. Autoboxing with Collections
      3. The Java 7 “Diamond” Syntax
      4. Sorting Collections and Arrays
      5. Navigating (Searching) TreeSets and TreeMaps
      6. Other Navigation Methods
      7. Backed Collections
      8. Using the PriorityQueue Class and the Deque Interface
      9. Method Overview for Arrays and Collections
      10. Method Overview for List, Set, Map, and Queue
    4. Generic Types (OCP Objective 3.1)
      1. The Legacy Way to Do Collections
      2. Generics and Legacy Code
      3. Mixing Generic and Nongeneric Collections
      4. Polymorphism and Generics
      5. Generic Methods
      6. Generic Declarations
    5. Certification Summary
    6. Two-Minute Drill
    7. Q&A Self Test
      1. Self Test Answers
  15. 7 Inner Classes
    1. Nested Classes (OCP Objective 2.3)
    2. Inner Classes
      1. Coding a “Regular” Inner Class
      2. Referencing the Inner or Outer Instance from Within the Inner Class
    3. Method-Local Inner Classes
      1. What a Method-Local Inner Object Can and Can’t Do
    4. Anonymous Inner Classes
      1. Plain-Old Anonymous Inner Classes, Flavor One
      2. Plain-Old Anonymous Inner Classes, Flavor Two
      3. Argument-Defined Anonymous Inner Classes
    5. Static Nested Classes
      1. Instantiating and Using Static Nested Classes
    6. Lambda Expressions as Inner Classes (OCP Objective 2.6)
      1. Comparator Is a Functional Interface
    7. Certification Summary
    8. Two-Minute Drill
    9. Q&A Self Test
      1. Self Test Answers
  16. 8 Lambda Expressions and Functional Interfaces
    1. Lambda Expression Syntax (OCP Objective 2.6)
      1. Passing Lambda Expressions to Methods
      2. Accessing Variables from Lambda Expressions
    2. Functional Interfaces (OCP Objectives 3.5, 4.1, 4.2, 4.3, and 4.4)
      1. Built-in Functional Interfaces
      2. What Makes an Interface Functional?
      3. Categories of Functional Interfaces
    3. Method References (OCP Objective 3.8)
      1. Kinds of Method References
    4. Write Your Own Functional Interface
      1. Functional Interface Overview
    5. Certification Summary
    6. Two-Minute Drill
    7. Q&A Self Test
      1. Self Test Answers
  17. 9 Streams
    1. What Is a Stream? (OCP Objective 3.4)
    2. How to Create a Stream (OCP Objectives 3.5 and 9.3)
      1. Create a Stream from a Collection
      2. Build a Stream with Stream.of()
      3. Create a Stream from an Array
      4. Create a Stream from a File
      5. Primitive Value Streams
      6. Summary of Methods to Create Streams
      7. Why Streams?
    3. The Stream Pipeline (OCP Objective 3.6)
      1. Streams Are Lazy
    4. Operating on Streams (OCP Objectives 3.7 and 5.1)
    5. Map-Filter-Reduce with average() and Optionals (OCP Objectives 5.3 and 5.4)
      1. Reduce
      2. Using reduce()
      3. Associative Accumulations
      4. map-filter-reduce Methods
    6. Optionals (OCP Objective 5.3)
    7. Searching and Sorting with Streams (OCP Objectives 5.2 and 5.5)
      1. Searching to See Whether an Element Exists
      2. Searching to Find and Return an Object
      3. Sorting
      4. Methods to Search and Sort Streams
      5. Don’t Modify the Source of a Stream
    8. Collecting Values from Streams (OCP Objectives 3.8, 5.6, and 9.3)
      1. Using collect() with Files.lines()
      2. Exercise 9-1: Collecting Items in a List
      3. Grouping and Partitioning
      4. Summing and Averaging
      5. Counting, joining, maxBy, and minBy
      6. Stream Methods to Collect and Their Collectors
    9. Streams of Streams (OCP Objective 5.7)
    10. Generating Streams (OCP Objective 3.4)
      1. Methods to Generate Streams
      2. Caveat Time Again
    11. A Taste of Parallel Streams
    12. Certification Summary
    13. Two-Minute Drill
    14. Q&A Self Test
      1. Self Test Answers
      2. Exercise Answer
  18. 10 Threads
    1. Defining, Instantiating, and Starting Threads (OCP Objective 10.1)
      1. Making a Thread
      2. Defining a Thread
      3. Instantiating a Thread
      4. Starting a Thread
    2. Thread States and Transitions
      1. Thread States
      2. Preventing Thread Execution
      3. Sleeping
      4. Exercise 10-1: Creating a Thread and Putting It to Sleep
      5. Thread Priorities and yield( )
    3. Synchronizing Code, Thread Problems (OCP Objectives 10.2 and 10.3)
      1. Preventing the Account Overdraw
      2. Synchronization and Locks
      3. Exercise 10-2: Synchronizing a Block of Code
      4. Thread Deadlock
      5. Thread Livelock
      6. Thread Starvation
      7. Race Conditions
    4. Thread Interaction (OCP Objectives 10.2 and 10.3)
      1. Using notifyAll( ) When Many Threads May Be Waiting
    5. Certification Summary
    6. Two-Minute Drill
    7. Q&A Self Test
      1. Self Test Answers
      2. Exercise Answers
  19. 11 Concurrency
    1. Concurrency with the java.util.concurrent Package
    2. Apply Atomic Variables and Locks (OCP Objective 10.3)
      1. Atomic Variables
      2. Locks
    3. Use java.util.concurrent Collections (OCP Objective 10.4)
      1. Copy-on-Write Collections
      2. Concurrent Collections
      3. Blocking Queues
      4. Controlling Threads with CyclicBarrier
    4. Use Executors and ThreadPools (OCP Objective 10.1)
      1. Identifying Parallel Tasks
      2. How Many Threads Can You Run?
      3. CPU-Intensive vs. I/O-Intensive Tasks
      4. Fighting for a Turn
      5. Decoupling Tasks from Threads
    5. Use the Parallel Fork/Join Framework (OCP Objective 10.5)
      1. Divide and Conquer
      2. ForkJoinPool
      3. ForkJoinTask
    6. Parallel Streams (OCP Objective 10.6)
      1. How to Make a Parallel Stream Pipeline
      2. Embarrassingly Parallel, Take Two (with Parallel Streams)
      3. A Parallel Stream Implementation of a RecursiveTask
      4. Reducing Parallel Streams with reduce()
    7. Certification Summary
    8. Two-Minute Drill
    9. Q&A Self Test
      1. Self Test Answers
  20. 12 JDBC
    1. Starting Out: Introduction to Databases and JDBC
      1. Talking to a Database
      2. Bob’s Books, Our Test Database
    2. Core Interfaces of the JDBC API (OCP Objective 11.1)
    3. Connect to a Database Using DriverManager (OCP Objective 11.2)
      1. The DriverManager Class
      2. The JDBC URL
      3. JDBC Driver Implementation Versions
    4. Submit Queries and Read Results from the Database (OCP Objective 11.3)
      1. All of Bob’s Customers
      2. Statements
      3. ResultSets
      4. When Things Go Wrong—Exceptions and Warnings
    5. Certification Summary
    6. Two-Minute Drill
    7. Q&A Self Test
      1. Self Test Answers
  21. A About the Online Content
    1. McGraw-Hill Professional Media Center Download
    2. Total Tester Online System Requirements
    3. Single User License Terms and Conditions
    4. Total Tester Online
    5. Technical Support
  22. Index