Single and Multi Line Comments in Java


The comments are the statements that are not executed by the compiler and interpreter. It can be used to provide information or explanation about the variable, method, class or any statement. It can also be used to hide program code for a specific time.

1. Single Line comments are started by // and may be positioned after a statement on the same line, but not before.

    Example:
       //single line comment

2. Multi-Line comments are defined between /* and */. They can span multiple lines and may even been positioned between statements.

     Example:
       /*
       Multi
       Line
       Comment
       */

This is a Java program that demonstrates single and multi-line comments.

  • The import java.lang.*; line is not necessary as the java.lang package is automatically imported.
  • The class comments declares a class named comments.
  • The public static void main(String args[]) method is the entry point of the program. It prints "Welcome To Tutor Joes" to the console using the System.out.println() method.
  • The /* ... */ block is a multi-line comment that contains information about the use of Lorem Ipsum in publishing and graphic design.

Overall, this program demonstrates the use of single-line comments with // and multi-line comments with /* ... */ in Java. When executed, the program will only print "Welcome To Tutor Joes" to the console, as the multi-line comment is not executed by the compiler.

Source Code

//03 Single and Multi Line Comment in Java
import java.lang.*;
 
class comments
{
	public static void main(String args[])
	{
		System.out.println("Welcome To Tutor Joes");
		/*
		In publishing and graphic design, Lorem ipsum is a placeholder text commonly used to demonstrate the visual form of a document or a typeface without relying on meaningful content. Lorem ipsum may be used as a placeholder before final copy is available.
		*/
	}
}

Output

Welcome To Tutor Joes
To download raw file Click Here

Basic Programs