This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes why static there? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why static there?" Watch "why static there?" New topic
Author

why static there?

Anuji Philip
Ranch Hand

Joined: Feb 25, 2002
Posts: 46
why java designers at SUN decided that 'static'
should be there with 'public static void main(
String args[])?Why not without static
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
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 .


Rob
SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why static there?