3.4. Comments

Comments are used to document the program and are ignored by the compiler. Java provides three types of comments to document a program:

Single-Line Comment: Character sequence // is used to comment a single line in Java program. The compiler ignores rest of the line in Java program when it encounters //.

Multiple-Line Comment: Multi line comment starts with sequence /* and ends with the sequence */. All the lines with in this are commented and are ignored by the compiler.

All comment start sequences such as (//, /*, /**) are ignored and the comment ends with the first occurrence of */.

Documentation Comment: Documentation comment starts with the sequence /** and ends with the sequence */. This is used to document the Java Program and the javadoc tool can generate HTML documentation for the program. This is placed front of classes, interfaces, methods, and field definitions to explain what it does.

			package javatutorial;

			// 1. Documentation comment, used by tools to generate documentation of your software.

			/**
			 * Example class showing various kinds of comments in java 
			 * 
			 * @author f5java.com
			 */
			public class JavaComments {


				public static void main(String[] args) {
					// 1. This is a single line comment, compiler ignores all types of comments
					
					System.out.println("Learning about comments in Java");
					System.out.println("Learning about comments in Java");
					// Next line is commented using single line comment
					// System.out.println("Learning about comments in Java");
					
					System.out.println("Learning about comments in Java");
					System.out.println("Learning about comments in Java");
					/* Multi line comment: Begin
					All code appearing in this block is ignored by the compiler
					usually used to comment multiple lines of code as below 
					
					System.out.println("Learning about comments in Java");
					System.out.println("Learning about comments in Java");
					System.out.println("Learning about comments in Java");
					System.out.println("Learning about comments in Java");
					System.out.println("Learning about comments in Java");
					
					Multi line comment: End */		

				}

			}