Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the convention for java package names without a domain association?

I can't find a Q/A on SO that answers my exact question, so I figure I'd post it and see what comes back.

As far as the naming convention goes for Java packages, I understand that it's supposed to be the reverse domain name: com.whatever.stuff and I get the rules about no mixed case, hyphens, keywords, etc.

I've also read section 7.7 (Unique-Package-Names) of the Java Language Specification. As far as I can tell, the rules from Java are to use the reverse domain to insure uniqueness... and if you don't have one, go get one:

You form a unique package name by first having (or belonging to an organization that has) an Internet domainname, such as sun.com. - Section 7.7

So if I'm not interested in shelling out the money for a domain name, I don't belong to a company whose name I can piggyback off of, is there any part of the naming convention that I'm missing that should be followed? I'm thinking I can just go name it whatever unique name I feel like at this point, but I was just wondering if I was missing anything.

Note: I would like to release my package for other developers to use, so I didn’t want to just do something that worked on my system, but something more standard if possible.

I added the android tag because the java packages I'm going to be writing are going to be used in an Android application, wasn't sure if there were different opinions from android developers.

like image 956
Mike Avatar asked Sep 21 '12 18:09

Mike


People also ask

What is the naming convention for packages in Java?

Naming ConventionsPackage names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example, com. example. mypackage for a package named mypackage created by a programmer at example.com .

Should Java package names be CamelCase?

The standard Java naming convention demands that all reference types be written in PascalCase, also known as upper camel case.

What are the two naming conventions in Java?

CamelCase (also known as Upper CamelCase) is where each new word begins with a capital letter (e.g., CamelCase, CustomerAccount, PlayingCard). Mixed case (also known as Lower CamelCase) is the same as CamelCase except the first letter of the name is in lowercase (e.g., hasChildren, customerFirstName, customerLastName).

Why do package names start with com?

Generally we android developer having practice to decide package name based on the domain name of a particular company. For example: Domain name: sun.com => Root package name something like : com. sun.


1 Answers

If you are going to be distributing a lot of stuff, I would really suggest getting a domain name. Another alternative however would be to use your e-mail: e.g. [email protected] would become com.gmail.bob. This is less common than using domain names but is still done by some and still ensures uniqueness.

like image 119
arshajii Avatar answered Oct 12 '22 10:10

arshajii