wood burning stoves 2.0
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "why static there?" Watch "why static there?" New topic

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

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 .

SCJP 1.4
I agree. Here's the link: http://aspose.com/file-tools
subject: why static there?
It's not a secret anymore!