Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to *really* ensure my Java package names are unique?

The standard way to avoid package name conflicts in Java is to use reverse-domain convention com.[mycompany].[rest-of-the-package-name]. This works brilliantly ... if one owns the domain [mycompany].com.

However, there are several individual developers (or students) who:

  • Don't (or can't afford to) own a domain
  • Still conjure up some package names hoping they will be unique.

This alone introduces scope for package conflicts.

Further, assume that I own [mycompany].com. What is preventing a developer from creating a library with the same package prefix as mine and distributing it? AFAIK, there is no legal binding with regard to package names ("you MUST own the domain which you have used in you Java package"). Not to mention that this action on the developer's part might not be intentional (how many of us comb the web looking for a non-existent domain name before we name our packages?).

Even further, even if I own a domain name, it may or may not be suitable for use as a package name (my domain name could include hyphens, or it could be so long that although it is a legal package name, it could still make it impractical).

So my question is: How do I really make my Java package name unique?

like image 238
curioustechizen Avatar asked May 22 '12 13:05

curioustechizen


2 Answers

You cannot absolutely guarantee that your package names will be globally unique. As you mentioned, there's nothing stopping someone else from using an identical package name, regardless of who owns whatever it is the package name is based on. There's no authoritative index of package names in use.

like image 66
Matt Avatar answered Nov 15 '22 21:11

Matt


I see two answers to your problem:

  • Make your student project a SourceForge project and name packages net.sf.myproject (or use any similar free host, such as GitHub). Such a package name is likely not to be used by others, although there is no guarantee as Matt Hurne points out
  • Other than that, if you can't or don't want to afford a domain, your program is unlikely to be used by a wide audience anyway, and you can name your packages whatever you want
like image 29
Lukas Eder Avatar answered Nov 15 '22 21:11

Lukas Eder