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

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.
6 months 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.

6 months 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?

7 months 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.
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.