In This Article, You Will Learn about Java Comments.
Before moving ahead, let’s know a bit about Java Output.
Table of Contents
Java Comments
Java Comments are used for better understanding & good explanation of codes and to prevent unnecessary code from executing.
Single-line Comments
In Java, single-line comments start with two forward slashes (//).
Any text that starts with // and the end of the line is not considered a code line by Java and will not be executed.
Example: Use a single-line comment before a line of code.
// write the “Hello World” program.
public class Main{
public static void main(String[] args){
System.out.print("Hello World ");
}
}
Example: Use a single-line comment at the end of a line of code.
public class Main{
public static void main(String[] args){
System.out.print("Hello World "); // write the “Hello World” program.
}
}
Java Multi-line Comments
In Java, if we have to write more than one line of comments, then use Multi-line comments that start with /* and end with */.
Example: Use a multi-line comment (like a block of comments) to explain the code.
/* write the “Hello World” program
In this Java file named Main.java.
*/
public class Main{
public static void main(String[] args){
System.out.print("Hello World ");
}
}
If you find anything incorrect in the above-discussed topic and have further questions, please comment below.
Get Started: Java Comments
In This Article, You Will Learn about Java Comments.
Before moving ahead, let’s know a bit about Java Output.
Table of Contents
Java Comments
Java Comments are used for better understanding & good explanation of codes and to prevent unnecessary code from executing.
Single-line Comments
In Java, single-line comments start with two forward slashes (//).
Any text that starts with // and the end of the line is not considered a code line by Java and will not be executed.
Example: Use a single-line comment before a line of code.
Example: Use a single-line comment at the end of a line of code.
Java Multi-line Comments
In Java, if we have to write more than one line of comments, then use Multi-line comments that start with /* and end with */.
Example: Use a multi-line comment (like a block of comments) to explain the code.
If you find anything incorrect in the above-discussed topic and have further questions, please comment below.
Connect on:
Recent Post
Sora ChatGPT Image Tutorial: How to create AI Images using ChatGPT Sora AI Model
ChatGPT Ghibli Tutorial: How to create Studio Ghibli Style Portraits
Python Bulk Email Sender Using Gmail & Google Sheets
Python Bulk Email Automation using Gmail
How to Create a Python Chatbot for Beginners
Popular Post
Get Started: SQL ANY and ALL Operators
Introduction to Parallel Query in DBMS
Introduction to Numpy Zipf Distribution
Python Set Project: A Practical Set Project for Beginners
Introduction to Machine Learning Normal Distribution & Scatter Plot
Top Articles
Top 10 Python Programming Tips Beginners Should Check
A Beginner Glance: Introduction to Python Language
Top Programming Languages used by MNCs
Python Program: Swap Two Values in Python
Python Program: Find Armstrong Number in Python
Archives
Categories
Tags
Share on