what does it mean to be OCP Java 8 Programmer II certified?

There are now three paths for one to become OCP 8 (Java Programmer II certified.) So what does it mean someone certified had to know to pass the exam. Well, that varies too.

The three paths

  1. Starting out with Java 8 – take the OCP 8 (IZ0-809)
    Pre-req: OCA 8 (1Z0-808)
  2. Holding a Java 7 Professional cert – take the Java 7 to 8 upgrade exam (IZo-810)
    Pre-req: OCP 7 (IZ0-804) or Java 7 upgrade exam (IZo-805)
  3. Holding any Java 6 or older Professional cert – take the Java 6 or earlier to 8 upgrade exam (IZo-813)
    Pre-req: SCJP/OCJP 6 (IZO-851) or Java 6 upgrade (IZ0-852) or SCJP/OCJP 5 (IZo-853) or Java 5 upgrade (1Zo-854) or Java 4 or lower Professional cert

What one would expect

It seems reasonable to assume some things here.

  1. People taking the OCP 8 directly should be tested on the topics that entail being Java 8 certified.
  2. vennPeople taking the upgrade from Java 7 should be tested on just the topics that were added in Java 8. This is the purple in the Venn diagram. There’s no reason to retest on the topics that the were already on the Java 7 exam. That’s the overlap in the Venn diagram. (This is a bit simplified. It’s really that the topics should be those on the OCA 8 or OCP 8, but not on the OCA 7 or OCP 7. Luckily the topics added on the OCA 8 are also on the OCP 8.)
  3.  venn2People taking the upgrade from older versions of Java have a more interesting situation. When taking a very old exam, lots of topics are different. For example, new topics include generics and the enhanced for loop for those upgrading from Java 5. These topics are so old that it is reasonable to assume the candidate knows this as these syntax changes are covered as part of questions on all sorts of topics. Since the exam changed a lot between Java 6 and 7, let’s just imagine all upgrade candidates in this group took the Java 6 exam. Which would imply the topics covered should be the purple OCP 8 circle except for the overlap with the OCP 6 circle. It doesn’t imply the topics covered in OCP 7 but not OCP 6 or 8 should be covered. After all, those topics were removed from the OCP 8 exam so shouldn’t be needed to get a Java 8 certification.

These assumptions turn out to not match what Oracle actually did. The rest of this blog post describes the surprises.

What people starting out with Java 8 were tested on, but those upgrading from Java 7 were not

Topics:

  1. The concept of immutability
  2. The concepts of deadlock, starvation, livelock, and race conditions. They are tested when upgrading indirectly but with less emphasis.

My thoughts: No big deal here

What people starting out with Java 8 were tested on, but those upgrading from Java 6 were not

  1. The concept of immutability
  2. The singleton pattern
  3. The concepts of deadlock, starvation, livelock, and race conditions. They are tested when upgrading indirectly but with less emphasis.
  4. The entire topic of JDBC

My thoughts: Leaving out the first three isn’t a big deal. Leaving out JDBC is bizarre. That’s a whole topic that is part of core Java. It started being needed for Java 7 (or 8) certification. Upgrading from an older version seems like it should require it. But nope.

What people upgrading from Java 7 were tested on, but those starting out with Java 8 were not

  1. The computeIfAbsent() and computeIfPresent() methods on Map
  2. Also merge()  [removed from main exam in October 2015 and removed from upgrade exam in November 2015]

My thoughts: Odd to add topics on an upgrade exam. These are so similar, I’d almost think they were implied on the Java 8 exam.

What people upgrading from Java 6 were tested on, but those starting out with Java 8 were not

  1. The computeIfAbsent() and computeIfPresent() methods on Map
  2. Also merge()  [removed from main exam in October 2015]
  3. IO.2 – DirectoryWatcher, FileVisitor and WatchService
  4. Locks package in concurrency API
  5. DecimalFormat and SimpleDateFormat

My thoughts: This is bizarre. These three NIO.2 classes, the locks package and the two format classes were on the OCP 7 exam, but not on the OCP 8 exam. Oracle changing their mind and taking something off the exam for a later version is perfectly reasonable. However, I would think that would mean you don’t put it on the upgrade exam! Why should the upgrade exam cover something that isn’t on the target exam.

Summary

If I was writing the objectives for the upgrade exam from Java 6,  I’d have dropped some topics and added JDBC. But I’m not writing the exam objectives so will remain puzzled.

Formatting Strings for the Java Foundations Junior Associate exam

Thinking about using our OCA 8 book to study for the Java Foundations Junior Associate exam? It covers most of the topics. See what other topics you need to learn and where to read about that. One of those topics is formatting a String using %s, %n and %d. Conveniently for you , I had written a draft of this material for our OCP book before finding out that topic is not on the OCP 8 exam. I asked our publisher if I could post the material online and they said yes. I’ve edited it down to cover the subset that is on the Java Foundations Junior Associate exam. While the style matches our book, keep in mind it has not gone through the normal editing process by our publisher.

Note that the exam only expects you to know %d (digit/integer), %s (string) and %n (new line). This post covers a bit about %f (decimal) for two reasons:

  1. To help you remember why %d is digit/integer and not a floating point number
  2. To see the power of printf!

Formatting Strings

Formatting a String is useful because they let us specify a lot of complex logic clearly and succinctly . Imagine you had to write code to print out exactly 3 decimal places and align the decimal places. That would be a lot of coding and logic. Or it could be done using formatting:

List<Double> values = Arrays.asList(123.456, -1.4, 2.0);

for (Double d : values)

System.out.printf("%7.3f%n", d);

Don’t worry if this seems like magic. In a nutshell, this uses a width of 7 with 3 decimal places followed by a new line. It outputs:

123.456
-1.400
2.000

You don’t have to be able to write code like this. It is just to show the power of formatting. Also, there are a lot more types and options in existence than you need to know for the exam. See the Formatter class in the Javadoc for the ones not on the exam. The following figure shows what is going on from a high level. Java is substituting the parameter into a part of the format string.c05f003Ok. From this point on, you do need to know the material for the exam.

The PrintStream class defines the methods format and printf. They do the exact same thing. Java wanted to name the method format. However, C++ has had this method called printf for decades. Java supports both names to make things easy for both C++ developers and new developers.

System.out and System.err are both PrintStream instances. Remember that System.out.println() can show up in questions on just about anything as can System.out.printf(). This means you won’t know specifically if you are being tested on printf or something else.

The signatures of these two methods are:

  • public PrintWriter format(String fmt, Object… args)
  • public PrintWriter printf(String fmt, Object… args)

Remember that the three dots mean varargs. You can pass as many arguments as you want here. Also, remember that format and printf are exactly the same so we will start to use them interchangeably.

The first parameter is a String with embedded format parameters. The remaining parameters are an ordered list of the parameters to be inserted:

int num = 3;

String s = "Three: ";

System.out.format("%s %d", s, num);

Java sees a format string of a String to be inserted, followed by a space and then followed by a number to be inserted. The output is:

Three: 3

There are a number of parts to a format string. You only need to know a simplified version which looks like:

%[arg_index$]conversion_char

Conversion Character

%d and %s are format conversion specifiers. These format specifiers indicate the type of the parameter. You are only required to know three of the format specifiers for the exam as listed in following table. You do have to memorize these. They are copied from C++ so some of the types might seem odd to you. We’ve tried to give a description that helps you remember it rather than the shortest one possible. If you are a C++ developer, you might know that %d actually stands for decimal rather than digit. This is harder to remember for a new developer because the whole point of %d is that there is not a decimal point.

Remember that %d is digit (integer) and not double.

Conversion Specifier Description
%d Specifies a number with digits and no decimal point. (also known as an integer number)
%n New line (line break)
%s Specifies a String

Argument Index

The remaining part of a format string is the argument index. This is the index number followed by a $.

Argument indexes start counting from 1 instead of 0.

These examples should be straightforward:

System.out.printf("%s, %s", "play", "time");    // play, time

System.out.printf("%2$s, %1$s", "play", "time"); // time, play

System.out.printf("%2$s, %2$s", "play", "time"); // time, time

The first line can omit the argument index since we want to use them in the order provided. The second line shows how to reverse the arguments. The final line shows how to use the same argument multiple times.

The Formatter Class

The Formatter class is an interpreter for the format strings used in format/printf methods. The class is similar to the PrintWriter class except that Formatter defines only the format methods and not the printf methods. Since the Formatter class didn’t exist in C++, Java didn’t need to be compatible with it. You invoke format in the way you do PrintWriter: passing in a format specifier followed by a comma-separated list of arguments.

For example, the following statements create a Formatter object and format a string of primitive types. What do you think this outputs?

StringBuilder sb = new StringBuilder();

Formatter fmt = new Formatter(sb);

int x = 123;

fmt.format("x=%d", x);

System.out.println(sb.toString());

In this example, the Formatter writes its output to a StringBuilder object. The int x is formatted and the resulting StringBuilder looks like this:

x=123

As you can see, working with Formatter is similar to working with PrintWriter.

Summary

printf() and format() use a format string. You need to know the simplified format of: %[arg_index$]conversion_char. The arg_index is optional. However, it must be specified in the correct order if present. The components you need to know are:

  • arg_index is an index that starts counting with one
  • conversion_character includes:
    • %b for boolean
    • %d for digit/decimal/integer (no decimal point)
    • %n for new line
    • %s for strings

Practice Questions

Question 1

What is the result of the following code?

System.out.format("%2$d is bigger than %2$d", 10, 5);

A: 10 is bigger than 5
B: 5 is bigger than 10
C: 10 is bigger than 10
D: 5 is bigger than 5
E: The code does not compile
F: A runtime exception is thrown

Question 2

Which of the following are true about the format string passed to printf? (Choose all that apply)

A: The argument index is a 0 based index.
B: The argument index is a 1 based index.
C: double goes with %d
D: int goes with %d

Question 3

What is the output of this statement?

System.out.printf("%2$d %1$s", "entry", 123.456);

A: 123 entry
B: 123.456 entry
C: entry 123
D: entry 123.456
E: The code does not compile
F: A runtime exception is thrown

Question 4

What is the output of this statement?

System.out.format("$n, $s", 123.456);

A: %n %s
B: $n $s
C: %n, %s
D: $n, $s
E: None of the above
F: A runtime exception is thrown

Question 5

What is the output of this statement?

System.out.println("%d", 123);

A: 0
B: 123
C: %d
D: The code does not compile
E: A runtime exception is thrown

The answers are posted here.

Real World Applications of Java for the Java Foundations Junior Associate exam

Thinking about using our OCA 8 book to study for the Java Foundations Junior Associate exam? It covers most of the topics. See what other topics you need to learn and where to read about that. One of those topics is real world applications of Java. This part is similar to on the Java 5/6 associate exam where you need to understand what certain technologies are on a high level.

Consider this post a mini-glossary of flashcards you need to know. You don’t need to know what the acronyms stand for. You do need to know their purpose.

Types of Java

  • Java SE – Java Standard Edition. The main version of Java
  • Java EE – Java Enterprise Edition. Adds server technologies such as Servlets and EJBs. (more on this coming up)
  • Java ME – Java Mobile Edition. A subset of Java SE that runs on mobile devices.

Working with Databases

  • SQL – Structured Query Language. Used for working with databases.
  • RDBMS – Relational Database Management System. A database such as MySQL or Oracle.
  • JDBC – Java Database Connectivity. Used to connect Java to a RDBMS using SQL.
  • JPA – Java Persistence Architecture. Used to map Java objects to a RDBMS.

Working with Components or Remote Calls

  • EJB – Enterprise Java Beans. Used for encapsulating the business logic of components. Can be used remotely or add transaction support.
  • RMI – Remote Method Invocation. Used for talking to other machines
  • Web Services – Used for talking to other machines through a defined interface
  • REST – Representational State Transfer. Used for web services.
  • SOAP – Simple Object Access Protocol. Used for web services

Web

  • Servlet – The entry point for a web call
  • JSP – Java Server Pages. Used to create the view code for a web application
  • JSF – Java Server Faces. Framework with components for a web application
  • Java Web Start – for downloading and running Java programs offline

Working in the Background

  • Asynchronous – Run a method or job without waiting for a reply
  • JMS – Java Message Service. Run a job asynchronously
  • Timer – Schedule a job for later

Client side

  • Applet – Java code that runs in a browser.
  • Sandbox – Protects your computer form an applet
  • Swing – Older technology for Java user interfaces
  • Java FX – Newer technology for Java user interfaces

Other terms

  • JNDI – Java Naming and Directory Interface. Used for looking up something like an EJB.
  • SMTP – Simple Mail Transfer Protocol. Used for sending email.

Practice Questions

Question 1

Which of the following are web technologies? (Choose all that apply)

A: EJB

B: JDBC

C: JSF

D: Servlet

E: SMTP

Question 2

Which of these technologies is used asynchronously?

A: EJB

B: JMS

C: JNDI

D: JPA

E: Swing

Question 3

Which of the following are database technologies? (Choose all that apply)

A: Java FX

B: JDBC

C: JPA

D: JSF

E: Servlet

Question 4

Which of the following run in a browser?

A: Applet

B: JNDI

C: JSF

D: JSP

E: Servlet

The answers are posted here.