Why do package names often begin with "com" [duplicate]
Possible Duplicate:
Java packages com and org
I am a java developer. Nowadays I am learning struts and when开发者_如何学运维 reading a tutorial a curiosity intruded in my mind regarding
package com.something.something;
I know it is a very simple package declaration but what about
package **com**.something.something;
This package name fragment often comes in many commercial distributions. Now I want to know what does it mean? Please clarify it.
Thanks and sorry if I couldn't clarify it...
It's just a namespace definition to avoid collision of class names. The com.domain.package.Class
is an established Java convention wherein the namespace is qualified with the company domain in reverse.
Wikipedia, of all places, actually discusses this.
The idea is to make sure all package names are unique world-wide, by having authors use a variant of a DNS name they own to name the package. For example, the owners of the domain name joda.org
created a number of packages whose names begin with org.joda
, for example:
org.joda.time
org.joda.time.base
org.joda.time.chrono
org.joda.time.convert
org.joda.time.field
org.joda.time.format
It's the domain name spelt out in reverse.
For example, one of my domains is hedgee.com. So, I use com.hedgee
as the base name of all my packages.
From the Wikipedia article on Java package naming:
In general, a package name begins with the top level domain name of the organization and then the organization's domain and then any subdomains, listed in reverse order. The organization can then choose a specific name for its package. Package names should be all lowercase characters whenever possible.
For example, if an organization in Canada called MySoft creates a package to deal with fractions, naming the package ca.mysoft.fractions distinguishes the fractions package from another similar package created by another company. If a US company named MySoft also creates a fractions package, but names it us.mysoft.fractions, then the classes in these two packages are defined in a unique and separate namespace.
This is what Sun-Oracle documentation says:
Package names are written in all lower case to avoid conflict with the names of classes or interfaces.
Companies use their reversed Internet domain name to begin their package names—for example, com.example.mypackage for a package named mypackage created by a programmer at example.com.
- com => domain
- something => company name
- something => Main package name
For example: com.paresh.mainpackage
Companies use their reversed Internet domain name to begin their package names—for example, com.example.mypackage for a package named mypackage created by a programmer at example.com. This information i have found at http://download.oracle.com/javase/tutorial/java/package/namingpkgs.html
精彩评论