简体   繁体   中英

My legal domain name is not a legal Java package name

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?

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.

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 .

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 (eg, 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM