• 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

does variable declared in declaration automatically become static

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was going through head first servlets & jsp book on page no 295.

I came across this example, in which count is initialized in expression now count is incremented by one. Next time it comes in the loop, it again is assigned with zero. Since the variable declared in expression becomes local variable.

Now the same variable count is declared in declaration. So it becomes class variable. Now this variable count is accessed in the local method. Now the question is how can a variable be initialized at class level , unless its a static variable. The variable show in example is not declared as static (As its in a servlet which is derived from jsp page). So does a variable declared in declaration automatically become static ?

thanks
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. It becomes an instance variable of the generated servlet. But since many threads my share this same servlet, this is a dangerous thing to do.

All scriptlets, including declarations, should no longer be used in JSPs. It's much safer to use modenr JSTL and EL mechanisms.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic