Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Main class naming convention

 
B West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

My problem is I'm not sure what to name the main method. I'm wondering if there is any kind of naming convention regarding main classes. The main methods main function is to just call all the other class relavent to the function of the application. So I'm kind of stuck wondering what to name the thing.

Anybody have any suggestions.

Thanks in advance..
 
jittu goud
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use any name ....which suits your application
[ October 20, 2008: Message edited by: jittu goud ]
 
B West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, and thank you for your reply. I understand that you can use any name, however is there any kind of standard that is applied here? If there isn't then fine, but I'd like to stay with convention if possible.


Again Thanks for your reply!

BW..
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The convention is to give the class a name which describes its purpose, or its function. What it does, or what it is. If your class is solely there to create some objects of other classes and call a method which runs until it's stopped -- this is common in GUI-based programs -- then I don't think it would be unreasonable to call the class "Main".
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Jittu said, you can practically use anything that takes your fancy.
Personally, I follow a few basic rules for my own convenience.

1) The main class should reflect the project name. e.g. I have a main class called "DiskMonitor".
2) Prefix all class names with a project code abbreviation. In this case "DM"
3) The names should be self explanatory. If I got a class called DMTableModel, it is pretty obvious that this is a custom table model.
3) Prefix all interface names with an I. e.g. IDMConstants

So much for the class naming conventions. However, on the other hand, there are coding conventions, which are quite elaborate, and should be really followed by all coders.
Here is a nice article which might interest you.
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
 
Rob Spoor
Sheriff
Pie
Posts: 20531
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maneesh Godbole:
2) Prefix all class names with a project code abbreviation. In this case "DM"

That's where I disagree. For your DMTableModel it makes sense because TableModel is the name of the interface you are implementing, but if such a thing is not necessary then I'd just let the package name make the distinction.

Of course that's all just a matter of opinion.
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rob Prime:

That's where I disagree.


Hehehe.
I was waiting for this from someone.
But like you said, its a matter of opinion.
[ October 21, 2008: Message edited by: Maneesh Godbole ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Maneesh Godbole:
But like you said, its a matter of opinion.


But I think Rob's opinion is correct
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Campbell Ritchie:

But I think Rob's opinion is correct


That was to be expected as both of you are ganging up on me
 
B West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your reply. I've seen where programmers also stick test on the end of the main class. Is this common as well?

Again thank to all who replied!

BW
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by B West:
Thank you all for your reply. I've seen where programmers also stick test on the end of the main class. Is this common as well?


A class named XXXTest is not supposed to be a "real" main class for an application; it's supposed to be a test or example program.

As was pointed out earlier "Main" is a perfectly good and common name for the entry-point class for an application; the package name lets you distinguish between the many classes named "Main".
 
B West
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for all your replies. I will use the name of main.

Thanks everybody!
bw
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic