• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

HFSJ question on listeners

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank You Abdul Rahman . I makes perfect sense now.

Archana
 
Skool. Stay in. Smartness. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic