Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

public static void main(String agrs[])  RSS feed

 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java main() method is in which class?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is in whichever class you put it in

A Java application needs a main method to start. This is the interface the Java runtime uses to call into your code.
 
Piyush Porwal
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or what he means to say is: if you fire "java ClassName", ClassName should have this.
 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sturrock

It is in whichever class you put it in

A Java application needs a main method to start. This is the interface the Java runtime uses to call into your code.


Thank you Paul. I thought, main() is necessary to run the program, so it must me somewhere mentioned in bulit-in classes
 
Campbell Ritchie
Sheriff
Posts: 53720
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by minal silimkar:
Originally posted by Paul Sturrock


Thank you Paul. I thought, main() is necessary to run the program, so it must me somewhere mentioned in built-in classes
No, none of the built-in classes has a main method, because none of the built-in classes is designed as the starting point for an application. You write a class which starts off your application, and you write a main method for the JVM to start with.
 
Minal Silimkar-Urankar
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Campbell Ritchie

No, none of the built-in classes has a main method, because none of the built-in classes is designed as the starting point for an application. You write a class which starts off your application, and you write a main method for the JVM to start with.


Thank you Campbell, for detailed explaination.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!