- •Contents at a Glance
- •Contents
- •About the Authors
- •About the Technical Reviewer
- •Acknowledgments
- •Introduction
- •Oracle Java Certifications: Overview
- •FAQ 1. What are the different levels of Oracle Java certification exams?
- •FAQ 4. Is OCPJP 7 prerequisite for other Oracle certification exams?
- •FAQ 5. Should I take the OCPJP 7 or OCPJP 6 exam?
- •The OCPJP 7 Exam
- •FAQ 7. How many questions are there in the OCPJP 7 exam?
- •FAQ 8. What is the duration of the OCPJP 7 exam?
- •FAQ 9. What is the cost of the OCPJP 7 exam?
- •FAQ 10. What are the passing scores for the OCPJP 7 exam?
- •FAQ 11. What kinds of questions are asked in the OCPJP 7 exam?
- •FAQ 12. What does the OCPJP 7 exam test for?
- •FAQ 13. I’ve been a Java programmer for last five years. Do I have to prepare for the OCPJP 7 exam?
- •FAQ 14. How do I prepare for the OCPJP 7 exam?
- •FAQ 15. How do I know when I’m ready to take the OCPJP 7 exam?
- •Taking the OCPJP 7 Exam
- •FAQ 16. What are my options to register for the exam?
- •FAQ 17. How do I register for the exam, schedule a day and time for taking the exam, and appear for the exam?
- •The OCPJP 7 Exam: Pretest
- •Answers with Explanations
- •Post-Pretest Evaluation
- •Essentials of OOP
- •FunPaint Application: An Example
- •Foundations of OOP
- •Abstraction
- •Encapsulation
- •Inheritance
- •Polymorphism
- •Class Fundamentals
- •Object Creation
- •Constructors
- •Access Modifiers
- •Public Access Modifier
- •Private Access Modifier
- •Protected and Default Access Modifier
- •Overloading
- •Method Overloading
- •Constructor Overloading
- •Overload resolution
- •Points to Remember
- •Inheritance
- •Runtime Polymorphism
- •An Example
- •Overriding Issues
- •Overriding: Deeper Dive
- •Invoking Superclass Methods
- •Type Conversions
- •Upcasts and Downcasts
- •Casting Between Inconvertible Types
- •Using “instanceof” for Safe Downcasts
- •Java Packages
- •Working with Packages
- •Static Import
- •Summary
- •Abstract Classes
- •Points to Remember
- •Using the “final” Keyword
- •Final Classes
- •Final Methods and Variables
- •Points to Remember
- •Using the “static” Keyword
- •Static Block
- •Points to Remember
- •Flavors of Nested Classes
- •Static Nested Classes (or Interfaces)
- •Points to Remember
- •Inner Classes
- •Points to Remember
- •Local Inner Classes
- •Points to Remember
- •Anonymous Inner Classes
- •Points to Remember
- •Enum Data Types
- •Points to Remember
- •Summary
- •Interfaces
- •Declaring and Using Interfaces
- •Points to Remember
- •Abstract Classes vs. Interfaces
- •Choosing Between an Abstract Class and an Interface
- •Object Composition
- •Composition vs. Inheritance
- •Points to Remember
- •Design Patterns
- •The Singleton Design Pattern
- •Ensuring That Your Singleton Is Indeed a Singleton
- •The Factory Design Pattern
- •Differences Between Factory and Abstract Factory Design Patterns
- •The Data Access Object (DAO) Design Pattern
- •Points to Remember
- •Summary
- •Generics
- •Using Object Type and Type Safety
- •Using the Object Class vs. Generics
- •Container Implementation Using the Object Class
- •Container Implementation Using Generics
- •Creating Generic Classes
- •Diamond Syntax
- •Interoperability of Raw Types and Generic Types
- •Generic Methods
- •Generics and Subtyping
- •Wildcard Parameters
- •Limitations of Wildcards
- •Bounded Wildcards
- •Wildcards in the Collections Class
- •Points to Remember
- •The Collections Framework
- •Why Reusable Classes?
- •Basic Components of the Collections Framework
- •Abstract Classes and Interfaces
- •Concrete Classes
- •List Classes
- •ArrayList Class
- •The ListIterator Interface
- •The LinkedList Class
- •The Set Interface
- •The HashSet Class
- •The TreeSet Class
- •The Map Interface
- •The HashMap Class
- •Overriding the hashCode() Method
- •The NavigableMap Interface
- •The Queue Interface
- •The Deque Interface
- •Comparable and Comparator Interfaces
- •Algorithms (Collections Class)
- •The Arrays Class
- •Methods in the Arrays Class
- •Array as a List
- •Points to Remember
- •Summary
- •Generics
- •Collections Framework
- •Processing Strings
- •String Searching
- •The IndexOf() Method
- •The regionMatches() Method
- •String Parsing
- •String Conversions
- •The Split() Method
- •Regular Expressions
- •Understanding regex Symbols
- •Regex Support in Java
- •Searching and Parsing with regex
- •Replacing Strings with regex
- •String Formatting
- •Format Specifiers
- •Points to Remember
- •Summary
- •Reading and Writing from Console
- •Understanding the Console Class
- •Formatted I/O with the Console Class
- •Special Character Handling in the Console Class
- •Using Streams to Read and Write Files
- •Character Streams and Byte Streams
- •Character Streams
- •Reading Text Files
- •Reading and Writing Text Files
- •“Tokenizing” Text
- •Byte Streams
- •Reading a Byte Stream
- •Data Streams
- •Writing to and Reading from Object Streams: Serialization
- •Serialization: Some More Details
- •Points to Remember
- •Summary
- •A Quick History of I/O APIs
- •Using the Path Interface
- •Getting Path Information
- •Comparing Two Paths
- •Using the Files Class
- •Checking File Properties and Metadata
- •Copying a File
- •Moving a File
- •Deleting a File
- •Walking a File Tree
- •Revisiting File Copy
- •Finding a File
- •Watching a Directory for Changes
- •Points to Remember
- •Summary
- •Introduction to JDBC
- •The Architecture of JDBC
- •Two-Tier and Three-Tier JDBC Architecture
- •Types of JDBC Drivers
- •Setting Up the Database
- •Connecting to a Database Using a JDBC Driver
- •The Connection Interface
- •Connecting to the Database
- •Statement
- •ResultSet
- •Querying the Database
- •Updating the Database
- •Getting the Database Metadata
- •Points to Remember
- •Querying and Updating the Database
- •Performing Transactions
- •Rolling Back Database Operations
- •The RowSet Interface
- •Points to Remember
- •Summary
- •Define the Layout of the JDBC API
- •Connect to a Database by Using a JDBC driver
- •Update and Query a Database
- •Customize the Transaction Behavior of JDBC and Commit Transactions
- •Use the JDBC 4.1 RowSetProvider, RowSetFactory, and RowSet Interfaces
- •Introduction to Exception Handling
- •Throwing Exceptions
- •Unhandled Exceptions
- •Try and Catch Statements
- •Programmatically Accessing the Stack Trace
- •Multiple Catch Blocks
- •Multi-Catch Blocks
- •General Catch Handlers
- •Finally Blocks
- •Points to Remember
- •Try-with-Resources
- •Closing Multiple Resources
- •Points to Remember
- •Exception Types
- •The Exception Class
- •The RuntimeException Class
- •The Error Class
- •The Throws Clause
- •Method Overriding and the Throws Clause
- •Points to Remember
- •Custom Exceptions
- •Assertions
- •Assert Statement
- •How Not to Use Asserts
- •Summary
- •Introduction
- •Locales
- •The Locale Class
- •Getting Locale Details
- •Resource Bundles
- •Using PropertyResourceBundle
- •Using ListResourceBundle
- •Loading a Resource Bundle
- •Naming Convention for Resource Bundles
- •Formatting for Local Culture
- •The NumberFormat Class
- •The Currency Class
- •The DateFormat Class
- •The SimpleDateFormat Class
- •Points to Remember
- •Summary
- •Introduction to Concurrent Programming
- •Important Threading-Related Methods
- •Creating Threads
- •Extending the Thread Class
- •Implementing the Runnable Interface
- •The Start( ) and Run( ) Methods
- •Thread Name, Priority, and Group
- •Using the Thread.sleep() Method
- •Using Thread’s Join Method
- •Asynchronous Execution
- •The States of a Thread
- •Two States in “Runnable” State
- •Concurrent Access Problems
- •Data Races
- •Thread Synchronization
- •Synchronized Blocks
- •Synchronized Methods
- •Synchronized Blocks vs. Synchronized Methods
- •Deadlocks
- •Other Threading Problems
- •Livelocks
- •Lock Starvation
- •The Wait/Notify Mechanism
- •Let’s Solve a Problem
- •More Thread States
- •timed_waiting and blocked States
- •waiting State
- •Using Thread.State enum
- •Understanding IllegalThreadStateException
- •Summary
- •Using java.util.concurrent Collections
- •Semaphore
- •CountDownLatch
- •Exchanger
- •CyclicBarrier
- •Phaser
- •Concurrent Collections
- •Apply Atomic Variables and Locks
- •Atomic Variables
- •Locks
- •Conditions
- •Multiple Conditions on a Lock
- •Use Executors and ThreadPools
- •Executor
- •Callable, Executors, ExecutorService, ThreadPool, and Future
- •ThreadFactory
- •The ThreadLocalRandom Class
- •TimeUnit Enumeration
- •Use the Parallel Fork/Join Framework
- •Useful Classes of the Fork/Join Framework
- •Using the Fork/Join Framework
- •Points to Remember
- •Summary
- •Using java.util.concurrent Collections
- •Applying Atomic Variables and Locks
- •Using Executors and ThreadPools
- •Using the Parallel Fork/Join Framework
- •Chapter 3: Java Class Design
- •Chapter 4: Advanced Class Design
- •Chapter 5: Object-Oriented Design Principles
- •Chapter 6: Generics and Collections
- •Chapter 7: String Processing
- •Chapter 8: Java I/O Fundamentals
- •Chapter 9: Java File I/O (NIO.2)
- •Chapter 10: Building Database Applications with JDBC
- •Chapter 11: Exceptions and Assertions
- •Chapter 12: Localization
- •Chapter 13: Threads
- •Chapter 14: Concurrency
- •OCPJP7 Exam (1Z0-804 a.k.a. Java SE 7 Programmer II) Topics
- •OCPJP 7 Exam (1Z0-805, a.k.a. Upgrade to Java SE 7 Programmer) Topics
- •Answers and Explanations
- •Answer Sheet
- •Answers and Explanations
- •Index
Chapter 1
The OCPJP 7 Exam: FAQ
The singular acronym of the OCPJP 7 exam is shorthand for two separate but congruent exams:
•The Java SE 7 Programmer II exam (exam number 1Z0-804)
•The Upgrade to Java SE 7 Programmer exam (exam number 1Z0-805)
These two exams are alternative paths to the same certification. The 1Z0-804 and 1Z0-805 exams both qualify the candidates who pass them for the same credential: Oracle Certified Professional, Java SE 7 Programmer (OCPJP 7). This book prepares you to take the OCPJP 7 exams.
The 1Z0-804 exam syllabus (given in full in Appendix A) consists of twelve topics, mapping to the titles and subjects of Chapters 3–14 of this book. This book serves equally as preparation for the 1Z0-805 exam, whose six topics map to Chapters 5–6 and 9–14 of this book (see Appendix A).
In this preliminary chapter, we address the frequently asked questions (FAQs) that are apt to come to mind when you are preparing for the OCPJP 7 exam. Again, the term “OCPJP 7 exam” should be taken in the sense of encompassing both variants of the exam, the 1Z0-804 and 1Z0-805. The course of study, model questions, and practice tests presented in this book will prepare you equally well to take either one. Which variant of the OCPJP 7 exam you take will depend on your existing credentials, as explained below.
The FAQs we present in this chapter answer concerns such as the placement of OCPJP 7 certification in the suite of Oracle Java certifications, the difficulty level and prerequisites of the OCPJP 7 exam, the scope of the topics on
the OCPJP 7 exam syllabus, the depth of the preparation for it, and the details of registering for and taking the exam. Broadly, this chapter consists of three sections:
•Oracle Java Certifications: Overview: FAQs 1–6 survey Oracle’s various Java exams as they map onto Java certifications. It focuses in particular on the OCAJP 7 exam, because the Oracle Certified Associate, Java SE 7 Programmer (OCAJP 7) credential is a prerequisite for OCPJP 7 certification via the 1Z0-804 exam.
•The OCPJP 7 Exam: FAQs 7–15 concern the objectives of the OCPJP 7 exam, the kinds of questions on it, and the details about the preparation for it.
•Taking the OCPJP 7 Exam: FAQs 16, 17, and 18 cover the nuts and bolts of registering for exam, the various things you need to do on the day of the exam, and actually taking the exam.
Oracle Java Certifications: Overview
FAQ 1. What are the different levels of Oracle Java certification exams?
Table 1-1 shows four ascending expertise levels of Oracle exams (Associate, Professional, Expert, and Master) matched with examples of Java certifications at those levels, together with the qualifying exams by name and number.
1
Chapter 1 ■The OCPJP 7 Exam: FAQ
Table 1-1. Oracle Certification Levels with Examples of Corresponding Java Exams (OPCJP 7 exam, in bold)
Certification Level |
Java Certification (Example) |
Exam Name |
Exam Number |
Oracle Certified Associate |
Oracle Certified Associate, Java SE 7 |
Java SE 7 Programmer I |
1Z0-803 |
(OCA) |
Programmer |
|
|
Oracle Certified |
Oracle Certified Professional, Java SE |
Java SE 7 Programmer II |
1Z0-804 |
Professional (OCP) |
7 Programmer |
|
|
|
Oracle Certified Professional, Java SE |
Upgrade to Java SE 7 |
1Z0-805 |
|
7 Programmer |
Programmer |
|
Oracle Certified |
Oracle Certified Expert, NetBeans |
NetBeans Integrated |
1Z0-889 |
Expert (OCE) |
Integrated Development |
Development |
|
|
Environment 6.1 Programmer |
Environment 6.1 |
|
|
|
Programmer Certified |
|
|
|
Expert Exam |
|
Oracle Certified |
Oracle Certified Master, Java SE6 |
Java Standard Edition 6 |
1Z0-856 |
Master (OCM) |
Developer |
Developer Certified |
|
|
|
Master Essay Exam |
|
|
|
|
|
Pictorially, Java exams offered by Oracle and their path can be observed in Figure 1-1.
Figure 1-1. Java certification path offered by Oracle
FAQ 2. Can you compare the specifications of the 1Z0-803, 1Z0-804, and 1Z0-805 exams in relation to OCAJP 7 and OCPJP 7 certification?
Yes, see Table 1-2.
2
|
|
|
Chapter 1 ■The OCPJP 7 Exam: FAQ |
|
Table 1-2. Comparison of the Oracle Exams Leading to OCAJP 7 and OCPJP 7 Certification |
||||
|
|
|
|
|
Exam Number |
1Z0-803 |
1Z0-804 |
1Z0-805 |
|
Expertise Level |
Beginner |
Intermediate |
Intermediate |
|
Exam Name |
Java SE 7 Programmer I |
Java SE 7 Programmer II |
Upgrade to Java SE 7 |
|
|
|
|
Programmer |
|
Associated |
Oracle Certified Associate, |
Oracle Certified |
Oracle Certified |
|
Certification |
Java SE 7 Programmer |
Professional, Java SE 7 |
Professional, Java SE 7 |
|
(abbreviation) |
(OCAJP 7) |
Programmer (OCPJP 7) |
Programmer (OCPJP 7) |
|
Prerequisite |
None |
OCAJP 7 |
Any older OCPJP version or |
|
Certification |
|
|
any version of SCJP |
|
Exam Duration |
2 hrs 30 minutes |
2 hrs 30 minutes |
3 hrs (180 mins) |
|
|
(150 mins) |
(150 mins) |
|
|
Number of |
90 Questions |
90 Questions |
90 Questions |
|
Questions |
|
|
|
|
Pass Percentage |
75% |
65% |
60% |
|
Cost |
~ USD 300 |
~ USD 300 |
~ USD 300 |
|
Exam Topics |
Java Basics |
Java Class Design |
Language Enhancements |
|
|
Working With Java Data Types |
Advanced Class Design |
Design Patterns |
|
|
Creating and Manipulate |
Object-Oriented Design |
Java File I/O (NIO.2) |
|
|
Strings |
Principles |
|
|
|
Creating and Using Arrays |
Generics and Collections |
Describe the JDBC API |
|
|
Using Loop Constructs |
String Processing |
Concurrency |
|
|
Working with Methods |
Exceptions and Assertions |
Localization |
|
|
and Encapsulation |
|
|
|
|
Working with Inheritance |
Java I/O Fundamentals |
|
|
|
Handling Exceptions |
Java File I/O (NIO.2) |
|
|
Building Database
Applications with JDBC
Threads
Concurrency
Localization
Note 1: In the Cost row, the given USD cost of the exams is approximate as actual cost varies with currency of the country in which you take the exam: $300 in US, £202 in UK, Rs. 8,500 in India, etc.
Note 2: The Exam Topics row lists only the top-level topics. Note that the 1Z0-804 and 1Z0-805 exams share certain high-level topic names—such as “Java File I/O (NIO.2),” “Concurrency,” and “Localization”—but that the subtopics are not identical between the two exams. The subtopics of the 1Z0-804 and 1Z0-805 exams are listed in Appendix A.
3
Chapter 1 ■The OCPJP 7 Exam: FAQ
FAQ 3. OCAJP 7 certification is a prerequisite for OCPJP 7 certification via the 1Z0-804 exam. Does that mean that I have to take the OCAJP 7 exam before I can take the OCPJP 7 exam?
No, requirements for certification may be met in any order. You may take the OCPJP 7 exam before you take the OCAJP 7 exam, but you will not be granted OCPJP 7 certification until you have passed both the 1Z0-803 exam and the 1Z0-804 exam—unless you are eligible to take and pass the 1Z0-805 exam, for which OCAJP 7 certification is not a prerequisite.
FAQ 4. Is OCPJP 7 prerequisite for other Oracle certification exams?
Yes, OCPJP 7 is prerequisite for many other exams, such as
•Java Enterprise Edition 5 Web Component Developer Certified Professional Exam (1Z0-858)
•Oracle Certified Master, Java SE 6 Developer exam (1Z0-855 and 1Z0-856)
FAQ 5. Should I take the OCPJP 7 or OCPJP 6 exam?
Although you can still take exams for older certifications such as OCPJP 6, OCPJP 7 is the best professional credential to have.
FAQ 6. How does the Oracle OCPJP 7 exam differ from the OCPJP 6 and OCPJP 5 exams (and the previous Sun versions SCJP 6 and SCJP 5)?
Short answer: The OCPJP 7 exam is tougher and covers more topics.
Long answer: Here is a short list of differences between the OCPJP 7 exam (1Z0-804) versus the OCPJP 6 and OCPJP 5 exams (1Z0-851 and 1Z0-853, respectively) and the SCJP 5 and SCJP 6 exams (the former Sun Microsystems versions of the OCPJP 6 and OCPJP 5 exams, leading to Sun Certified Java Programmer 6 and 5 certifications):
•Like the former SCJP 6/SCJP 5 exams, the OCPJP 6 and 5 exams cover language fundamentals and some of the common APIs involving strings, arrays, and so on. At the Java SE 7 level, most of these topics have been moved to the OCAJP 7 exam, which is the prerequisite for OCPJP 7 certification through the 1Z0-804 exam path. Note that some questions in OCAJP 7 have the same difficulty level as OCPJP 7 questions.
•The OCPJP 7 exam covers more topics than the OCPJP 6 and 5 exams and their Sun predecessors, including JDBC, localization, NIO.2, and concurrency APIs.
•OCPJP 7 also covers new features of Java SE 7, including try-with-resources statements, new APIs in JDBC, string-based switches, and binary literals.
•The questions in the OCPJP 7 exam are tougher than those asked in the OCPJP 6 and 5 exams and their Sun predecessors.
•The OCPJP 7 exam has only multiple-choice questions, whereas the retired SCJP exams also had interactive questions (drag-and-drop, match-the-options, etc.).
The differences between the OCPJP 6 and OCPJP 7 exams are summarized in Table 1-3.
4