Say you're working on the core module of the foo
project for BarBaz Incorporated. Your code fragment might look like this:
package com.barbaz.foo.core; import com.barbaz.foo.util;
What would the convention be if your company's website was not barbaz.com
, but instead bar-baz.com
?
You are right, the simple answer is: You are NOT allowed to use the hypen in package names. If you have a unique package name build from a domainname containing a hyphen you have to translate it to the underscore.
Package 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 .
The package names do not follow camel casing or underscores or hyphens package naming convention.
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.
The SUN-era Java Language Specification gives a suggested convention:
If the domain name contains a hyphen, or any other special character not allowed in an identifier (§3.8), convert it into an underscore.
But it's just a suggestion...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With