Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP 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

Hi guys. First off, thanks for you replies. Happens that the real code doesn't have those strings. Instead it has respose = repository.[query]. So I'd like to find a way to avoid those nested if else-if statements. I think it could be done by using lambdas along with maps but all I was trying was unsuccessful.
1 day ago
Given this code:

I'd like to replace those nested if with something related with Optional. I've seen this in case we deal with one parameter but in case of having the && operator I don't know how to do it.

1 day ago
Hi everyone. Some time ago I started reading Effective Java book and some of its items put more doubts on me than before I had. This is the case of Item 17 that says: "Classes should be immutable unless there’s a very good reason to make them mutable.". It's crazy for me because in my daily work I've never tend to use immutables over mutables and I've never seen before this practice in the codes I've worked with. For example, if I should deal with an entity User class that is populated by Hibernate annotations I don't make it immutable or in case or creating a service class, the same.
Rather my idea about immutables is that you can use them for such classes like a utility class or objects that don't use to change.

I'd like to know your point of view to know how much this book is right.

3 weeks ago
Hi guys. Last year I gave the OCA certification and during this year it was difficult for me to prepare the OCP but I'd like to have the goal of passing the OCP in 2021. I'd like OCP because I've already bought the books from Jeanne.

Thank you guys for your replies. They were very helpful for me because in the book from were I'm studying it's not so clear. On the other side, I first decided to learn JavaEE before learning Spring Framework because I think that in the long term is the best way to go through. Anyway I met guys who didn't know what's a Servlet and they were working with different Frameworks like Struts.

So just to show you that I really took into consideration your replies I want to share with you my summary of your replies:

- Objects in a JEE webapp can be stored in one of 4 scopes:
* Application scope:
* Application scope is what's stored in the Map for web ApplicationContext.

* If you want to store information which belongs to the whole application, you put in into the web context.

* Session scope:
* Session scope is what's stored in the Map for HttpSession.

* If you want to store information which relates to a user's session, you put in into the session.

* Request scope:
* Is carried along with the current HttpServletRequest.

* If you want to store information which relates specifically to the servlet, you put into the servlet context.

* Page scope (is an artefact of JSPs) : Is really just local variables in the servlet that gets compiled from a JSP

-> JavaServer Faces adds some extra scopes, but they're based mostly off session scope.

-> Of course the three things have similar features because they are all for the purpose of storing data which arises at run time.

Cheers!, Pablo.
1 year ago
Hi everyone. I know for example that a session is a set of requests made from the same browser to the same webapp in a certain time and it allows to identify an user (it's necessary because of HTTP is stateless). But what I see is that both of them have similar behaviour. For example, I can hold data structures either in a session by httpSessionEvent.getSession().setAttribute() method or in a servletContextEvent.setAttribute() method.

1. Maybe the big difference that I've found so far is that WebContext is shared by all of the threads while a Session is unique by every thread of the servlet instance created by the container.

2. Another thing what I'm not really sure is that when the webapp is deployed by the servet the context is created in that moment, while a session is first created when a request comes to the webapp.

I'm really interested to see guys your point of view because I was looking in google and I didn't find any good answer to my doubt.

1 year ago
Hi guys. Im learning javaee so i saw an example in a book but it's not well described.

I have a project in Eclipse running on Tomcat with an index.html file who inside has a web form:

-> This file is on the root level: ../jee7_book_workspace/ej03_ch2/index.html

And this is the code of my servlet (I hid imports):

And I tried with a lot of different codes within the web.xml but neither worked.
-> This was my last try:

So, can someone psl give me a hand with the right web.xml?

1 year ago
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.