JAVA Comments In Depth

JAVA comments are the explanatory statement or the statements that define our code to someone who is reading our code and it makes the code easily understandable by everyone. Comments are used in every programming language. Comments are considered as a good practice.

JAVA Comments In Depth

In this tutorial we will learn about comments in JAVA. We will learn why and when we use comments in any programming language. Before moving on to JAVA Comments let's just see what comments simply mean then we will learn about JAVA comments and its types.

A comment is basically a line that defines or reminds something about our content

In computer programming, a comment is a line of code that explains the source code of a computer program more easily and efficiently. It basically makes our program more human-readable. Comments are neglected by the compilers and interpreters during the program run.

There are two ways that we can use to insert comments in the JAVA programs:

Single-Line Comments ( // ) -The comments that begins with // are single line comments in JAVA. The JAVA compiler ignores everything following // in that same line.

Example:

// My first comment in JAVA.

What if we wanted to arrange our comment in multiple lines in the JAVA program then we use multi-line comments in JAVA.

Multi-Line Comments (/*....*/) - It starts with /* and ends with */. So everything inside the starting tag and end tag is considered as comment. It can be written in multiple lines.

Example:

/* This is my first comment in JAVA
    Best of luck for future */

So basically there are two types of comments in JAVA.

  1. Single-line Comment
  2. Multi-line Comment

Let us just stop here in this tutorial we will look more concepts in other tutorials. So please be with us for the journey of learning JAVA.

What's Your Reaction?

like
0
dislike
0
love
0
funny
0
angry
0
sad
0
wow
0