Search code examples
javajavadocconventions

What should have javadoc in Java?


What should be documented by javadoc comments (classes, methods, constructors and fields? Or only classes methods and constructors?)? Is there any convention about that ?

Please provide links to relevant resources in your answer whenever possible. Thank you

EDIT: The question is not about how is it usualy done or what is logical to comment with javadoc. The question is what can be found about this matter in any official Sun/Oracle documents (guidelines about writing javadoc, conventions, specifications and so on). Also please do not answer about how should the javadoc comments look like, the question is specifically about what should be commented, not how.


Solution

  • Javadoc is to document the public API of your code.

    In a nutshell, you need to document all your public and protected classes, methods, constructors, and fields (because they are accessible to your users).

    You need to describe what a method does, not how it does it. Of course, if implementation details result in interesting side-effects, for example performance characteristics, and also usage limitations, those should be mentioned.

    Oracle has official guidelines on "How to Write Doc Comments for the Javadoc Tool".