What's the convention for java package names without a domain association?

21,954

Solution 1

If you are going to be distributing a lot of stuff, I would really suggest getting a domain name. Another alternative however would be to use your e-mail: e.g. [email protected] would become com.gmail.bob. This is less common than using domain names but is still done by some and still ensures uniqueness.

Solution 2

One convention is to use the domain name of the hosting provider, e.g.

com.github.myrepositoryname
net.sf.sourceforge.myproject
com.googlecode.myproject

Benefits:

Drawbacks:

  • if you decide to change providers, you either have package structures which are out-of-date, or you introduce backward-incompatible changes to keep the source in line with your new provider

Solution 3

Domain names can be had for free. For example dyn.com offers free domain names of the form 'whatever.dyndns.org' at http://free.domain.name/

Solution 4

If you are the only coder, you can just use your name. My name is Jannis Froese, so I would use

jannisfroese.projectname.stuff

or if you want to stay with 'valid' domain names

localhost.jannisfroese.projectname.stuff

(localhost is a reserved top level domain)

Of course this only works if your name is sufficiently unique, so that a collision is unlikely enough

Solution 5

In a professional environment, the convention is to use reverse domain. In an environment that's more associated with yourself, you can use org.projectname.packagename.*.

It's a convention, not a hard and fast rule. You're free to use whichever domain naming style you like.

Share:
21,954

Related videos on Youtube

Mike
Author by

Mike

Have a BS in computer science from SIUE Worked @ Motorola for 6 years as an embedded systems software engineer Currently reside in OH working for Emerson as a software engineer

Updated on July 09, 2022

Comments

  • Mike
    Mike almost 2 years

    I can't find a Q/A on SO that answers my exact question, so I figure I'd post it and see what comes back.

    As far as the naming convention goes for Java packages, I understand that it's supposed to be the reverse domain name: com.whatever.stuff and I get the rules about no mixed case, hyphens, keywords, etc.

    I've also read section 7.7 (Unique-Package-Names) of the Java Language Specification. As far as I can tell, the rules from Java are to use the reverse domain to insure uniqueness... and if you don't have one, go get one:

    You form a unique package name by first having (or belonging to an organization that has) an Internet domainname, such as sun.com. - Section 7.7

    So if I'm not interested in shelling out the money for a domain name, I don't belong to a company whose name I can piggyback off of, is there any part of the naming convention that I'm missing that should be followed? I'm thinking I can just go name it whatever unique name I feel like at this point, but I was just wondering if I was missing anything.

    Note: I would like to release my package for other developers to use, so I didn’t want to just do something that worked on my system, but something more standard if possible.

    I added the android tag because the java packages I'm going to be writing are going to be used in an Android application, wasn't sure if there were different opinions from android developers.

    • nathanfranke
      nathanfranke over 2 years
      I often see me.myname.myproject
  • Mike
    Mike over 11 years
    +1 That's actually a really good idea, I didn't think to use my email account. I'm only planing on distributing 2 packages really, not a lot... So maybe that's what I'll go with.
  • Brian
    Brian over 11 years
    +1 Getting a domain name is a good idea if you plan on distributing your stuff.
  • Mike
    Mike over 11 years
    +1 it's a good point, I'd use it as a back up to using my email due to the drawback, but it's another good way to do this. Thanks!
  • Jannis Froese
    Jannis Froese over 11 years
    +1, very nice. To distinguish from the namespace of the email provider, it could be useful to prefix it with email. (as in email.com.gmail.bob)
  • Grundlefleck
    Grundlefleck over 11 years
    @Mike just don't change your email address ;-)
  • Anay Karnik
    Anay Karnik about 9 years
    What can we do, when we get a domain name afterwards? Can't we use a domain we don't own? What happens if we surrender the domain we are currently using? Thanks.
  • Mathieu K.
    Mathieu K. about 6 years
    @JannisFroese, someone now owns the com.email domain, thus invalidating email.com.* Link: com.email
  • Mathieu K.
    Mathieu K. about 6 years
    Please split this into two answers; they are not at all the same, and thus they each have different merits.
  • Mathieu K.
    Mathieu K. about 6 years
    Email isn't a good idea unless you own your own domain, in which case it's not necessary anyway. My reasoning: I don't own [email protected] in any meaningful sense that I can discern--I'm just a user, and no money has changed hands--nor can I prevent Google from creating an example.gmail.com subdomain.
  • ecv
    ecv over 4 years
    Just to ad that this is still a valid solution for when you move to a domain of your own and upload the app-ads.txt file to your server, as Google at least apparently (and I'm so glad!) won't use your app ID to look for your server but your Google Play app entry website URL. Yay! (This had me sweating for a while)