A small story about what the package name of the sample code to be posted on Qiit etc. is good. It seems good to use an example domain.
It's quite familiar, so it may be needless to say, but for the time being. It is customary to prefix the Java package name with the domain name in reverse order to avoid duplication of FQCN. In The Java Language Specification, the following is listed as "Example 6.1-1. Unique Package Names". [^ jspec].
Package name example
com.nighthacks.java.jag.scrabble
org.openjdk.tools.compiler
net.jcip.annotations
edu.cmu.cs.bovik.cheese
gov.whitehouse.socks.mousefinder
That said, applying the above rules to the sample code feels a bit exaggerated. I have briefly summarized the requirements for the package name in the sample code.
--You don't have to worry about duplication of FQCN --Since it is a sample, I want to write it briefly --I want to clarify that it is a sample ――In the first place, you don't have your own domain name ――However, I'm also reluctant to use other domain names without permission.
So I came up with the idea of diverting a reserved domain. Reserved domains are managed by IANA [^ iana] and can be freely used in documents according to the purpose. There are four reserved top-level domains (TLDs).
Reserved TLD | Use |
---|---|
.test | Domain for testing |
.example | Domain for illustration |
.localhost | Domain for loopback address |
.invalid | Domain to indicate invalid |
Isn't example and invalid just right to use in the package name of the sample code?
Example
package example
public class SampleClass {
// ...
}
So far, I used com.example
[^ example-com] as the package name, but now I'm going to use ʻexample`. You can reduce 4 characters.
Recommended Posts