Home Commenting methods

Know your audience

When commenting your methods, be sure to keep in mind who exactly your comments are addressed to. You should assume that your reader is competent, does not know anything about the assignment, and does not care about how your code works, only what it does.

Comment every method

You must comment every single method in your class. Your comment should describe what that method does (but not how it does it).

Exception: Commenting your main method is optional

The only method you are not required to comment is your public static void main(String[] args) method (though you can, if you want to).

What to comment on

When writing a method header comment, focus on describing your parameters, any return values, and any interactions your program will have with the outside world (printlns, reading or writing to files, getting input from the user, etc).

Formatting your comments

You may format your comments however you wish as long as it's readable and the information we're looking for is there. Expand for suggested formatting styles.