• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HFSJ question on listeners

 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given:



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

A. UBUBUB

B. BBUBUB

C. BBUBUBB

D. BUBBUBB

E. BBUBUBBUB

F. BBUBBUBBUB


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.


Archana
 
Abdul Rahman
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranjit Gopinathan
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You Abdul Rahman . I makes perfect sense now.

Archana
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic