This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!

Pablo Napoli

Ranch Hand
+ Follow
since Jun 28, 2019
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 Pablo Napoli

Thanks both for your attention! I whish next year take that exam and later I'd like get your new book ocp 11 to take, maybe on 2021, the other one.

Without your books I coulnd't have taken the OCA.

Cheers!, Pablo.
Thanks Jeanne!. Your example was very graphic.

By the way, because of personal motives I will have to move the date of my exam for later. I was expecting take it on December but I think it will be on March or April. So my question is when do you think OCP 8 will be removed by Oracle. Or if in other cases they did let people known with anticipation.

Thanks so much!
Hi guys. I'm studying for ocp8 exam from OCP study guide of jeanne and scott chapter 7 about Concurrency.

I'm gonna transcribe what the books says:
Given: service.scheduleAtFixedRate(command, 5, 1, TimeUnit.MINUTES);
This  example executes a Runnable task every minute, following an initial five-minute delay

One risk of using this method is the possibility a task could consistently take longer to run than the period between tasks.

Up to here what I understand is that for example in this case on the first minute a task is created and submitted and then it's gonna take 5 minutes to be executed. And in the minute number two ( while the first task is on delaying) another task is submitted and so on.

What would happen if the task consistently took five minutes to execute?

Despite the fact that the task is still running, the ScheduledExecutorService would submit a new task to be started every minute.

-> And now what I'm not understandying:

If a single thread executor was used, over time this would result in endless set tasks being scheduled, which would run back to back assuming that no other tasks were submitted to the ScheduledExecutorService.

Especially I can't totally undertand the following: "this would result in endless set tasks being scheduled, which would run back to back assuming that no other tasks were submitted"

I can guess that a stack of tasks would be piled up as if there was not every minute a new task being submitted.

I looked that I took literaly the exercise and what's going on is that I'm not shutting down the service.
Hi everyone!. I have a question about the exercise bellow that i coded of page 346 (jeanne and scott book) because result2 does not finish when i run it and I dont know why, being that the book does not specify it. Just, in order to make the test, I changed MINUTES by SECONDS for result2.

What the book says is: The first task is scheduled 10 seconds in the future, whereas the second task is scheduled 8 minutes in the future.

Hi Tim. Thank you so much for your reply. It was really interesting. If I should take some points about you said, I'd chose these:
* if you can recover, it's better to catch the exception, report it, repair it, and go on.

* Exactly where to deal with an exception is often the challenge.

* The best place to catch something is the highest level you can do something about it.

Now I'm studying the chapter Exceptions and assertions of Ocp study guide and in page 291 about using multi-catch it says: "It is common to log the error and convert it to a different exception type". And in the example it converts an Exception to a RuntimeException:
} catch(Exception e){
throw new RuntimeException(e);

Wouldn't it be a bad practice?. I mean, If i have an Exception is because it's about an important matter and as you said, I want to obligate the caller to deal with this issue. So making this conversion who is gonna call this method might not notice it until the exception happens. It's just my point of view according to what we were talking about.

Thanks mate!
Hi guys. I'm preparing my ocp certification (that also takes Exceptions topic) but I think is better to make the question here because it's more related with the basis of the topic.

I will try to explain myself with an example that I was thinking: It's common to use IlegalArgumentException in setter methods. So we can have a code snippet like the following:

So up to this point I figure, what if there is another programmer that will invoke setAge() method and cannot see the method's implementation with the IllegalArgumentException?. I mean, thinking in design, it would be better not to use any RuntimeException or turn it to a checked exception because what's the meaning of throwing an exception if you are not obligated to deal with that. In this case is not good ending the program just because someone made the mistake of passing an incorrect age. I'd prefer show a message to the user letting him/her know about what's going on. And to achieve that If I throw a checked exception I'm saying to the other programmer: "If this case happens, you have to let the user knows".

I'd like to know your opinion because I'm a bit confuse with this case. Anyway, if I'm right, what's the real meaning of unchecked exceptions?.

Yes, I got "black" too and I'm compiling with Java8. Maybe it does not appear on the website cause still nobody found this errata. But also is apparently wrong exercise 31.
Hi Ritchie. Yes, for both exercises, 31 and 32.

Hi guys. My answer was option B but in the book says D, Whereby I coded it and see that I was right. I will attach the diagram from question 31 where this exercise is based.

32. Given the snippets of resource bundles in question 31 from when we compiled the application, what is the result of the following?

Locale.setDefault(new Locale("en"));
ResourceBundle rb = ResourceBundle.getBundle("Buggy");

A. null
B. black
C. white
D. The code throws an exception at runtime.

Book's answer: D. Since no locale is specified, the code tries to find a bundle matching the default locale. Two resource bundles match the language English. The Java class one is used since it is present. However, it does not contain a key color , nor does its parent. Java does not allow looking in a properties file resource bundle once it has matched a Java
class resource bundle. Therefore, it throws a MissingResourceBundleException , and Option D is the answer.

Right answer: Option B.
Hi guys. This is a errata of the book OCA/OCP JAVA SE8 Programmer Practice Test by Jeanne and Scott.

Answer's book:
B. Since no locale is specified, the code tries to find a bundle matching the default locale. While none of the resource bundles match English United States, two do match the language English. The Java class one is used since it is present. Since the Java resource bundle for English doesn’t have a key wheels , we go up to the parent resource bundle. The default Java resource bundle does have the key wheels with the value 4 , so Option B is correct.

Right answer: Option C Because by not matching with for not having found the key "wheels", it will continue with (default locale is en_US) so in this file it can find that key and retrieves its value.

I checked it compiling it.
Hi everyone and sorry for the late reply. Yes, I was wrong with the code that I posted. The line that I wanted to show you should be: "public static <T> void make(List<? extends T> list){". So again I'm gonna paste the code below.

Error message: error: incompatible types: CAP#1 cannot be converted to Number
       for(Number n : list){
 where T is a type-variable:
   T extends Object declared in method <T>make(List<? extends T>)
 where CAP#1 is a fresh type-variable:
   CAP#1 extends T from capture of ? extends T
1 error

So what I want to say is:
1-  Test2.<Number>make(l); : I'm indicating that T should be taken as Number.

2- public static <T> void make(List<? extends T> list){ : As T is taken as Number, I could translate it as: public static <Number> void make(List<? extends Number> list){

3 for(Number n : list){ : I don't understand why it does not compile because I'm looping a List referring each element with a Number type.

So this is my question and I tried to be more clear than before.

Thanks again to all those who replied my post.
Hi guys. I'm reviewing my summaries from the chapter of generics of OCP Study Guide by Jeanne and Scott and pracicing some exercices I came up with the exercise below that I can't totally grasp why doesn't it compile.

The error message is:
error: incompatible types: CAP#1 cannot be converted to Number
for(Number n : list){
 where T is a type-variable:
   T extends Object declared in method <T>make(List<? extends T>)
 where CAP#1 is a fresh type-variable:
   CAP#1 extends T from capture of ? extends T

It's weird for me because here Test.<Number>make(l); I'm saying that T shoud be taken as Number and then here make(List<? extends T>) I say that the wildcard should extend Number so I don't know what's wrong with this for(Number n : list){.

If I change make(List<? extends T> by make(List<? extends Number> it does compile but in regards what I can "read" of the code at first it should compile.

Please, can someone show me what I'm not finding out?. Thanks as always!
Thanks guys for your replies!. They were very useful for me to understand that there is no a logical cause to this happens but it is rather a "design resolution". Anyway it could be something very tricky if OCP designers test try to play with this.

Anyway, I like to add my opnion. I think Java is not such a clear language about conversions between different types. I expose my thought because I'd like to know your opinion (you guys are like jedi masters for me) so if I'm wrong I could change it. But this is not the only case tht I've seen.
For instance, it's a tricky example that I could never clarify:

In this code it's possible getting a Double by the addition of n+d and then convert it to int.

But here I can't make the convertion:

For sure we can say that in the fist one we made an addition but anyway I think it's not clear because for different cases I cannot cast from a wrapper to a primitive.
Hi guys. I'm studying with the OCP Practice test book and from chapter 14 ex.30 I got a question related to DoubleToIntFunction.

Because I don't understand how is possible that a lambda implementing that functional interface can receives either Double or double (while the signature is applyAsInt​(double value) ) whereas with other functional interfaces you should to respect the input parameters from the lambda to match with the signature of the interface. For example:

On the other hand with DoubleToIntFunction: