views:

494

answers:

11

So most Java resources when speaking of packages mention a com.yourcompany.project setup. However, I do not work for a company, and don't have a website. Are there any naming conventions that are common? An email address, perhaps?

A: 

com.deviantart.bhelyer. :-P

Chris Jester-Young
Yeah, uh, no. :]
Bernard
+8  A: 

Use a top-level domain like 'bernard' or something else unique. The important part is that the domain is unique so that you avoid clashes, and not that it starts with a real Internet top-level domain like org or com. E.g.

import java.util.*;
import bernard.myProject.*;
import org.apache.commons.lang.*;
Stu Thompson
I'm pretty sure there's more than one Bernard :P
izb
I AM UNIQUE! I mean, err, that makes sense. Thanks stu.
Bernard
If and when you actually distribute the code, it will be from "some web site" (sourcrforge, google code, whatever), and THEY will have a domain name you can use along with your project name. Ideally, that will be a simple refactor operation in the IDE when it comes to that. Until then, Bernard.
Will Hartung
+2  A: 

Good advice on this topic found on the web: "Start your package names with your email address, reversed.[...] Or, host your code at a site which will give you a slice of their domain."

Rafał Dowgird
My problem with that advice is you are taking a sub-domain of a domain that you actually don't own or have control over. If there was a clash (however unlikely) you would be entirely in the wrong.
Stu Thompson
+2  A: 

Why not register a domain?

They're fairly cheap and doing so will guarantee that you don't clash with anybody else (Or at least give you the satisfaction that if a clash does occur, it's the other person who will have to rewrite their code)

Either register your own name, or try to make up a name that you may use as the basis for a business at a later date.

bernard.surname.net ...or... madeupname.net

Either will cost you less than 10GBP per year.

Personally, I'd go for the made up name approach, as it's likely to look more professional (Unless you choose something really strange).

An added advantage is that a lot of domains will come with email capabilities, giving you a better email address than [email protected].

belugabob
+1  A: 

What you can do also is register a domain (actually a sub-domain) through a service such as DynDns (or one of the equivalents) and then use that domain name. You will be the sole controller and it is free and easy to maintain. They have a choice of 88 top domains at the moment (October 2008). dyndns dynamic dns service

Donal Tobin
+1  A: 

If your creating an open source project, you could register it with Sourceforge and use net.sourceforge.myproject. This is common with a lot of Java projects. An example is PMD http://pmd.sourceforge.net/.

brianegge
A: 

For my own personal work when I don't have a namespace, I go for something simple like org.<myname>.*

Alan
A: 

I've been in a couple different companies who write house java classes. Often they're just com.blah.blah.blah without regard to whether there's a actual domain name behind it.

Axeman
A: 

IMHO, best if it does not depend on any external information, such as hosting provider or company (it could be released to the open source community), since package-level refactoring is not quite desirable, especially in the case of frameworks and libraries. I suggest choosing your project name carefully and unambiguously, then using org.<project name> as the root package.

thSoft
+2  A: 

Note that the "reverse domain name" thing is just a convention: useful since it definitely avoids clashes if everyone adhers to it, but you don't have to follow it.

Just choose a name that you can be reasonably sure nobody else will use and which is not registered as trademark by anyone - because that's the one way you could actually get into legal trouble.

And that means it's in fact a rather bad idea to use some sort of "subdomain" of a free service you're using, like deviantart or a dyndns or free mail service! Because most (if not all) of those domains are trademarked terms, and if your projects ever gets widely distributed, it could be seen as violating the trademark. Just because they allow you to use that name as an email address (or whatever) doesn't mean you can use it for anything else - in fact, their EULA almost certainly restricts usage to exactly that one purpose.

Michael Borgwardt
A: 

Many people have their own websites and relatively unique names (or login names).

If your name is Bernard Something, you may own BernardSomething.com, making com.bernardsomething.xxxx (or com.bsomething.xxx) a legitimate package name IMHO for personal code.

That being said, If your project name is unique, you may want to name the package after that.

And of course, get the domain after your name if you don't own it yet!

Uri