SCJP 1.4<br />SCWCD 1.4(91%)<br />Working on SCJD -Bodgitt & Scrapper Constructions...<br /> <br />"It takes 43 muscles to frown & 17 to smile but it doen't take any to just sit there with a dumb look on your face .. Keep Smiling "
The only point important here is that when you replace a value of a attribute, only valueUnbound() is called.
puneet
God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
SCJP 1.4<br />SCWCD 1.4(91%)<br />Working on SCJD -Bodgitt & Scrapper Constructions...<br /> <br />"It takes 43 muscles to frown & 17 to smile but it doen't take any to just sit there with a dumb look on your face .. Keep Smiling "
I think it is quite clear, line 15 and 16 add two attributes, so valueBound() method is called, which prints B couple of times.
With line 17 you replace a value in the attribute, so valueUnbound is called, and it prints UB.
With line 18 you remove the attribute, and so UB gets printed.
The only point important here is that when you replace a value of a attribute, only valueUnbound() is called.
[/QB]
Adam
SCJA, SCJP 5.0, SCWCD 1.4, SCBCD 5, SCEA 5
God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Originally posted by Bhavik Patel:
15. req.getSession().setAttribute("key", new X());
16. req.getSession().setAttribute("key", new X());
17. req.getSession().setAttribute("key", "x");
18. req.getSession().removeAttribute("key");
public void valueBound(HttpSessionBindingEvent event){
System.out.println("B");
}
public void valueUnbound(HttpSessionBindingEvent event){
System.out.println("UB");
}
answer is BBUBUB
Please explain me ...i have gone through other threads but its not clear enough..thanks
God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
req.getSession().setAttribute("key", new X()) - Wil print B
req.getSession().setAttribute("key", new X());-Wil print UBB
req.getSession().setAttribute("key", "x"); - No effect here,coz 'x' is not an object of this class.
req.getSession().removeAttribute("key") - Wil print UB
Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Originally posted by Vinod Ennes:
public class Binding extends HttpServlet implements HttpSessionBindingListener
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
request.getSession().setAttribute("name",new Binding());
request.getSession().setAttribute("name",new Binding());
}
public void valueBound(HttpSessionBindingEvent event)
{
System.out.println("VALUE BOUND");
}
public void valueUnbound(HttpSessionBindingEvent event)
{
System.out.println("VALUE UNBOUND");
}
}
Below is my output.
VALUE BOUND
VALUE UNBOUND
VALUE BOUND
Can anyone explain this?
Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Originally posted by Bhavik Patel:
15. req.getSession().setAttribute("key", new X());
16. req.getSession().setAttribute("key", new X());
17. req.getSession().setAttribute("key", "x");
18. req.getSession().removeAttribute("key");
public void valueBound(HttpSessionBindingEvent event){
System.out.println("B");
}
public void valueUnbound(HttpSessionBindingEvent event){
System.out.println("UB");
}
answer is BBUBUB
Please explain me ...i have gone through other threads but its not clear enough..thanks
God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Originally posted by Narendra Dhande:
Hi,
Yes, What is the problem with this answer ? Can you figure out.
Thanks
God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Regards,<br />Deepti.
Regards,<br />Deepti.
God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
SCJP (1.4)
when you really want something, all the universe always conspires in your favour.<br /> <br />SCJP1.5-77%<br />SCWCD-89%
Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Don't get me started about those stupid light bulbs. |