• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

why static there?

 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why java designers at SUN decided that 'static'
should be there with 'public static void main(
String args[])?Why not without static
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
main()is a special method - it's an "entry point." That's what the JVM calls to start your program.
It's a simple, well defined execution start point. If you didn't make it static, that would mean the JVM would have to create an instance of your main-class before it could call the main() method, and this is not only more work, but less flexible because it has to make a lot of assumptions about your initial program state.
It's much simpler to have a well-defined static method that can be called without any class instances, and let the implementor of main() (the programmer) fill in all the little details about what to do one the user thread is executing .
reply
    Bookmark Topic Watch Topic
  • New Topic