Languages

Java - package naming convention

4 points
Asked by:
Bartek
1205

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 answers
4 points
Answered by:
Bartek
1205

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
Hey 👋
Would you like to know what we do?
  • Dirask is online IT community for professionals and hobbyist to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.