Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
4. Here come my Problem: 4. req.getSession().removeAttribute("key");
Now the key is having the string, I am removing it from the session. key is now holding the string, not an object, the how valueUnbound() is called..
saivenumadhav
Originally posted by Ali Gohar:
I am really surprised to hear this from a SCJP. If you recall String is an object
Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
saivenumadhav
After this method executes, and if the new object implements HttpSessionBindingListener, the container calls HttpSessionBindingListener.valueBound. The container then notifies any HttpSessionAttributeListeners in the web application.
If an object was already bound to this session of this name that implements HttpSessionBindingListener, its HttpSessionBindingListener.valueUnbound method is called.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Originally posted by Micheal John:
Your explanation is clear. Thanks a lot!!
Originally posted by Micheal John:
1. req.getSession().setAttribute("key", new X());
A new object X is added into the session, and the object X is also implementing HttpSessionBindingListener..so valueBound() is invoked..so it prints B
2. req.getSession().setAttribute("key", new X());
A new object X is now replacing the old one into the session, and hence new object is added/replaced once again, valueBound() is invoked..so it prints B
3. req.getSession().setAttribute("key", "x");
A new string object "x" is now replacing the old object X..and the object X is implementing HttpSessionBindingListener.. that is why the valueUnBound is invoked..so it prints UB
Problematic Area:
4. req.getSession().removeAttribute("key");
Now the key is holding the string object "x", but the String class is not implemeting the HttpSessionBindingListener, then how valueUnbound is invoked?
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
|