Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.*
....
like image 846
Freewind Avatar asked Nov 30 '11 02:11

Freewind


People also ask

Which is the correct order of statements for a Java class file?

Java classes are defined in this order: package statement, import statements, class declaration, making Option D the only correct answer.

How do you write a good Javadoc comment?

Writing Javadoc Comments In general, Javadoc comments are any multi-line comments (" /** ... */ ") that are placed before class, field, or method declarations. They must begin with a slash and two stars, and they can include special tags to describe characteristics like method parameters or return values.

How do you write a comment document in Java?

The special comments in the Java source code that are delimited by the /** ... */ delimiters. These comments are processed by the Javadoc tool to generate the API docs. The JDK tool that generates API documentation from documentation comments.

Does the order of classes matter in Java?

Yes, it matters for local classes.


2 Answers

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 {
    ...
}
like image 102
Rob Hruska Avatar answered Oct 21 '22 11:10

Rob Hruska


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.

like image 26
Paŭlo Ebermann Avatar answered Oct 21 '22 09:10

Paŭlo Ebermann