Should I use /* */ or /** */ for the copyright in the top of a java file?
Asked Answered
P

4

19

There is a copyright comment in each java file, but I don't know which one should I use: /* */ or /** */?

 /*
  * Copyright ...
  */
 import java.util.*
 ...

or

/**
 * Copyright ...
 */
import java.util.*
....
Pinite answered 30/11, 2011 at 2:53 Comment(0)
L
12

This rather old (circa 1999) Sun coding conventions document suggests /* */.

More specifically, it suggests the following layout for your class/interface file(s):

  • Beginning comments

    /*
     * Classname
     * Version information
     * Date
     * Copyright notice
     */
    
  • package and import statements
  • Class and interface declarations (which includes Javadoc comments for the class - see table entry #1).

Example:

/*
 * MyClass
 *
 * v1.0
 *
 * 2011-11-29
 * 
 * This file is copyrighted in an awesome way.
 */
package com.example.mypackage;

import com.example.otherpackage;

/**
 * Javadoc comments for the class.
 */
public class MyClass {
    ...
}
Lammergeier answered 30/11, 2011 at 3:25 Comment(0)
B
10

Javadoc will only gather /** ... */ comments if they are directly before any declaration to be documented. package (other than in package-info.java) and import declarations are not documented anyway, so Javadoc will not look at the comment in either way.

As it doesn't matter for Javadoc, you can as well use the "less heavy" /* ... */ version.

Bimonthly answered 30/11, 2011 at 9:51 Comment(1)
+1 Here's the documentation reference if you want to add it to your answer. Specifically the section Placement of comments, where it states: "Documentation comments are recognized only when placed immediately before class, interface, constructor, method, or field declarations". It also sort of identifies the discussion on this question: "A common mistake is to put an import statement between the class comment and the class declaration. Avoid this, as the Javadoc tool will ignore the class comment."Lammergeier
R
6

If you use /** */ documenting tools will grab it so you're better off using it :)

Ruthenic answered 30/11, 2011 at 2:54 Comment(3)
Is that always the Right Thing, though? What if the copyright only applies to the code? What if the Javadoc API is licensed/copyrighted differently?Lammergeier
This is actually incorrect for the example code given in the question. See Paŭlo's answer and my comment on it.Lammergeier
Javadoc will not grab stuff before an import statement like in the example in the question.Tit
P
4

I just read some open source java projects, found they all use /* */

Pinite answered 30/11, 2011 at 2:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.