Java – the convention for word separator in Java package names

javanaming-conventionspackage

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

  1. com.stackoverflow.my_package (Snake Case using underscore)
  2. com.stackoverflow.my-package (Kebab Case using hyphens)
  3. com.stackoverflow.myPackage (Camel Case)
  4. com.stackoverflow.MyPackage (Pascal Case)

What is the general standard?

Best Answer

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.