• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doubt regarding a question in the final mock on hfsj

 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i just finished completing the final mock exam given in hfsj. i have a doubt in question number 55. it is as follows;

public class ServletX extends HttpServlet{

public void doGet(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException {
req.getSession().setAttribute("key",new X());
req.getSession().setAttribute("key",new X());
req.getSession().setAttribute("key","x");
req.getSession().removeAttribute("key");
}
}

public class X implements HttpSessionBinidingListener {
public void valueBound(HttpSessionBindingListener event){
System.out.println("B");
}
public void valueUnbound(HttpSessionBindingListener event){
System.out.println("UB");
}
}

which logging output would be generated by an invocation of the doGet method?

the answer given is - BBUBUB
but i think the answer should be only - BBUB
how come that last UB comes? i means when at the end you remove the attribute you are only removind an attribute who's value is onlya string and not an object of type X. so how come that UB part comes?


also i just finished the mock exam and scored 56/69. do you guys think this score would be enough for me to take on the real exam?

thank you in advance..
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the answer BBUBUB is right.

statement 1:req.getSession().setAttribute("key",new X());

object of X is bounded

statement 2:req.getSession().setAttribute("key",new X());

object of X is bounded and object of old X is unbounded(overwriting)

statement 3:req.getSession().setAttribute("key","x");

now key is refering String x.So object of X refered by key in statement 2 is again unbounded.

statement 4:req.getSession().removeAttribute("key");
listener wont be called since this is not an object of X

I hope this would clear your doubts...
Regards
Bala.
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dinuka Arseculeratne:


also i just finished the mock exam and scored 56/69. do you guys think this score would be enough for me to take on the real exam?



56 is great score.. I scored only 50
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you all for the clarification.
 
Won't you please? Please won't you be my neighbor? - Fred Rogers. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic