• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class named main?

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm an intermediate java developer, I have seen a couple of code examples out there where they named their class 'main' instead of just having a main method.

Have you seen this? What method would be the main one in a main class?
 
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The name of a class has no effect on its behavior. It is however considered good style to capitalise the first character of a class name, so "Main" would be preferred over "main".
 
osgaldor Storm
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I do understand that, but my question is more about how to identify the main method in a class named Main.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

osgaldor Storm wrote:Thank you. I do understand that, but my question is more about how to identify the main method in a class named Main.



Short answer. The main() method takes a String array for parameters, and is public, static, and returns a void.

Longer answer. Assuming that you mean the location of the main method of the application, then that would depends on how the application is executed. If a starting class file is specified, then that is the class where the main() method is. If a starting jar file is specified, then the main() method is in a class in that jar file. And the class in that jar file is determined by the manifest file.

Henry
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You identify the main method in any class, whatever its name, by its signature:



Note that not all classes have to have a main method like that, only those which are intended to be run from the command line or some similar technique.
 
Tim Cooke
Sheriff
Posts: 5555
326
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly the same as you would in a class of any other name.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

osgaldor Storm wrote:Have you seen this? What method would be the main one in a main class?


As everyone has already said: Main.main().

I'd just add that personally, I really don't like the idea of calling a class Main, because it doesn't have any meaning. Main what?

Winston
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It happens if you use NetBeans; that tends automatically to create a class called Main to incorporate the main method.
reply
    Bookmark Topic Watch Topic
  • New Topic