Search code examples
javadnspackagenotationreverse-dns

Why is reverse DNS notation used for package naming?


There is a technical reason for using the reverse DNS package notation? Or is it just a convention?


Solution

  • Sun used to maintain a Java Coding Standards guide - you can find an archived copy on the Oracle site here - according to this site this has not been maintained since 1999: http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

    The part covering recommendation for package names does suggest to use domain names of the owning organization, top-level-domain first: http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367

    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.

    I think this became the accepted standard for some time, even though it's not as strictly followed today. There's no reason why you can't devise a naming pattern for your project or organization that makes best sense to you - there's no technical reason why it has to follow this domain name pattern.

    The typical pattern followed today is higher level groupings first (organizational or project name) followed by increasingly more specific groupings down to most specific functional or technical grouping in the name last.