• 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
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

java

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why we use static in public static void main(string arr[])?
 
Master Rancher
Posts: 4818
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When the java command starts a program, it needs a FIXed way to call it.
By making main() static, it can call main() and let main() do what is needed to instantiate the class and get it started.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
.. because the main{String []args)method has to be called by OS.So in order to make it possible for OS to access it without creating the instance of the class, containing the main(String []args)method,it is declared static.
 
Sheriff
Posts: 67650
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
"J new", please check your private messages for a final important administrative matter.
[ June 27, 2008: Message edited by: Bear Bibeault ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
siddharth, welcome to JavaRanch.

Please use a meaningful subject line when you post a question, instead of a title like "java". A better title would have been, for example: "Why is main() static?".

To answer your question: It's really just a design decision by the people who invented the Java language.

By making main() static, the JVM doesn't have to instantiate the class that the method is in to be able to call it - which makes starting a program simpler.
[ June 27, 2008: Message edited by: Jesper Young ]
reply
    Bookmark Topic Watch Topic
  • New Topic