• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hey whats the deal with main() placement  RSS feed

 
bob von ilten
Greenhorn
Posts: 21
Linux Mac OS X MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just an opinion question.

It doesn't appear to matter to the app if main() is placed on top or on bottom or the class. I was used to seeing in listed first now I have run across a number classes with main() listed at the bottom of the class. Is this merely a personal pref or is there some rational behind it that I am missing?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just a method. Other than the precise signature (which the JVM is looking for) it's no different to any other method, so there are no particular rules about where it should appear.
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think whether putting the main() at the top or bottom of the class has any effect, the way you said. I think its all about readability and what you feel comfortable with, so its a personal preference (I think).



 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote: there are no particular rules about where it should appear.

Although, a company/employer may have a style guide that says where it should go, in which case you should follow its recommendation.
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I prefer to put the main method in a separate class, and I usually call it XXXDemo, but as everybody else has said, that is a personal preference.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!