Languages

Java - package naming convention

4 points
Asked by:
Bartek
2050

Is there a correct way to name packages in java?

Can I use underscores or do I need to use capital letters like with class names?

My package names combinations:

example_loops_tests
exampleLoopsTests
ExampleLoopsTests
example.loops.tests

Which one is correct? Or there is more then 1 correct way to name packages in java?

1 answer
4 points
Answered by:
Bartek
2050

From Oracle code convention:

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

9 - Naming Conventions

From google java style guide:

5.2.1 Package names
Package names are all lowercase, with consecutive words simply concatenated together (no underscores).

For example:

// correct:
com.example.deepspace

// incorrect:
com.example.deepSpace
com.example.deep_space

style guide - 5.2.1-package-names

0 comments Add comment
Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join