This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Doubt in HFSJ Mock Exam Question 55 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Doubt in HFSJ Mock Exam Question 55" Watch "Doubt in HFSJ Mock Exam Question 55" New topic
Author

Doubt in HFSJ Mock Exam Question 55

Yoshita Jain
Greenhorn

Joined: Sep 15, 2007
Posts: 23
Hi folks,

Another doubt in HFSJ :

Here's a snippet similar to the Question 55: (pg 790,828)


session.setAttribute("dab", new DealerAddrBean());
session.setAttribute("dab", new DealerAddrBean());
session.setAttribute("dab","x");
session.removeAttribute("dab");



The DealerAddrBean class implements HttpSessionBindingListener

public class DealerAddrBean implements HttpSessionBindingListener

{

public void valueBound(HttpSessionBindingEvent hsbe)
{
System.out.print("B");

}

public void valueUnbound(HttpSessionBindingEvent hsbe)
{
System.out.print("UB");

}

}


The result I get is BUBBUB

The HFSJ answer is BBUBUB (the closest one)

I am fairly confident that the extra 'B' is an error.
However I'd like you guys to confirm that.

(The third setAttribute is Simply setting a string.. so we can't expect the listener to be called for that)

Thanks & Regards,

Yoshita
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
with different web containers you get a different sequence of events, but regardless of which container you will have 2 binds and 2 unbinds happen.

Whatever answer you choose has to have these 4 events accounted for. that is why the "extra B" is not extra at all.

Try coding it in your web container and see which answer you get.
Swathi Sri
Greenhorn

Joined: Jan 18, 2007
Posts: 22
Hi,

correct answer is "BUBBUB"

First B: for session.setAttribute("dab", new DealerAddrBean());

Next UB-> B: for session.setAttribute("dab", new DealerAddrBean());
As it is replacing the same attribute dab..

Next UB: for session.setAttribute("dab","x");
As it is removing existing DealerAddrBean (Unbind is called). Since it is not binding DealerAddrBean but its placing a string, no valueBound method is called.

session.removeAttribute("dab"); is not printing anything because it is removing attribute where value is String.. and it does not have valueUnbound() method.

Hope this helps you.

Regards,
Swathi.
Yoshita Jain
Greenhorn

Joined: Sep 15, 2007
Posts: 23
Hi,

Swathi, yes thanks... that helps... that is in keeping with the answer I got when I tried it out.

Got you point Michael. Thanks a ton. (Guess I'm seeing double these days )I tried this using RAD and got BUBBUB.

Hmm So this is container dependent too....

Regards,
Yoshita
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Run it on Tomcat (which the book assumes that you do) and it comes out BBUBUB
Abhishek Pratap
Ranch Hand

Joined: Apr 14, 2006
Posts: 43
This is definately container dependent. even i posted the same few days back...

it says that always Bound happens First and then unbound. if the value is replaced than first the new Value is Bound and then old Value is Unbound.
Logically it doesn't seems to be the correct sequence but actually its like that.
for example:
if session is invalidated the sessionDestroyed of HttpSesssionListener is called first and after that valueUnbound of HttpBindingListener is called.

As per my perception the listeners are called earlier than the actual object is removed or added or replaced internally. thats y the sequence is irregular.

Hope this will help you.
Yoshita Jain
Greenhorn

Joined: Sep 15, 2007
Posts: 23
Thanks Abhishek.
naresh govindaswmay
Ranch Hand

Joined: Aug 15, 2007
Posts: 90
hi,
i could not get the answer in the posted question.please any body help me out for this question.

Thanks and regards
naresh govindaswamy


Thanks and Regards<br />Naresh govindaswamy
Ssr Shankarraj
Greenhorn

Joined: Nov 06, 2007
Posts: 1
Hi all,

for the above question the answer given in HFSJ is correct i verified the same. its like even when you replace also it first call valueBound and then the valueUnbound method.


if there is any syntax or typing error please forgive me this the first time i am entering and replying ....
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 483

Hi all

session.setAttribute("dab", new DealerAddrBean());
session.setAttribute("dab", new DealerAddrBean());
session.setAttribute("dab","x");
session.removeAttribute("dab");



The DealerAddrBean class implements HttpSessionBindingListener

public class DealerAddrBean implements HttpSessionBindingListener

{

public void valueBound(HttpSessionBindingEvent hsbe)
{
System.out.print("B");

}

public void valueUnbound(HttpSessionBindingEvent hsbe)
{
System.out.print("UB");

}


the simplest rule here that we got 2 DealerAddrBean objects & 1 String object , so the listener will work ONLY for the 2 DealerAddrBean objects, so when first time the obj bounded it will print "B" , same as second time , when the obj unbounded it will priint "UB", as we got 2 objects so it will be printed twice , So the finally nswer is : BBUBUB


Thanks,
Sherif
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in HFSJ Mock Exam Question 55