Java Comments

Java comments are used to ignore lines or blocks of code by the compiler means when the compiler compiles a Java program it ignores those codes that are commented.

Java Comments are used in different - different conditions, In this topic we will see when and how to use comments, so let’s first know why to use Java comments.

Java Comments

Why Java Comments

This is a very common thing to know why we use comments in Java programming. Basically, java comments are used as remarks in programming, suppose a group of people are developing software and each person is given some parts to code, and last all parts have to combine. There may be many methods and variables in each part, so developers put a comment about what that method is. Usually, developers create a comment and write a remark about the use of that method or variable that he has created so that other developers can easily understand it.

Type of Comments in Java

There are three types of comments in java which are listed below.

  1. Single-Line comment
  2. Multi-Line Comment
  3. Documentation Comment

Single-Line comment

As the name indicates, it is used to ignore a single-line code or to write a remark in a single line. It is denoted by // and after it type all your remarks. There is no limit to how many single-line comments can be used in a program. Let’s take a look with the help of an example.

For Example


In the above program all lines that are stat from // are single-line commented, the compiler ignores all these lines in the compilation.

Actually, it’s not about the line, it’s about the remaining code in a line after the // symbol.

If a line contains some code and then // and then some other code, in this case compiler only ignores the codes that are after the // symbol in that line.

Output

Multi-Line Comment in Java

Multi-line comments are also used to ignore or for remarks in a program, it can be used in multiple lines at once. It starts from /* and ends by */. All code and text between these are ignored by the compiler at the time of compilation. Let’s see it in action in the below example.

For Example

Output

Imp: Closing */ symbol is must otherwise it will comment all code after /* symbol.

Documentation Comment

Comment used to produce an HTML file that documents your program. The documentation comment begins with like this /** and ends with */:


Remarks

  • There is no limit to how many comments you are using in a program.
  • There is no limit to how many types are comments you are using in a program.
  • You can use a multi-line comment as a single-line comment, just put both opening /* and closing */ in the same line.
  • The use of comments depends on the developer for what reason he is using it.

Related Topics

Harsh Pokharna Net Worth 2024, Business, Salary, Income Source, Car, House

Top 10 Most Popular Trading Platform in India

What are the Nature of Management and types?

Average salary in UK

Kuldeep Singh Chauhan Net Worth 2024, Business, Salary, Income Source, Car, House

Wan Hong Net Worth 2024, Business, Salary, Income Source, Car, House

What is the list of the top 10 billionaire in the world

Mukesh Ambani Net Worth 2024, Business, Salary, Income Source, Car, House

Average salary in Senegal

Harshad Sharma Net Worth 2024, Business, Salary, Income Source, Car, House

What is a money economy?

What is the nature of competition in marketing?

Chanakya Hridaya Net Worth 2024, Business, Salary, Income Source, Car, House

Ankit Bhati Net Worth 2024, Business, Salary, Income Source, Car, House

What are the developing and evaluating alternative solutions?

Average salary in Anguilla

Lizzie Chapman Net Worth 2024, Business, Salary, Income Source, Car, House

VS Sudhakar Net Worth 2024, Business, Salary, Income Source, Car, House

Average salary in Falkland Islands

Vinay Sanghi Net Worth 2024, Business, Salary, Income Source, Car, House

Anshoo Sharma Net Worth 2024, Business, Salary, Income Source, Car, House

Average salary in Croatia

Average salary in The Gambia

Harsh Jain Net Worth 2024, Business, Salary, Income Source, Car, House

Average salary in Portugal

Gajendra Jangid Net Worth 2024, Business, Salary, Income Source, Car, House

Empowering Individuals: How Helping Businesses Make Better Decisions Can Earn You Extra Money

What is the List of Top Digital Marketing Companies Websites?

What is the market structure and conditions?

Atul Shree Net Worth 2024, Business, Salary, Income Source, Car, House

Email Us: advertise@gdatamart.com

Donate Us: Support to GDATAMART

© 2023 GDATAMART.COM (All Rights Reserved)