11.10 JavaDocs

JavaDoc comments are a special type of comment used to document parts of your code, such as a method, variable (aka field), or class (see Ch. 12). A JavaDoc comment for a method can describe its purpose, its parameters, what it returns (assuming the method is not void), and more. The descriptions for the parameters and return value are marked with their respective tags (@param and @return).
/** * Returns the average of two doubles * @param a first double * @param b second double * @return the average of two doubles */ public static double average(double a, double b) { return (a + b) / 2; }
To write a JavaDoc comment, you do the same thing as a multi-line comment, except that it starts with two asterisks instead of just one (/** instead of /*).
The nifty thing about JavaDoc comments is that you can automatically generate a JavaDoc (which are basically HTML pages) with them, which is commonly used in creating effortless programming documentation. You can view the JavaDoc for the Scanner class here, which describes the uses of the class, methods in the class, etc.
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.