Why is reverse DNS notation used for package names?

Is there a technical reason to use the reverse DNS packet designator? Or is it just an agreement?

+5
source share
3 answers

Sun is used to provide guidance on Java coding standards - here you can find archival copies on the Oracle site - according to this site this is not supported since 1999: http://www.oracle.com/technetwork/java/codeconvtoc-136057.html

The package coverage recommendation for package names suggests first using the domain names of the owner organization, the top-level domain: http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367

The unique package name prefix is ​​always written in all lowercase ASCII and must be one of the top-level domain names, currently com, edu, gov, mil, net, org or one of the English two-letter codes indicating the countries specified in ISO 3166, 1981.

Subsequent components of the package name are modified according to the organization of their own internal naming conventions. Such conventions may indicate that some components of a directory name are a division, department, project, machine, or username.

I think this has become a recognized standard for some time, although it has not been so strictly enforced today. There is no reason why you cannot develop a naming template for your project or organization that makes the best sense for you - there are no technical reasons why it should follow this domain name template.

A typical pattern that is being followed today is first a group of a higher level (the name of the organization or project), followed by more and more specific groups up to the most specific functional or technical grouping in the name of the latter.

+6
source

I think that now it is basically just a convention, but I would say that it helps organize things down abit.

Here are some examples of why I say this: com.vzy.gui.* And com.vzy.io.*

  • passing through them, we see com and think: "Oh, uh, this is the company that made it"
  • then vzy and think: "The people who did it, vzy!"
  • then gui and io , which leads us to the fact that "this works with the GUI, and this other one works with IO, cool."

I think another good way to show this is to bring it back and see how it will look ...

 import ArrayList.util.java import BorderLayout.awt.java import File.io.java import JButton.swing.javax import JFrame.swing.javax import JLabel.swing.javax import JOptionPane.swing.javax import JPanel.swing.javax import JScrollPane.swing.javax import JSlider.swing.javax import LinkedBlockingQueue.concurrent.util.java import PrintWriter.io.java import Scanner.util.java import SwingUtilities.swing.javax 

or

 import java.awt.BorderLayout import java.io.File import java.io.PrintWriter import java.util.ArrayList import java.util.Scanner import java.util.concurrent.LinkedBlockingQueue import javax.swing.JButton import javax.swing.JFrame import javax.swing.JLabel import javax.swing.JOptionPane import javax.swing.JPanel import javax.swing.JScrollPane import javax.swing.JSlider import javax.swing.SwingUtilities 
+4
source

There are no technical reasons, only an agreement to avoid conflicts. The following abusive quote from the Java Language Specification :

Developers should take measures to avoid the possibility of publishing two published packages with the same name, choosing unique package names for widespread packages ...

You form a unique package name by first having (or belonging to an organization that has) a domain name on the Internet, for example oracle.com. Then you drop this name, component by component, to get com.oracle in this example and use it as a prefix for the names of your packages, using the agreement developed in your organization to further administer package names. Such an agreement may indicate that some components of the package name are divisions, departments, projects, machines or login names.

...

The name of the package does not mean that the package is stored on the Internet. The proposed convention for creating unique package names is just a way to negotiate a package naming convention on top of the existing well-known unique name registry, rather than creating a separate package name registry.

The reason the package name is the reverse sequence of domain names is simply because the package name is a fully qualified name . Each package contains a set of classes / interfaces and / or subpackages, and the name of the subpackage must be prefixed with its containing package to form the full name:

The full name of a named package, which is a subpackage of another named package, consists of the full name of the containing package, followed by " . ", Followed by the simple (member) name of the subpackage.

+3
source

All Articles