You often hear the general recommendation that, in the best case, comments should simply not be necessary at all. But concerning JavaDoc, they play an important role not only for the developer, but also for the user of the library.
Additionally, writing JavaDoc comments may be more useful for you (especially for a beginner) than for anyone else: When you find it hard to describe what a variable is or what a method does with a single /** One-line-JavaDoc comment */
, then you'll automatically re-think what you have done there.
When generating JavaDocs, you may choose whether you want to generate them only for the public
and protected
parts of the API, or also for default- or private
elements.
However, you should in any case document protected
methods: May someone who extends the class only call this method, or is he also allowed to override this method? If so, are there any pre- and postconditions that he should know about? Should he call super.theMethod()
in the overridden version? (BTW: If he's not allowed to override the method, then it should be final
, but documented anyhow)
BTW: I personally comment everything, but know that most people think it's not necessary or even a bad style, especially for "trivial" things
/**
* The number of elements in this set
*/
private final int numberOfElements;
I think it does not harm, but helps in many cases. Maybe, regarding private
parts, it's just a matter of taste.