简体   繁体   English

main()方法的Java类的包约定

[英]package convention for main() method`s Java class

I am building an standalone Java application. 我正在构建一个独立的Java应用程序。

In that, i have to use the class with main() method. 在那,我必须使用main()方法的类。 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, 我的问题是,

  • are above package name for given purpose making sense ? 是否有特定用途的包装名称有意义? if not then any suggestions? 如果不是那么任何建议?
  • is there standard for naming this ? 是否有标准来命名这个?

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'. 当我使用主类创建项目时,我通常将它放在应用程序“com.acmeglobal.killerapplication”的最顶层包中,并给它一个简单的名称,如“App”,“Main”或“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. 在您建议的软件包名称中,我更喜欢'main',在'init'或'initialization'之后,尽管我认为初始化不应该是主类的关注点。 The package called 'server' seems misleading to me because it suggests that there is also a client, which I don't think you intended. 名为“服务器”的软件包对我来说似乎有误导性,因为它表明还有一个客户端,我认为你并不打算这样做。

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. 如果main只包含Main类,那么合并main和init对我来说也没问题。

is there standard for naming this ? 是否有标准来命名这个?

No. 没有。

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 . 因此,如果公司Acme有域名www.acmeglobal.com他们的包结构将以com.acmeglobal为前缀而不是com.acme

Adhering to this standard reduces the likelihood of developers creating colliding classes. 遵守此标准可降低开发人员创建冲突类的可能性。

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. 如果将代码放在适当的包结构中,那么将来有助于维护并提高可读性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM