Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q55 Mock Exam

 
Nikhil Jain
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • 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
 
Surendra Kumar
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want prompt response, please post the question also, though it's very long.
 
Saurabh Kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic