• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

context and static parameters

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyboby tell me is there any difference between static and context variables? In the sense like : static variables are shared among objects, and context variables are shared among the servlets objects.


THANKS !!!
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

static variables are shared among objects, and context variables are shared among the servlets objects.



I think there is some confusion here.
When we say static variables, it means that instances of that class do not have separate copies of that variable.
And there is no such thing as context variables, there are either context parameters or context attributes. The word context only specifies the scope and the life of the parameter or attribute.


Can anyboby tell me is there any difference between static and context variables?


Now can you reframe the above question so that it becomes more clear what exactly you want to know.
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

static variables are shared among objects



Yes. When you define a static variable it belongs to class/interface it is defined. So no matter how many objects you created (in case of class) you get same value for all the instances. You could access static variable even without an instance (like ClassName/InterfaceName.Variablename).

and context variables are shared among the servlets objects.



Actually that's refered as Context Parameters, and yes they are shared by the web app which those parameters defined (those parameters are defined in web.xml and will bound to ServletContext at the deploy time/when the server restarts.).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic