7

The name of my domain name is 3DTOPO.com. Apparently java does not allow package domain names to start with a number.

Why doesn't the Java reverse domain name follow the same rules as domain names do? I really don't want to name my package com.threedtopo....

For starters that isn't my domain name! Anyone else would be free to register and use that domain. Besides it is very awkward and not the name of my business.

Does anyone have package name suggestions?

Richard JP Le Guen
  • 28,364
  • 7
  • 89
  • 119
Jeshua Lacock
  • 5,730
  • 1
  • 28
  • 58
  • "Apparently java does not allow domain names to start with a number." => what? Do you have some code? – Richard JP Le Guen Oct 18 '12 at 00:17
  • 1
    Are you mixing the terms "package" and "domain name" up? – Richard JP Le Guen Oct 18 '12 at 00:19
  • Why do you feel such a strong urge to sync your domain name and your package names? What's wrong with _com.tdt_ as a package prefix (3 starts with a t). I'd be WAY more concerned about using _short_ package names (rather than ones that match the legal name of my organization). – jahroy Oct 18 '12 at 00:26
  • 1
    jahroy: I thought the whole concept of using reverse domain names was minimize conflicts. What if Tucker Davis Technologies develops an app and uses their reverse domain name? – Jeshua Lacock Oct 18 '12 at 00:30
  • 1
    Every company I've ever worked for has used an outdated, out of sync acronym for their package names. Nowadays company names seem to come and go (as companies are bought, sold, and re-named). I've never been a part of an effort to re-factor package names just because the company name changed... – jahroy Oct 18 '12 at 00:30
  • 2
    @jahroy Because that would confuse Tucker-Davis Technologies' Java devs, and irritate Maven users when they both released stuff with the same group id? I don't see why *you're* so adamant about not caring; you seem even more upset than the OP. – Dave Newton Oct 18 '12 at 00:33
  • @jahroy As a point of information, btw, I *have* worked at places where packages were renamed when the company name changed, along with copyright headers, and so on. Several places, in fact. – Dave Newton Oct 18 '12 at 00:36
  • Cool. I'm glad I've never worked at a place like that! And hopefully re-factoring tools made it a trivial operation. If you ever get to worry about such things with your code, you're probably a lucky guy! – jahroy Oct 18 '12 at 00:37
  • @jahroy So are they. "Was that class on the old or new packages?" Yuck, no thanks. Consistency is actually useful. – Dave Newton Oct 18 '12 at 00:37
  • @jahroy Also, if you don't use an @, the person you're replying to may not be notified you're talking to them, depending on context. – Dave Newton Oct 18 '12 at 00:40
  • @DaveNewton - Um... thanks for making my point for me. That's why there's no point re-naming packages just because a company changed its name: Just keep things consistent by continuing to use the original package name. (Not sure why I seem upset) – jahroy Oct 18 '12 at 00:40
  • Um... whatever. It's not consistent to keep using a package name that isn't your company any more. Less so if someone else buys the rights to the old name, or... etc. There can also be legal (internal and external) ramifications, client implications both technical and otherwise, and so on. Laugh and point all you want, but the reality is that there are several good reasons to migrate package names, and it's not a big deal. – Dave Newton Oct 18 '12 at 00:49
  • Your points are valid for sure. Maybe I'm being to snarky, but my main point was that A.) there's not an unbreakable rule that your package name matches your domain name and B.) The OP _probably_ doesn't have to worry about any of this for quite some time. – jahroy Oct 18 '12 at 01:13
  • 1
    @jahroy - A) You are right. The advice about using reverse DNS names as the package prefix is **advice**. But it is **good advice**, because ... B) The problem with people ignoring the advice is that it can cause trouble *at some future point*. For instance, imagine (hypothetically) that Microsoft decided to unilaterally start publishing lots of stuff in the "desktop" package. Q: who gets hurt? A: potentially anyone who ignored the advice and used "desktop" as their package prefix. *"Microsoft - he don't care!"* Moral: ignore the advice at your peril. – Stephen C Oct 18 '12 at 01:24

4 Answers4

11

I think you mean Java doesn't allow package names to begin with a number.

One common alternative is to preface it with an underscore, _3dtopo.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • 3
    Java doesn't allow *any symbolic name* to begin with a number. – Peter Gluck Oct 18 '12 at 00:20
  • That is the only thing I can think of, but still makes me cringe. If they chose to base packages on domain names, why don't they allow legal domain names to be used? – Jeshua Lacock Oct 18 '12 at 00:22
  • 1
    @JeshuaLacock, package names can be used as symbolic names anywhere within your program. If you had a package named `3L`, the parser wouldn't know if that was the number `3` (long) or your package name. – mpontillo Oct 18 '12 at 00:23
  • 3
    @JeshuaLacock Parsing/lexing simplification/normalization. Plus when Java was invented there weren't very many domain names. Of all the things to complain about regarding Java, this is pretty low on my list. – Dave Newton Oct 18 '12 at 00:24
  • 1
    Actually, it's a vast conspiracy with the sellers of domain names. They want you to pay another 15 bucks to buy another package name. The nerve! – mpontillo Oct 18 '12 at 00:25
  • @PeterGluck Correct, but I was specifically correcting the OP's statement. – Dave Newton Oct 18 '12 at 00:25
  • 1
    You know... as I read the BNF in [RFC 1034](http://www.ietf.org/rfc/rfc1034.txt), DNS originally didn't allow a digit in the first position of a domain name. Extract: ` – Michael Petrotta Oct 18 '12 at 00:28
  • @MichaelPetrotta I thought not, but couldn't remember that far back. Ugh, just flashed back to bang-paths, too. – Dave Newton Oct 18 '12 at 00:30
  • Alas, starting with an underscore does not appear to be a valid solution. It compiles with no errors, but when I try to install the apk I get this error: 10-10 20:49:49.740: E/PackageParser(15789): parsePackageLite error: specifies bad package name "com._3dtopo.comicbook.android": bad character '_' – Jeshua Lacock Oct 18 '12 at 02:47
  • ARRRRR! Even worse, even the APK won't install, Google won't let me upload a new APK with a different reverse domain name. So looks like the hours I spent setting up my Google Play page are completely wasted. I am under a deadline, and I don't think I will have time to create a new listing. In other words I am pretty much screwed. – Jeshua Lacock Oct 18 '12 at 03:15
10

Sun/Oracle specifically addresses this question in the Java tutorial's Naming a Package section:

In some cases, the internet domain name may not be a valid package name. This can occur if the domain name contains a hyphen or other special character, if the package name begins with a digit or other character that is illegal to use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as "int". In this event, the suggested convention is to add an underscore.

They proceed to give a few examples, the relevant one in this case being the domain 123name.example.com becoming package com.example._123name.

ctrueden
  • 6,751
  • 3
  • 37
  • 69
5

According to RFC 1912,

Allowable characters in a label for a host name are only ASCII letters, digits, and the `-' character. Labels may not be all numbers, but may have a leading digit (e.g., 3com.com). Labels must end and begin only with a letter or digit. See [RFC 1035] and [RFC 1123]. (Labels were initially restricted in [RFC 1035] to start with a letter, and some older hosts still reportedly have problems with the relaxation in [RFC 1123].) Note there are some Internet hostnames which violate this rule (411.org, 1776.com). The presence of underscores in a label is allowed in [RFC 1033], except [RFC 1033] is informational only and was not defining a standard. There is at least one popular TCP/IP implementation which currently refuses to talk to hosts named with underscores in them. It must be noted that the language in [1035] is such that these rules are voluntary -- they are there for those who wish to minimize problems. Note that the rules for Internet host names also apply to hosts and addresses used in SMTP (See RFC 821).

So the allowing digits at the front of domain names didn't begin until RFC 1123, in 1989.

It's worth noting that they started writing Java in 1990. Domains beginning with numbers probably weren't common by then, so package names seemed analogous to hostnames.

Package names don't have to directly correspond to domain names. To me, domain names are temporary - they can be bought and sold. Package names might last much longer than domain names.

For what it's worth, 3com solved it by buying another domain. ;-) They used com.palm.webos for some software.

Community
  • 1
  • 1
mpontillo
  • 13,559
  • 7
  • 62
  • 90
  • 1
    And now that there's Unicode domain names (and the mind-boggling [rfc5892](http://tools.ietf.org/html/rfc5892)) it gets even more confusing :/ – Dave Newton Oct 18 '12 at 00:50
5

Why doesn't the Java reverse domain name follow the same rules as domain names do?

Because:

  1. It isn't a 'reverse domain name', it is a Java package name.
  2. It is composed of Java identifiers, which don't permit a leading digit.
user207421
  • 305,947
  • 44
  • 307
  • 483