Multiline comments in Java with example

In this tutorial, we are going to learn the usage of  the feature multiline comments in Java programming language.
This tutorial helps in clearing out the doubts and confusions in the concept.

A Comment is a programmer-readable explanation or annotation in the source code of a computer program.

Multiline comments are the extensions of regular comments.

Multiline Comments in Java with examples

Comments:

A comment in java programming language is created by placing two forward slashes(/) before the content
you wanted to comment out.

A comment is never executed in the runtime of the actual program.

class Codespeedy{
  public static void main(String args[]){
       System.out.println("no comment in output");
//anything you write here is a comment
}
}

Output:

no comment in output
Multiline Comments:

Multi-line comments start with /* and ends with */ . Any text between /* and */ will be ignored by Java.

A multiline comment does the same functioning  as that of a single line comment.

But the actual drawback of a single line comment gave birth to a multiline comment . A single line comment explained above can comment out only a text of one line.

So, here we use multiline comments. Multiline comments are generated be placing /* at the beginning of the text content and */ at the end of the text content.

The text in between those, as many lines as possible, is commented out and will not be executed in the runtime of the program.

class multilinecom{
public static void main(String args[]){
/* the content here is commented
none of the lines in here are executed 
every line here is considered a comment*/
System.out.println("excecution successful");
}

Output:

execution successful

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top