File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt 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 "doubt" Watch "doubt" New topic


bani kaali
Ranch Hand

Joined: May 05, 2002
Posts: 42
can anyone pls tell me why we have to declare the main() method as static, taking a string array as an argument?
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

Because the Java Language Specification says so.
The method main must be declared public, static, and void. It must accept a single argument that is an array of strings.

[ July 12, 2002: Message edited by: Jessica Sant ]

- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Charu Murali
Ranch Hand

Joined: Jul 12, 2002
Posts: 37
A static method is the one that will be called with out craeting any objects. Since we need the main method to be called before any objects are created, it should be decalred as static.

I agree. Here's the link:
subject: doubt
It's not a secret anymore!