GeeCON Prague 2014*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes HFSJ Mock Exam Question 55 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 Mock Exam Question 55" Watch "HFSJ Mock Exam Question 55" New topic
Author

HFSJ Mock Exam Question 55

julius hock
Greenhorn

Joined: Apr 06, 2006
Posts: 7
I'm wondering what is the different between
setAttribute("key", new X()); //print "B"
setAttribute("key", "x") // print "UB";
Question 55.
15. req.getSession().setAttribute("key", new X());
16. req.getSession().setAttribute("key", new X());
17. req.getSession().setAttribute("key", "x");
18. req.getSession().removeAttribute("key");

public void valueBound(HttpSessionBindingEvent event){
System.out.println("B");
}

public void valueUnbound(HttpSessionBindingEvent event){
System.out.println("UB");
}

Answer: B. BBUBUB


Any help would be much appreciated.
Adam Czysciak
Ranch Hand

Joined: Feb 25, 2005
Posts: 82
I'm wondering what is the different between
setAttribute("key", new X()); //print "B"
setAttribute("key", "x") // print "UB";
Question 55.
15. req.getSession().setAttribute("key", new X());
16. req.getSession().setAttribute("key", new X());
17. req.getSession().setAttribute("key", "x");
18. req.getSession().removeAttribute("key");
}
Answer: B. BBUBUB

The B/UB are printed only for elements of class X. "x" is a String... So:
15. new X() is created, prints "B"
16. another X() object is created and bound to session, so "B" is printed. But previous object created in line 15 is removed, so "UB" is printed too.
17. it removes object put in line 16 (so prints "UB") and inserts String object, so nothing more is printed.

So, it prints BBUBUB.

BTW: Personally for me it would be more logical that it prints BUBBUB (eg line 16 should first unbound previous object and then bound new object). But BBUBUB was the only answer that could fit for me while answering this question. And no - I didn't check it


Adam<br /> <br /><i>SCJA, SCJP 5.0, SCWCD 1.4, SCBCD 5, SCEA 5</i>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HFSJ Mock Exam Question 55