OCP Java SE 7 Programmer II Certification Guide
Prepare for the 1ZO-804 exam
Mala Gupta
  • August 2015
  • ISBN 9781617291487
  • 832 pages
  • printed in black & white

A good read for all who want to deepen their Java knowledge, even if not preparing for the exam.

Simon Joseph Aquilina, KPMG Crimsonwing

PRODUCT ALERT: ePub + kindle formats coming September 11, 2015

OCP Java SE 7 Programmer II Certification Guide is a concise, focused study guide that prepares you to pass the OCP Java SE 7 Programmer II exam (1Z0-804) the first time you take it. The book systematically guides you through each exam objective, teaching and reinforcing the Java skills you need through examples, exercises, and cleverly constructed visual aids. In every chapter, you'll find questions just like the ones you'll face in the real exam. Exam tips, diagrams, and review notes structure the learning process for easy retention.

Table of Contents show full

preface

acknowledgments

about this book

about the author

about the cover illustration

Introduction

Disclaimer

Introduction to OCP Java SE 7 Programmer II certification (1Z0-804)

The importance of the OCP Java SE 7 Programmer II certification

Comparing the OCA Java SE 7 Programmer I (1Z0-803) and OCP Java SE 7 Programmer II (1Z0-804) exams

Complete exam objectives, mapped to book chapters, and readiness checklist

FAQ

FAQ on exam preparation

FAQ on taking the exam

The testing engine used in the exam

1. Java class design

1.1. Java access modifiers

1.1.1. Public access modifier

1.1.2. Protected access modifier

1.1.3. Default access (package access)

1.1.4. The private access modifier

1.1.5. Access modifiers and Java entities

1.1.6. Effects of changing access modifiers for existing entities

1.2. Overloaded methods and constructors

1.2.1. Argument list

1.2.2. When methods can’t be defined as overloaded methods

1.2.3. Overloaded constructors

1.3. Method overriding and virtual method invocation

1.3.1. Need of overridden methods

1.3.2. Correct syntax of overriding methods

1.3.3. Can you override all methods from the base class or invoke them virtually?

1.3.4. Identifying method overriding, overloading, and hiding

1.3.5. Can you override base class constructors or invoke them virtually?

1.4. Overriding methods of class Object

1.4.1. Overriding method toString()

1.4.2. Overriding method equals()

1.4.3. Overriding method hashCode()

1.5. Casting and the instanceof operator

1.5.1. Implicit and explicit casting

1.5.2. Combinations of casting

1.5.3. Using the instanceof operator

1.6. Packages

1.6.1. The need for packages

1.6.2. Defining classes in a package using the package statement

1.6.3. Using simple names with import statements

1.6.4. Using packages without using the import statement

1.6.5. Importing a single member versus all members of a package

1.6.6. The import statement doesn’t import the whole package tree

1.6.7. Importing classes from the default packag

1.6.8. Static imports

1.7. Summary

1.8. Review notes

1.8.1. Java access modifiers

1.8.2. Overloaded methods and constructors

1.8.3. Method overriding and virtual method invocation

1.8.4. Java packages

1.9. Sameple exam questions

1.10. Answers to sample exam questions

2. Advanced Class Design

2.1. Abstract classes and their application

2.1.1. Identify abstract classes

2.1.2. Construct abstract classes and subclasses

2.1.3. Understand the need for abstract classes

2.1.4. Follow the dos and don’ts of creating and using abstract classes

2.1.5. Compare abstract classes and concrete classes

2.2. Static and final keywords

2.2.1. Static modifier

2.2.2. Nonaccess modifier-final

2.3. Enumerated types

2.3.1. Understanding the need for and creating an enum

2.3.2. Adding implicit code to an enum

2.3.3. Extending java.lang.Enum

2.3.4. Adding variables, constructors, and methods to your enum

2.3.5. Where can you define an enum?

2.4. Static nested and inner classes

2.4.1. Advantages of inner classes

2.4.2. Static nested class (also called static inner class)

2.4.3. Inner class (also called member class)

2.4.4. Anonymous inner classes

2.4.5. Method local inner classes

2.4.6. Disadvantages of inner classes

2.5. Summary

2.6. Review notes

2.6.1. Abstract classes

2.6.2. Nonaccess modifier-static

2.6.3. Nonaccess modifier-final

2.6.4. Enumerated types

2.6.5. Static nested classes

2.6.6. Inner classes

2.6.7. Anonymous inner classes

2.6.8. Method local inner classes

2.7. Sample exam questions

2.8. Answers to sample exam questions

3. Object-oriented design principles

3.1. Interfaces

3.1.1. Understanding interfaces

3.1.2. Declaring interfaces

3.1.3. Implementing interfaces

3.1.4. Extending interfaces

3.2. Class inheritance versus interface inheritance

3.2.1. Comparing class inheritance and interface inheritance

3.2.2. Preferring class inheritance over interface inheritance

3.2.3. Preferring interface inheritance over class inheritance

3.3. IS-A and HAS-A relationships in code

3.3.1. Identifying and implementing an IS-A relationship

3.3.2. Identifying and implementing a HAS-A relationship

3.4. Cohesion and low coupling

3.4.1. Cohesion

3.4.2. Coupling

3.5. Object composition principles

3.6. Introduction to design patterns

3.6.1. What is a design pattern?

3.6.2. Why do you need a design pattern?

3.7. Singleton pattern

3.7.1. Why do you need this pattern?

3.7.2. Implementing the Singleton pattern

3.7.3. Ensuring creation of only one object in the Singleton pattern

3.7.4. Comparing Singleton with global data

3.8. Factory pattern

3.8.1. Simple Factory pattern (or Static Factory pattern)

3.8.2. Factory Method pattern

3.8.3. Abstract Factory pattern

3.8.4. Benefits of the Factory pattern

3.8.5. Using the Factory pattern from the Java API

3.9. DAO pattern

3.9.1. What is the DAO pattern?

3.9.2. Implementing the DAO pattern

3.9.3. Using the Simple Factory pattern with the DAO pattern

3.9.4. Using the Factory Method or Abstract Factory pattern with the DAO pattern

3.9.5. Benefits of the DAO pattern

3.10. Summary

3.11. Review notes

3.11.1. Interfaces

3.11.2. Class inheritance versus interface inheritance

3.11.3. S-A and HAS-A relationships in code

3.11.4. Cohesion and low coupling

3.11.5. Object composition principles

3.11.6. Singleton pattern

3.11.7. Factory pattern

3.11.8. DAO pattern

3.12. Sample exam questions

3.13. Answers to sample exam questions

4. Generics and Collections

4.1. Introducing generics: WARM-UP

4.1.1. Need for introducing generics

4.1.2. Benefits and complexities of using generics

4.2. Creating generic entities

4.2.1. Creating a generic class

4.2.2. Working with generic interfaces

4.2.3. Using generic methods

4.2.4. Bounded type parameters

4.2.5. Using wildcards

4.2.6. Using bounded wildcards

4.2.7. Type erasure

4.2.8. Refreshing the commonly used terms

4.3. Using type inference

4.3.1. Using type inference to instantiate a generic class

4.3.2. Using type inference to invoke generic methods

4.4. Understanding interoperability of collections using raw types and generic types

4.4.1. Mixing reference variables and objects of raw and generic types

4.4.2. Subtyping with generics

4.5. Introducing the collections framework: WARM-UP

4.6. Working with the Collection interface

4.6.1. The core Collection interface

4.6.2. Methods of the Collection interface

4.7. Creating and using List, Set, and Deque implementations

4.7.1. List interface and its implementations

4.7.2. Deque interface and its implementations

4.7.3. Set interface and its implementations

4.7.4. Set implementation classes

4.8. Map and its implementations

4.8.1. Map interface

4.8.2. HashMap

4.8.3. LinkedHashMap

4.8.4. TreeMap

4.9. Using java.util.Comparator and java.lang.Comparable

4.9.1. Comparable interface

4.9.2. Comparator interface

4.10. Sorting and searching arrays and lists

4.10.1. Sorting arrays

4.10.2. Sorting List using Collections

4.10.3. Searching arrays and List using collections

4.11. Using wrapper classes

4.11.1. Class hierarchy of wrapper classes

4.11.2. Creating objects of the wrapper classes

4.11.3. Retrieving primitive values from the wrapper classes

4.11.4. Parsing a string value to a primitive type

4.11.5. Difference between using method valueOf() and constructors of wrapper classes

4.11.6. Comparing objects of wrapper classes

4.12. Autoboxing and unboxing

4.13. Summary

4.14. Review notes

4.14.1. Creating generic entities

4.14.2. Using type inference

4.14.3. Understanding interoperability of collections using raw types and generic types

4.14.4. Working with the Collection interface

4.14.5. Creating and using List, Set, and Deque implementations

4.14.6. Map and its implementations

4.14.7. Using java.util.Comparator and java.lang.Comparable

4.14.8. Sorting and searching arrays and lists

4.14.9. Using wrapper classes

4.14.10. Autoboxing and Unboxing

4.15. Sample exam questions

4.16. Answers to sample exam questions

5. String Processing

5.1. Regular expressions

5.1.1. What is a regular expression?

5.1.2. Character classes

5.1.3. Predefined character classes

5.1.4. Matching boundaries

5.1.5. Quantifiers

5.1.6. Java’s regex support

5.2. Searching, parsing, and building strings

5.2.1. Searching strings

5.2.2. Replacing strings

5.2.3. Parsing and tokenizing strings with Scanner and StringTokenizer

5.3. Formatting strings

5.3.1. Formatting classes

5.3.2. Formatting methods

5.3.3. Defining format strings

5.3.4. Formatting parameter %b

5.3.5. Formatting parameter %c

5.3.6. Formatting parameters %d and %f

5.3.7. Formatting parameter %s

5.4. Summary

5.5. Review notes

5.5.1. Regular expressions

5.5.2. Search, parse, and build strings

5.5.3. Formatting strings

5.6. Sample exam questions

5.7. Answers to sample exam questions

6. Exceptions and Assertions

6.1. Using the throw statement and the throws clause

6.1.1. Creating a method that throws a checked exception

6.1.2. Using a method that throws a checked exception

6.1.3. Creating and using a method that throws runtime exceptions or errors

6.1.4. Points to note while using the throw statement and the throws clause

6.2. Creating custom exceptions

6.2.1. Creating a custom checked exception

6.2.2. Creating a custom unchecked exception

6.3. Overriding methods that throw exceptions

6.4. Using the try statement with multi-catch and finally clauses

6.4.1. Comparing single-catch handlers and multi-catch handlers

6.4.2. Handling multiple exceptions in the same exception handler

6.5. Auto-closing resources with a try-with-resources statement

6.5.1. How to use a try-with-resources statement

6.5.2. Suppressed exceptions

6.5.3. The right ingredients

6.6. Using assertions

6.6.1. Exploring the forms of assertions

6.6.2. Testing invariants in your code

6.6.3. Understanding appropriate and inappropriate uses of assertions

6.7. Summary

6.8. Review notes

6.8.1. Using the throw statement and the throws clause

6.8.2. Custom exceptions

6.8.3. Overriding methods that throw exceptions

6.8.4. Try statement with multi-catch and finally clauses

6.8.5. Auto-close resources with try-with-resources statement

6.8.6. Assertions

6.9. Sample exam questions

6.10. Answers to sample exam questions

7. Java I/O Fundamentals

7.1. Introducing Java I/O: WARM-UP

7.1.1. Understanding streams

7.1.2. Understanding multiple flavors of data

7.2. Working with class java.io.File

7.2.1. Instantiating and querying File instances

7.2.2. Creating new files and directories on your physical device

7.3. Using byte stream I/O

7.3.1. Input streams

7.3.2. Output streams

7.3.3. File I/O with byte streams

7.3.4. Buffered I/O with byte streams

7.3.5. Primitive values and strings I/O with byte streams

7.3.6. Object I/O with byte streams: reading and writing objects

7.4. Using character I/O with readers and writers

7.4.1. Abstract class java.io.Reader

7.4.2. Abstract class java.io.Writer

7.4.3. File I/O with character streams

7.4.4. Buffered I/O with character streams

7.4.5. Data streams with character streams: using PrintWriter to write to a file

7.4.6. Constructor chaining with I/O classes

7.5. Working with the console

7.6. Summary

7.7. Review notes

7.7.1. Working with class java.io.File

7.7.2. Using byte stream I/O

7.7.3. Using character I/O with readers and writers

7.7.4. Working with the console

7.8. Sample exam questions

7.9. Answers to sample exam questions

8. Java File I/O (NIO.2)

8.1. Path objects

8.1.1. Multiple ways to create Path objects

8.1.2. Methods to access Path components

8.1.3. Comparing paths

8.1.4. Converting relative paths to absolute paths

8.1.5. Resolving paths using methods resolve and resolveSibling

8.1.6. Method relativize()

8.2. Class Files

8.2.1. Create files and directories

8.2.2. Check for the existence of files and directories

8.2.3. Copy files

8.2.4. Move files and directories

8.2.5. Delete files and directories

8.2.6. Commonly thrown exceptions

8.3. Files and directory attributes

8.3.1. Individual attributes

8.3.2. Group of attributes

8.3.3. Basic attributes

8.3.4. DOS attributes

8.3.5. POSIX attributes

8.3.6. AclFileAttributeView interface

8.3.7. FileOwnerAttributeView interface

8.3.8. UserDefinedAttributeView interface

8.4. Recursively access a directory tree

8.4.1. FileVisitor interface

8.4.2. Class SimpleFileVisitor

8.4.3. Initiate traversal for FileVisitor and SimpleFileVisitor

8.4.4. DirectoryStream interface

8.5. Using PathMatcher

8.6. Watch a directory for changes

8.6.1. Create WatchService object

8.6.2. Register with WatchService object

8.6.3. Access watched events using WatchKey interface

8.6.4. Processing events

8.7. Summary

8.8. Review notes

8.8.1. Path objects

8.8.2. Class Files

8.8.3. Files and directory attributes

8.8.4. Recursively access a directory tree

8.8.5. Using PathMatcher

8.8.6. Watch a directory for changes

8.9. Sample exam questions

8.10. Answers to sample exam questions

9. Building Database Applications with JDBC

9.1. Introduction

9.1.1. JDBC API overview

9.1.2. JDBC architecture

9.1.3. JDBC drivers

9.2. Interfaces that make up the JDBC API core

9.2.1. Interface java.sql.Driver

9.2.2. Interface java.sql.Connection

9.2.3. Interface java.sql.Statement

9.2.4. Interface java.sql.ResultSet

9.3. Connecting to a database

9.3.1. Loading JDBC drivers

9.3.2. Use DriverManager to connect to a database

9.3.3. Exceptions thrown by database connections

9.4. CRUD (create, retrieve, update, and delete) operations

9.4.1. Read table definition and create table

9.4.2. Mapping SQL data types with Java data types

9.4.3. Insert rows in a table

9.4.4. Update data in a table

9.4.5. Delete data in a table

9.4.6. Querying database

9.5. JDBC transactions

9.5.1. A transaction example

9.5.2. Create savepoints and roll back partial transactions

9.5.3. Commit modes and JDBC transactions

9.6. RowSet objects

9.6.1. Interface RowSetFactory

9.6.2. Class RowSetProvider

9.6.3. An example of working with JdbcRowSet

9.7. Precompiled statements

9.7.1. Prepared statements

9.7.2. Interface CallableStatement

9.7.3. Database-stored procedures with parameters

9.8. Summary

9.9. Review notes

9.9.1. Introduction

9.9.2. Interfaces that make up the JDBC API core

9.9.3. Connecting to a database

9.9.4. CRUD (create, retrieve, update, and delete) operations

9.9.5. JDBC transactions

9.9.6. RowSet objects

9.9.7. Precompiled statements

9.10. Sample exam questions

9.11. Answers to sample exam questions

10. Threads

10.1. Create and use threads

10.1.1. Extending class Thread

10.1.2. Implement interface Runnable

10.2. Thread lifecycle

10.2.1. Lifecycle of a thread

10.2.2. Methods of class Thread

10.2.3. Start thread execution

10.2.4. Pause thread execution

10.2.5. End thread execution

10.3. Protect shared data

10.3.1. Identifying shared data: WARM-UP

10.3.2. Thread interference

10.3.3. Thread-safe access to shared data

10.3.4. Immutable objects are thread safe

10.3.5. Volatile variables

10.4. Identify and fix code in a multithreaded environment

10.4.1. Variables you should care about

10.4.2. Operations you should care about

10.4.3. Waiting for notification of events: using wait, notify, and notifyAll

10.4.4. Deadlock

10.4.5. Starvation

10.4.6. Livelock

10.4.7. Happens-before relationship

10.5. Summary

10.6. Review notes

10.6.1. Create and use threads

10.6.2. Thread lifecycle

10.6.3. Methods of class Thread

10.6.4. Protect shared data

10.6.5. Identify and fix code in a multithreaded environment

10.7. Sample exam questions

10.8. Answers to sample exam questions

11. Concurrency

11.1. Concurrent collection classes

11.1.1. Interface BlockingQueue

11.1.2. Interface ConcurrentMap

11.1.3. Class ConcurrentHashMap

11.2. Locks

11.2.1. Acquire lock

11.2.2. Acquire lock and return immediately

11.2.3. Interruptible locks

11.2.4. Nonblock-structured locking

11.2.5. Interface ReadWriteLock

11.2.6. Class ReentrantReadWriteLock

11.2.7. Atomic variables

11.3. Executors

11.3.1. Interface Executor

11.3.2. Interface Callable

11.3.3. Interface ExecutorService

11.3.4. Thread pools

11.3.5. Interface ScheduledExecutorService

11.4. Parallel fork/join framework

11.5. Summary

11.6. Review notes 709

11.6.1. Concurrent collection classes

11.6.2. Locks

11.6.3. Executors

11.6.4. Parallel fork/join framework1

11.7. Sample exam questions

11.8. Answers to sample exam questions

12. Localization

12.1. Internationalization and localization

12.1.1. Advantages of localization

12.1.2. Class java.util.Locale

12.1.3. Creating and accessing Locale objects

12.1.4. Building locale-aware applications

12.2. Resource bundles

12.2.1. Implementing resource bundles using property files

12.2.2. Implementing resource bundles using ListResourceBundle

12.2.3. Loading resource bundles for invalid values

12.3. Formatting dates, numbers, and currencies for locales

12.3.1. Format numbers

12.3.2. Format currencies

12.3.3. Format dates

12.3.4. Formatting and parsing time for a specific locale

12.3.5. Formatting and parsing date and time together for a specific locale

12.3.6. Using custom date and time patterns with SimpleDateFormat

12.3.7. Creating class Date object using class Calendar

12.4. Summary

12.5. Review Notes

12.5.1. Internationalization and localization

12.5.2. Resource bundles

12.5.3. Formatting dates, numbers, and currencies for locales

12.6. Sample exam questionsS

12.7. Answers to sample exam questions

Appendix - Answers to 'Twist in Tale' exercises

13. Full Mock exam

13.1. Available online only at www.manning.com/gupta2

About the book

The OCP Java 7 certification tells potential employers that you’ve mastered the language skills you need to design and build professional-quality Java software. Passing the OCP isn’t just about knowing your Java, though. You have to also know what to expect on the exam and how to beat the built-in tricks and traps.

OCP Java SE 7 Programmer II Certification Guide is a comprehensive, focused study guide that prepares you to pass the OCP exam the first time you take it. It systematically guides you through each exam objective, reinforcing the Java skills you need through examples, exercises, and cleverly constructed visual aids. In every chapter you’ll find questions just like the ones you’ll face on the real exam. Tips, diagrams, and review notes give structure to the learning process to improve your retention.

What's inside

  • 100% coverage of the OCP Java SE 7 Programmer II exam (1Z0-804)
  • Flowcharts, UML diagrams, and other visual aids
  • Hands-on coding exercises
  • Focuses on passing the exam, not the Java language itself

About the reader

Designed for readers with intermediate-level Java skills.

About the author

Mala Gupta is a trainer of programmers who plan to pass Java certification exams. She holds the OCP Java SE 7 Programmer, SCWCD, and SCJP certifications and is the author of OCA Java SE 7 Programmer I Certification Guide (Manning 2013).


combo $44.99 pBook + eBook
eBook $35.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

Makes the certification objectives clear and easy to understand.

Mikael Strand, Capgemini

An Excellent resource for the OCP certification exam.

Ahutosh Sharma, Discover Financial Services, LLC

With a conversational style of writing, detailed code examples, and self-test questions, this book will successfully lead you to your OCP certification.

Mikalai Zaikin, IBA IT Park