Java Comments
Java Comments
In this article you will read about the Java Comments, like what is Java comments, uses of comments in Java and also read the types of Java comments with programming examples.
What is Java Comment?
Comments in Java are the statements that are not executed by the compiler and interpreter. It can be used to provide information or execution about the variable, class and method or any statement to the programmers.
Uses of Comments
In any programming languages comments are use to explain the code and make it more readable. It can also used to prevent execution when testing alternative code.
Types of Comments in Java
Mainly there are three types of comments are used in Java programming languages, that are given below with programming examples.
- Single Line Comment
- Multi Line Comment
- Documentation Comment
We defined below all the types Comments with programming examples.
Single Line Comment
The Single Line Comment in Java is used to comment only one line. In this when the programmers needs to write only one line comments and statements then they used single line comment method.
Syntax;
// This is Single Line Comment
Example of Single Line Comment;
public class comment { public static void main(String[] args) { // This is Single Line Comment System.out.println("StudyMuch"); } }
Above you can see the syntax and programming examples of single line comment, in example green line is the comment line.
Multi Line Comment
The Multi Line Comment in Java is used to comment multiple line of code statement in one time. If programmers need to write multiple lines of comments, then they can used multi line comment.
Syntax;
/* This is Multi Line Comment here we print StudyMuch website */
Example of Multi Line Comment;
public class comment { public static void main(String[] args) { /* This is Multi Line Comment here we print StudyMuch website */ System.out.println("StudyMuch"); } }
You can see above, syntax and programming example of Multi Line Comments, in this method you can write comment multiple lines of comments.
Documentation Comment
The Documentation Comment is used to create documentation API. To create documentation API.
Syntax;
/** This is Documentation Comment to create Documentation. */
Example of Documentation Comment;
/** The Calculator class provides        methods to get addition and subtraction of given numbers.*/ public class Calculator { /** The add() method returns            Sum of numbers.*/ public static int add(int a, int b) {            return a+b; } /** The sub() method returns            subtraction of numbers.*/ public static int sub(int a, int b){               return a-b;    } }
You can see above programming examples of Documentation comments, the green line is documentation comments. You need to use Javadoc Too to compile this Documentation comments.
So, in this article you read about the comment of Java programming language with syntax and programming examples also. I hope you read well and learned something amazing. If you have any questions and doubts, please ask in the comment sections.
Read Also –
2 Comments
Ivy Lavender · March 12, 2023 at 4:06 am
To the studymuch.in webmaster, Your posts are always well-referenced and credible.
smortergiremal · November 3, 2024 at 10:22 pm
Having read this I thought it was very informative. I appreciate you taking the time and effort to put this article together. I once again find myself spending way to much time both reading and commenting. But so what, it was still worth it!