Introduction
Java Fundamentals
Java Flow Control
Java Arrays
Object Oriented Programming
Comments in Java and Types
Comments can be used to explain Java code, and to make it more readable. It can also be used to prevent execution when testing alternative code. In this tutorial, we will get a basic overview of Java Comments, how to use them, and their types with Examples.
In Java, Comments are used to explain the program such as a overview of the operation, some information about variables, methods and to make it more readable. Comments are statements that are not executed by the compiler and interpreter.
Types of Comments in Java:
There are two types of comments in Java:
1. Single Line Comments in Java:
- The single-line comment is used to comment only one single-line.
- Single-line comment is also known as End of Line.
- To write a single line comment, we can use the // symbol.
// Example of Single Line commend prints "Hello HashCodec!"
import java.io.*;
public class HelloHash {
public static void main(String[] args) {
System.out.println("Hello HashCodec!");
// Prints "Hello HashCodec!" to the console.
}
}
Output :
Hello HashCodec!
2. Multi-Line Comments in Java
- Multi-line comments start with /*.... */.
- In Java, the lines between this /_ and ends with _/ are ignored
- Multi-line comment is also known as Traditional Comment.
/*
This is an example of Multi Line comment.
Prints "Hello HashCodec!" to the console.
*/
import java.io.*;
public class HelloHash {
public static void main(String[] args) {
System.out.println("Hello HashCodec!");
}
}
Output :
Hello HashCodec!