• 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

Q55 Mock Exam

 
Ranch Hand
Posts: 393
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys I have 2 questions

1. What is the logic behind the answer BBUBUB in Q55 of coffee cram exam. Sorry the question is too long to type out..

req.getSession.setAttribute("key", new x());
req.getSession.setAttribute("key", new x());
req.getSession.setAttribute("key", "x");
req.getSession.removeAttribute("key", new x());

Code in the class that implements HttpBindingListener
public class X implmenets HttpBindingListener {
valueBound() {
System.out.println("B");
}

valueUnBound() {
System.out.println("UB");

}
}
2. Is there any <description> tag in <listener/> tag.. One of the question in the coffee cram exam has the aboove question
 
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you want prompt response, please post the question also, though it's very long.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For ques 1:
Referring to Servlet spec.

If an object of the same name is already bound to the session, the object is replaced.
After this method executes, and if the new object implements HttpSessionBindingListener, the container calls HttpSessionBindingListener.valueBound. The container then notifies any HttpSessionAttributeListeners in the web application.

If an object was already bound to this session of this name that implements HttpSessionBindingListener, its HttpSessionBindingListener.valueUnbound method is called.



Now here is how it goes:

req.getSession.setAttribute("key", new x());
calls valueBound()
req.getSession.setAttribute("key", new x());
calls ValueBound()

The tricky part goes here:
req.getSession.setAttribute("key", "x");
calls valueUnbound()

An object implementing HttpSessionBindingListener (new X()) was bound to name "key" previously, and now an String object "x"(not implementing the interface) is being bound to name "key", the container will call HttpSessionBindingListener.valueUnbound method on new X() obj(which was bound to name "key").

req.getSession.removeAttribute("key", new x());
calls valueUnbound()


This is best to my understanding, please correct me if I am wrong.

Thanks and regards,
Saurabh Kumar
 
reply
    Bookmark Topic Watch Topic
  • New Topic