• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet Request Listener Query

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ranchers,
Pls. consider the following code snippet taken from a tech web site.
I have two queries here:
(1) Is it a must to define the no-args default constructor explicitly? What's the harm if we rely on the Java compiler provided default constructor?

(2) Why do we need a static variable here. We know that there's just one copy of any static variable irrespective of inatances created. But, I wonder if there would be more than one instance of ReqListener class in any scenario.

Thanks,
Reema
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) No there is no harm in relying on the default, no-arg constructor.
Remember though, the default constructor is only created if no others exist.
If you create any other constructors, then you must, if you need one, explicitly create the no-arg constructor as well.

2) The amount of code posted is not enough for us to say for sure that only one instance of that listener is going to be created.
[ February 28, 2007: Message edited by: Ben Souther ]
 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben for the post.
Here's the complete code.


And just one <listener> tag in web.xml


I don't think we need static variable out there?
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anyone know the anwer for reema's Query?

Please Let me know.

Reema,

did you get the answer if so post it. am in need of the same.


Regards, Raghav
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think static is not needed here. There should be only one instance of this listener.
 
reply
    Bookmark Topic Watch Topic
  • New Topic