[JAVA] Use an example domain for the package name in the sample code

Overview

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.

Java package naming method

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

Sample code package name

Domain name-based naming is a bit exaggerated

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.

Clearly named by diverting the reserved domain

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 {
  // ...
}

in conclusion

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

Use an example domain for the package name in the sample code
Sample source code for finding the least common multiple of multiple values in Java
Sample code that uses the Mustache template engine in Spring Boot
Sample code to call the Yahoo! Local Search API in Java
[Reference example] Copyright is described in the comment of the source code.
Sample code that uses the Mustache template engine JMustache in Java
Guess the character code in Java
Use the Findbugs plugin in Eclipse
Pre-written source code for the activity
I checked the package name referenced by the class contained in the JAR file
I want you to use Enum # name () for the Key of SharedPreference
Source code for finding an orthonormal basis with the Gram-Schmidt orthogonalization method