File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ question on listeners Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ question on listeners" Watch "HFSJ question on listeners" New topic

HFSJ question on listeners

Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147

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







Answer is B.

I didn't understand how B is the answer.

When the first new X() is called it is "B" and when next new x() is called, the first value will be overwritten so it calls valueUnbound() that is "UB" and then valueBound() that is "B" and when it calls remove , it is "UB" .

Answer should be "BUBBUB".

someone please explain me how B is answer.

Abdul Rahman
Ranch Hand

Joined: Jul 04, 2008
Posts: 63
Hi Archana,

on execution of line 15, HttpSessionBindingListener's valueBound() is called. Hence output is B.
on execution of line 16, HttpSessionBindingListener's valueBound() and valueUnboound() is called. Hence output is BUB.
on execution of line 17, HttpSessionBindingListener's valueUnbound() is called. Hence UB. valueBound() is not called since X is not bound to the session.
on execution of line 18, HttpSessionBindingListener's valueUnbound() is not called because the X has already been unbound in line16.

so the output generated is BBUBUB.
Remember that the valueBound() is called first then valueUnbound() is called. This is contrary to the common belief that the vice-versa happens.
hope this explains your query.

SCJP5, SCWCD5, [scwcd wall of fame]
Ranjit Gopinathan
Ranch Hand

Joined: Jul 03, 2007
Posts: 46
When I executed the example the answer was BBUBUB.

The attribute replacement sequence may be like , new value is Bound and due to that the old value gets Unbound.

This is not an accurate answer to your question. Somebody with more knowledge can throw some light on this.

Edit : Abdul Rahman answered it better. I didnt see his reply when I was replying.
Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
Thank You Abdul Rahman . I makes perfect sense now.

I agree. Here's the link:
subject: HFSJ question on listeners
jQuery in Action, 3rd edition