• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

static with main

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everybody
i am new in the field of java. i want to know why we use static with main (public static void main)
thanks
Banti Goyal
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By declaring the method "main" as a static method, it does not act upon an instance of the class. In other words, you don't have to have an object created to use the main method. Obviously, it would be hard to create an object (an instance of the class) before the program starts.
That's how I rationalize in my mind the reason for declaring the main method as static.
 
Sheriff
Posts: 9099
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, Sun has declared that main() should have this signature:
public static void main( String[] args ). If you use the wrong signature, there is a high probability that your program will not run because the JVM will not be able to find the main() method, and therefore will not be able to start the application.

Marilyn
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!