| Author |
Main class naming convention
|
B West
Greenhorn
Joined: Oct 10, 2008
Posts: 29
|
|
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
Joined: Mar 30, 2007
Posts: 46
|
|
you can use any name ....which suits your application [ October 20, 2008: Message edited by: jittu goud ]
|
 |
B West
Greenhorn
Joined: Oct 10, 2008
Posts: 29
|
|
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
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
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
Joined: Jul 26, 2007
Posts: 8439
|
|
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
|
[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
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.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Maneesh Godbole
Saloon Keeper
Joined: Jul 26, 2007
Posts: 8439
|
|
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
Joined: Oct 13, 2005
Posts: 32694
|
|
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
Joined: Jul 26, 2007
Posts: 8439
|
|
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
Joined: Oct 10, 2008
Posts: 29
|
|
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
Joined: Jul 08, 2003
Posts: 24057
|
|
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".
|
[Jess in Action][AskingGoodQuestions]
|
 |
B West
Greenhorn
Joined: Oct 10, 2008
Posts: 29
|
|
Thank you for all your replies. I will use the name of main. Thanks everybody! bw
|
 |
 |
|
|
subject: Main class naming convention
|
|
|