ajduke
ajduke

Reputation: 5057

package convention for main() method`s Java class

I am building an standalone Java application.

In that, i have to use the class with main() method. As this is the class where all execution begins, i usually place in one of package structure

com.<company-name>.<project-name>.init
com.<company-name>.<project-name>.main
com.<company-name>.<project-name>.server
com.<company-name>.<project-name>.initializer

My Question is,

Upvotes: 2

Views: 14146

Answers (4)

Adriaan Koster
Adriaan Koster

Reputation: 16209

When I create a project with a main class I usually put it in the topmost package of the application 'com.acmeglobal.killerapplication' and give it a simple name like 'App', 'Main' or 'Start'.

I try to keep my main class as small as possible; it only bootstraps the application. If parsing of application arguments is even slightly nontrivial I even create a separate class for that.

Of your suggested package names I prefer 'main', after that either 'init' or 'initialization' although I think initialization should not be the concern of the main class. The package called 'server' seems misleading to me because it suggests that there is also a client, which I don't think you intended.

Upvotes: 5

G.S
G.S

Reputation: 10881

Defining package structure is for your own use. If you place your code in proper package structure then it will help in future for maintenance and increase the readability.

Upvotes: 0

Kevin Bowersox
Kevin Bowersox

Reputation: 94499

The packages you suggest look fine, but just to be thorough they should be prefixed with the domain name in reverse. So if the company Acme has domain www.acmeglobal.com their package structure would be prefixed with com.acmeglobal instead of com.acme.

Adhering to this standard reduces the likelihood of developers creating colliding classes.

Upvotes: 1

StarPinkER
StarPinkER

Reputation: 14271

are above package name for given purpose making sense ? if not then any suggestions?

I think it make sense. Merging main and init is also fine for me if your main only contains the Main class.

is there standard for naming this ?

No.

Upvotes: 2

Related Questions