What is the convention for word separator in Java package names?

Jigar picture Jigar · Jul 5, 2010 · Viewed 149.5k times · Source

How should one separate words in package names? Which of the following are correct?

  1. com.stackoverflow.my_package (underscore)
  2. com.stackoverflow.my-package (hyphens)
  3. com.stackoverflow.MyPackage (CamelCase)

What is the general standard?

Answer

bragboy picture bragboy · Jul 5, 2010

All three are not the conventions.

Use com.stackoverflow.mypackage.

The package names do not follow camel casing or underscores or hyphens package naming convention.

Also, Google Java Style Guide specifies exactly the same (i.e. com.stackoverflow.mypackage) convention:

5.2.1 Package names

Package names are all lowercase, with consecutive words simply concatenated together (no underscores). For example, com.example.deepspace, not com.example.deepSpace or com.example.deep_space.

Google Java Style Guide: 5.2 Rules by identifier type: 5.2.1 Package names.