File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "HFSJ question on listeners" Watch "HFSJ question on listeners" New topic
Author

HFSJ question on listeners

Archana Annamaneni
Ranch Hand

Joined: Jan 29, 2003
Posts: 147
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

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.


Abdul
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.

Archana
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFSJ question on listeners