首页 > 解决方案 > Java package naming when domain and app name are the same

问题描述

I'm curious about best practices around Java package naming when the domain name and the class name would be the same.

For example, if I am creating a new android app called Foo and my domain is foo.com

The java package name would be

com.foo.foo

correct?

Is there a better way to name it or am I overthinking this?

标签: javaandroid

解决方案


the convention is always

domain.domainname.package[.subpackage].Class

(where subpackage is optional). The goal is to have a unique namespace for each project, to avoid namespace collisions, so shortening it is not a good idea.

to answer your question: com.foo.foo is a correct name if the second foo is the name of your project. if this project now contained a class Bar, the path would be com.foo.foo.Bar.


推荐阅读