Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

After reading gnat's answer to Why a static main method in Java and C#, rather than a constructor? I take his answer to mean that the purpose of a Java class with a static main method is to define a program entry point and that it is not meant to be the program itself.

There may be a better way to do this, but I usually have the class with the static main method to do something simple like this:

public class MenuLauncher
{
    public static void main(String[] args) {
        Menu menu = new Menu();
        menu.run();
    }
}

Would the code above be the best practice for OOP where the class with static main doesn't do much more than launch or start program logic contained within a separate non-static object; after-all main is static so wouldn't the MenuLauncher class itself be very limited? Since main is a starting point I don't see any other purpose for the class other than to be a point of entry.

Is there a Java naming convention commonly used for classes that contain a main method and serve the purpose of being a program entry-point?

share|improve this question
1  
I usually call mine Program. –  Robert Harvey Aug 12 '13 at 21:45
1  
I call it Main and it's generally less than 20 lines long (with a bit of exception catching and parameter parsing). –  assylias Aug 12 '13 at 22:11
    
the last 5 I wrote were Test1, Test2, Test3, Test4, and Test5 :) Was writing some small tests and didn't want to spend time thinking up descriptive names as it was throwaway code anyway. –  jwenting Aug 13 '13 at 5:20
add comment

2 Answers

up vote 4 down vote accepted

No, there is no widely used naming conventions for this. Examples I have seen are Main, Application, XLauncher or X, where X is the name of the project/application.

And yes, I think it's good for this class to contain only the minimum logic/code necessary to set up the application and start it. But I'm sure there are a lot of God Objects and Big Balls of Mud out there with a main method tacked onto a multi thousand line monstrosity.

share|improve this answer
add comment

They are called the Main-Class, whether or not they are called Main and whether or not they do little or much.

They usually have the logic required for starting up the program.

In CLI apps they usually validate parameters.

In Desktop app they open a the main menu like yours or open the main window.

If you read the MANIFEST files in a jar file, you would find they are called that.

Manifest-Version: 1.0
Created-By: xxx
Built-By: xxx
Build-Jdk: 1.6.0_04
Main-Class: myPackage.MenuLauncher
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.