Commenting Java Code

Comments are essential to good programming. Every file containing code should start with a comment justifying its existence. Comments should be sprinkled liberally throughout every file explaining the purposes and goals of every block of code that is not obvious. When you are in a hurry to finish a task, documenting what you are doing is not glamorous, but years later when you need to go make a fix for yourself or a customer, you’ll be very glad you took the time to comment your code.

Comments are ignored by the ‘javac’ command. The compiler does not care what you put into a comment. You can even put code into a comment and the ‘javac’ command will pretend it doesn’t exist.

Java has three commonly used types of comments. There are the single-line comments, multi-line comments, and Javadoc comments. They are all useful. However, Javadoc comments are the most powerful, because technical documentation for your code can be automatically generated from them.

Continue reading “Commenting Java Code”