how should one seperate words in package names
- com.stackoverflow.my_package (underscore)
- com.stackoverflow.my-package (hypens)
- com.stackoverflow.MyPackage (camel-case)
What is the general standard?
how should one seperate words in package names
What is the general standard?
All the three are not the conventions.
Use com.stackoverflow.mypackage
The package name do not follow camel casing or underscores or hypens
There is none. But usually you don't want a package name to be more than one word long.
I'd like to point out that a package name with a hypen in it is illegal anyway, it is not a valid Java identifier.
Go with com.stackoverflow.mypackage
convention.
The official naming conventions aren't that strict, they don't even 'forbid' camel case notation except for prefix (com
in your example).
But I personally would avoid upper case letters and hyphenations, even numbers. I'd choose com.stackoverflow.mypackage
like Bragboy suggested too.
(hyphenations '-' are not legal in package names)
EDIT
Interesting - the language specification has something to say about naming conventions too.
In Chapter 7.7 Unique Package Names we see examples with package names that consist of upper case letters (so CamelCase notation would be OK) and they suggest to replace hyphonation by an underscore ("mary-lou" -> "mary_lou") and prefix java keywords with an underscore ("com.example.enum" -> "com.example._enum")
Some more examples for upper case letters in package names can be found in chapter 6.8.1 Package Names.
Here's what the official naming conventions document prescribes:
Packages
The prefix of a unique package name is always written in all-lowercase ASCII letters and should be one of the top-level domain names, currently
com
,edu
,gov
,mil
,net
,org
, or one of the English two-letter codes identifying countries as specified in ISO Standard 3166, 1981.Subsequent components of the package name vary according to an organization's own internal naming conventions. Such conventions might specify that certain directory name components be division, department, project, machine, or login names.
Examples
com.sun.eng
com.apple.quicktime.v2
edu.cmu.cs.bovik.cheese
Note that in particular, anything following the top-level domain prefix isn't specified by the above document. The JLS also agrees with this by giving the following examples:
com.sun.sunsoft.DOE
gov.whitehouse.socks.mousefinder
com.JavaSoft.jag.Oak
org.npr.pledge.driver
uk.ac.city.rugby.game
The following excerpt is also relevant:
In some cases, the internet domain name may not be a valid package name. Here are some suggested conventions for dealing with these situations:
- If the domain name contains a hyphen, or any other special character not allowed in an identifier, convert it into an underscore.
- If any of the resulting package name components are keywords then append underscore to them.
- If any of the resulting package name components start with a digit, or any other character that is not allowed as an initial character of an identifier, have an underscore prefixed to the component.