Marco Olivi

+ Follow
since Jul 06, 2022
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Marco Olivi

The IOException to be handled is actually on line 11, when a new FileInputStream is created.
Last really long and boring post for Jeanne and Scott, about all of the small errors I found on the online tests.
Questions with wrong answer:


Given the following, which can correctly fill in the blank? (Choose all that apply.)
var date =;
var time =;
var dateTime =;
var zoneId = ZoneId.systemDefault();
var zonedDateTime = ZonedDateTime.of(dateTime, zoneId);
Instant instant = ______________________________;

B. new Instant()
C. date.toInstant()
D. dateTime.toInstant()
E. time.toInstant()
F. zonedDateTime.toInstant()

Option A correctly creates the current instant. Option B correctly converts from seconds to an Instant. Option F is also a proper conversion. Options C, D, and E are incorrect because the source object does not represent a point in time. Without a time zone, Java doesn’t know what moment in time to use for the Instant.

Answer B does not compile, and explanation refers to other code.


Which of the following method signatures are valid overrides of the hairy() method in the Alpaca class? (Choose all that apply.)

import java.util.*;

public class Alpaca {
  public List˂String˃ hairy(List˂String˃ list) { return null; }

A.public List˂String˃ hairy(List˂CharSequence˃ list) { return null; }
B.public List˂String˃ hairy(ArrayList˂String˃ list) { return null; }
C.public List˂String˃ hairy(List˂Integer˃ list) { return null; }
D.public List˂CharSequence˃ hairy(List˂String˃ list) { return null; }
E.public Object hairy(List˂String˃ list) { return null; }
F.public ArrayList˂String˃ hairy(List˂String˃ list) { return null; }

A valid override of a method with generic arguments must have a return type that is covariant, with matching generic type parameters. Options D and E are incorrect because the return type is too broad. Additionally, the generic arguments must have the same signature with the same generic types. This eliminates options A and C. The remaining options are correct, making the answer options B and F.

Option B has a different signature. If I'm not wrong it should compile overloading the method, not overriding it.


Which statement is true of the following module?

  |-- staff

A. The directory structure shown is a valid module.
B. The directory structure would be a valid module if were added directly underneath zoo/staff.
C. The directory structure would be a valid module if were added directly underneath zoo.
D. The directory structure would be a valid module if were added directly underneath zoo/staff.
E. The directory structure would be a valid module if were added directly underneath zoo.
F. None of these changes would make this directory structure a valid module.

Modules are required to have a file at the root directory of the module. Option D matches this requirement.

Correct answer should be answer E.

Confusing/inaccurate answers and explanations:

Which statements are true about migration? (Choose all that apply.)
A. Bottom-up migration involves automatic modules.
B. Bottom-up migration involves unnamed modules.
C. Bottom-up migration involves both the classpath and module path.
D. Top-down migration involves automatic modules.
E. Top-down migration involves unnamed modules.
F. Top-down migration involves both the classpath and module path.

Top-down migration starts with putting all JARs on the module path as automatic modules, making option D correct. Bottom-up migration starts with leaving all JARs on the classpath as unnamed modules, making options B and C correct.

That might be the only topic of the book I didn't get very well. The answers are coherent with the explanation on the book, but not really with the ones on that topic.

How many lines in this code fail to compile?

A. Zero
B. One
C. Two
D. Three
E. Four
F. Five

Lines 16 and 19 do not compile because they are not allowed in a try-with-resources declaration. Only declarations that implement AutoCloseable or Closeable are permitted. Line 17 does not compile because both the ResultSet type and concurrency mode are required if either is specified. Line 20 does not compile because execute() returns a boolean rather than a ResultSet. Finally, line 22 does not compile because the ResultSet method should be next(), not hasNext(). Since there are five errors, option F is correct.

Line 20 actually compiles as var is used. Lines 22(wrong method) and 23(wrong reference) still not compile, so answer is still E.

Which statements about the following declarations are correct? (Choose all that apply.)

A. The HasWater declaration compiles.
B. The IsSalty declaration compiles.
C. The IsSea declaration does not compile because an interface can extend only one interface.
D. The IsSea declaration compiles because it is not required to implement any of the methods it inherits.
E. The Ocean declaration compiles.
F. The variable color is inherited by the Ocean class.

The HasWater and IsSalty interfaces compile, making options A and B correct. Option C is incorrect, as an interface can extend multiple interfaces. That said, the IsSalty interface still does not compile, but the reason is that the return types of Boolean and boolean are not covariant; in other words, one is not a subtype of the other. For this reason, option D is also incorrect. Even though IsSalty is an abstract type, the compiler can detect that no concrete method could ever override both inherited abstract methods simultaneously. Option E is incorrect, as a class cannot be marked both abstract and final. Finally, option F is correct, as interface variables are implicitly public and inherited in the classes that implement the interface.

Ocean declaration does not compile so it can't inherit anything.

Suppose conn is a valid connection object and the exhibits table is empty. Which are true? (Choose two.)

A. As written, the table will remain empty after this code.
B. As written, the table will contain one row after this code.
C. As written, the code will throw an exception.
D. When line W is commented out, the table will remain empty after this code.
E. When line W is commented out, the table will contain one row after this code.
F. When line W is commented out, the code will throw an exception.

The code starts with autocommit off. As written, we turn autocommit mode back on and immediately commit the transaction. This is option B. When line W is commented out, the update gets lost, making option D the other answer.

Answer D and E should be both wrong as the result should be unknown. Quoting the study guide :

The other edge case is what happens if you have autocommit set to false and close your connection without rolling back or committing your changes. The answer is that the behavior is undefined. It may commit or roll back, depending solely on the driver.

Suppose that the table enrichment has three rows with the animals bat, rat, and snake. How many lines does this code print?

var sql = "SELECT toy FROM enrichment WHERE animal = ?";
try (var ps = conn.prepareStatement(sql)) {
  try (var rs = ps.executeQuery()) {
       while (

A. 0
B. 1
C. 3
D. The code does not compile.
E. A SQLException is thrown.
F. A different exception is thrown.

The code compiles because PreparedStatement extends Statement, and Statement allows passing a String in the executeQuery() call. While PreparedStatement can have bind variables, Statement cannot. Since this code uses executeQuery(sql) in Statement, it fails at runtime. A SQLException is thrown, making option E correct.

The explanation seems to come from another question. A SQLException is thrown because the bind variable is not implemented before executing the query.

When printed, which String gives the same value as this text block?

var pooh = """
  "Oh, bother." -Pooh

Underscore after print.

How many of these lines contain a compiler error? (Choose all that apply.)
12: int one = Math.round(6.6);
13: int two = Math.round(6.6f);
14: long three = Math.round(6.6);
15: long four = Math.round(6.6f);

A. 0
B. 1
C. 2
D. 3
E. 4

The floor() method returns an int when passed a float, which allows lines 13 and 15 to compile. In contrast, it returns a long when passed a double. This allows line 14 to compile, but not line 12. Since one line does not compile, option B is the answer.

floor() instead of round()
Which of the following lines can fill in the blank to print true? (Choose all that apply.)

10: public static void main(String[] args) {
11:    System.out.println(test(____________________________));
12: }
13: private static boolean test(Function˂Integer, Boolean˃ b) {
14:    return b.apply(5);
15: }

A. i::equals(5)
B. i -˃ {i == 5;}
C. (i) -˃ i == 5
D. (int i) -˃ i == 5
E. (int i) -˃ {return i == 5;}
F. (i) -˃ {return i == 5;}

Option A looks like a method reference. However, it doesn't call a valid method, nor can method references take parameters. The Predicate interface takes a single parameter and returns a boolean. Lambda expressions with one parameter are allowed to omit the parentheses around the parameter list, making option C correct. The return statement is optional when a single statement is in the body, making option F correct. Option B is incorrect because a return statement must be used if braces are included around the body. Options D and E are incorrect because the type is Integer in the predicate and int in the lambda. Autoboxing works for collections, not inferring predicates. If these two were changed to Integer, they would be correct. For more information, see Chapter 8

Predicate instead of Function.
Finally an errata from the book from Chapter11 - Formatting Number :

Since NumberFormat is an interface, we need the concrete DecimalFormat class to use it.

NumberFormat is actually an abstract class that provides many factory methods. DecimalFormat extends NumberFormat and inherits all of those methods, and that wouldn't be true if NumberFormat was an interface. NumberFormat formatter = DecimalFormat.getCurrencyInstance(); will compile and work correctly. I found it on the real test.

Hi everybody,
Today I passed the certification test!
Just want to share my experience for people who are approaching to the exam right now.
I'm 35 year old, I started studying Java on official Java Tutorials in January (never ever coded before), then bought the OCP Study Guide at the end of June and the Enthuwere Tests about a week ago. Completely self taught, working in the meanwhile.
I got 76%, that was my average score on simulations. Found the test on the same level of the practice tests, but less time consuming (less code and less options), so that I had about 20 minutes to review marked questions.
Finally: I booked the exam on Pearson Vue website, saving 20€, compared to the price on oracle's site.

A big thanks to all who supported me in the last weeks, you saved me from some really big headaches, especially to Jeanne and Paul.
I got it. "num>3", while I was reading "num==3"
Hello everybody!
This is question 14 from exam #1

Suppose that the table counts has five rows with the numbers 1 to 5. How many lines does this code print?

And that's the answer:

This code is tricky. While it does have two loops for the ResultSet, there is no call to the database in between. Therefore, the second call to setInt() is unused, and the second while loop does not iterate through any data. Only two lines are printed, making option C correct.

I can't understand why it says it prints two lines. For what I see the query is executed once and get just one line. So the first time returns true and the result is printed, but the second time it returns false, and the second while loop is not executed.

Jeanne Boyarsky wrote:

Marco Olivi wrote:1)Why do that code throws an EOFException?

And this one not?

I don't know. Interesting find.

It looks like you can't create an ObjectInputStream from a file if it's output stream is still open, as well as you can't create it from a file that doesn't exist or is not an Object data file.

Which statement is true of the following module?

  |-- staff

A. The directory structure shown is a valid module.
B. The directory structure would be a valid module if were added directly underneath zoo/staff.
C. The directory structure would be a valid module if were added directly underneath zoo.
D. The directory structure would be a valid module if were added directly underneath zoo/staff.
E. The directory structure would be a valid module if were added directly underneath zoo.
F. None of these changes would make this directory structure a valid module.


Modules are required to have a file at the root directory of the module. Option D matches this requirement.

Is that correct? I answered E, so that module-info file can export Vet.class through the package "staff", assuming Vet declares that is part of package staff.
Thank you Paul, for all of your explanations. I had already read the one in the question, but it was in contrast with the mental model I had of migration methods.
Now it's seems it's much much clearer in my head.
Let me understand if I'm getting closer:
- With the Bottom-up method, you need to be in control of all of the classes/packages/jar files, in order to pack all of them in named-modules. At the end of the process, every class in contained in a module-jar file, that is inside the module-path folder.
- You use Top-down method when you are not in control of some classe/packages/jar files, so that you can't convert all of them to named-modules or you just can't move some of them from the class path. So you just convert the packages you own, using automatic-modules as bridges from name-module and the unnamed module. If at the end of the method there are still classes in the class-path, you need to have at least on automatic module to use them.
Hello everybody!
After reading the post by @Hans-Joachim Bleichenbacher I really got confused about module migration. And this confusion got REALLY worse when I came into that question from Enthuwere quiz.

Identify true statement(s) about migration. Select one option

1) In bottom-up migration all modules are moved to module-path. (correct answer)
2) In top-up migration all modules are moved to module path.
3) In top-up migration, the required modules are migrated first.
4) Unnamed modules become automatic modules in top-down migration.
5) In both the approaches for migration, classpath can be used.

For answer 1, I would say that, yes at the end of the migration all of the modules are moved to module-path, but during migration we move one module at time. But before conversion we don't have modules but packages and classes, so how can we move theme?
For answer two the explanation is:

In top-up migration you start with the packages that you are most interested in and upgrade them as named modules, without worrying about their dependencies. You put the dependencies either on module-path (to make them automatic modules) or on classpath (to make them part of the unnamed module).

First of all.: what is the top-up method? Couldn't find anything on the Study Guide about that. Anyway I can't get how this method can compile: just taking some "random"  packages (the one I am "most interested in...without worrying about their dependencies"), and turning them into named-modules without specifying his dependencies (requires) will not allow them to get automatic module, as well as it won't be able (as a named-module) to access to classes and jars in the classpath if needed. So how it is supposed to work?
As I don't know what a top-up method is, I don't get the third answer neither..
Fourth answer's explanation:

In top-down migration, classes that cannot be migrated or cannot be upgraded to automatic modules are left on the classpath and they become part of the unnamed module.

That the answer I gave as true, intending it as "Jar packages without a module-info file become automatic modules in the top-down migration". And that was of course a bad interpretation. Anyway, what the explanation says is different from what I got from the Study Guide. For what I remember, the SG didn't mentioned the possibility of files (classes or jar files?) who couldn't be moved to the module-path. It just says that all of the jar files must be moved to the module-path and becomes automatic modules, and then is possible to convert the jar files we own in named-modules using automatic names.

Please help me!!!  
Thank you Jeanne, you're always so kind!

I just logged this on the errata from another thread.

My post was a few hours earlier  
Thanks Hans, yes it helped, as I was misunderstanding Jeanne's sentence, and not just for the logically word. Reading again the whole topic made it clear.
Anyway I still don't understand why my MainClass does compile but does not execute..
Hi Hugo,
I took me a while to understand it as well, and I think it's just a language misunderstanding.
In my language when a moment is behind another it means it's before the other.
In english "behind" means after.
Hello everybody! Almost finished with the Study Guide, and Chapter 14 was definitely the toughest one!

I have just two questions.

1)Why do that code throws an EOFException?

And this one not?

Is that the only way of obtaining an ObjcetOutput/InputStream? Aren't there any shortcut methods like Files.newBufferedReader(Path p)?

2) Are Collections Serializalbe?
List, Set and Map do not extend Serializable, but all of those implemetation do implement it (or most of them?). But all of the objects contained in those collection MUST implement Serializable. Is that correct? Is that on the exam?

I also think I've found two small errata in the textbook.

First one is on table 14.4, third line. The method "toAbsolutePath()" is not part of the Files class, and should be listed on table 14.3 as an instance method of class "Path".
The second is on the second code snippet above table 14.4:

Path method getName() needs an int parameter. I think it was instead intended the method getPathName().
Hello Albert,
I think the book is not saying that the value of "animals" is 3 for the fact that this is a do/while loop, but it's just remembering to the student how a do/while loop works.
Hi Tymo,
I'm studying on Jeanne&Scott's book, never worked as developer nor anything similar, trying to get ready for the certification in September.
Yes, the Practice Test book is all made of question&answers. How much is that important for the exam?
I think it depends on your previous knowledge of java and the way you want to study for the exam.
The Study Guide is REALLY exhaustive about any topic. It prepares you for all of the specifics classes, methods and commands that could be asked in the exam, giving you general explanation of every API or class you need to know. It also says often things like "you have to know that for the exam" or "the exam will try to trick you on that thing", etc.
For me is perfect, because otherwise it would be really difficult to choose what to focus on. Might be a bit boring for people using those APIs every day since a few years.
Tests are the best part, and in the Study Guide you get around 25 question per chapter, plus the online tests and flashcards. I still have to get to the end, but for what I see on the forum most people get prepared just with the Study Guide.

I think the book really worths the money.
Hope my experience can be helpful somehow!