Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

attribute listeners!  RSS feed

 
ashok khetan
Ranch Hand
Posts: 153
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class that will recieve notification if an Attribute is added to or removed from a session will implement which interface?(From javaranch mock exam)
1) HttpSessionListener
2) HttpSessionObjectListener
3) HttpSessionAttributeListener
4) HttpSessionBindingListener

--> I think answer should be both 3) and 4), becos' HttpSessionAttributeListener has attributeAdded() and attributeRemoved() methods while HttpSessionBindingListener has valueBound() and valueUnbound() methods.Correct me if i am wrong.
ashok.

 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree.
They seem to do similar functions (?) except that HttpSessionAttributeListener has an "extra" attributeReplaced() method.
 
satish kolli
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are different..
One will notify the object(itself) when it is bound or unbound from session.
The other one will notify you when an attribute gets added/removed/replaced.
Check this link: http://www.javaranch.com/ubb/Forum18/HTML/000181.html
Thanks!
Satish Kolli, SCJP2
 
Gagan Indus
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Agree with Satish , they are indeed different.
So i guess ans should only be option 3)
( But if the question explicitly order " Choose 2" , then of course add option 4) as well )

------------------
Gagan (/^_^\) SCJP2
Die-hard JavaMonk -- little Java a day , keeps u going .
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah! Thanks!
"The devil is in the details..." AKA: I should read more carefully. Fatal flaw if not done at the exam!
 
Win Yu
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone give me some examples about: contextListener,contextAttributeListener,sessionListener,sessionAttributeListener.I could not find example on the books.
Thanks
 
Tim Duncan
Ranch Hand
Posts: 150
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!