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

doubt regarding a question in the final mock on hfsj

 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • 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..
 
Boobalan Pillai
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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.
 
Kishore Balla
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thank you all for the clarification.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic