• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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: 67750
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.
 
Joel Salatin has signs on his property that say "Trespassers will be Impressed!" Impressive tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic