- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Comments in Javan
The Java language supports three types of comments −
Sr.No. | Comment & Description |
---|---|
1 | /* text */ The compiler ignores everything from /* to */. |
2 | //text The compiler ignores everything from // to the end of the line. |
3 | /** documentation */ This is a documentation comment and in general, its called doc comment. The JDK Javadoc tool uses doc comments when preparing automatically generated documentation. |
Following is a simple example where the lines inside /*...*/ are Java multi-line comments. Similarly, the line which proceeds // is Java single-line comment.
Example
/** * The HelloWorld program implements an application that * simply displays "Hello World!" to the standard output. * * @author Zara Ali * @version 1.0 * @since 2014-03-31 */ public class HelloWorld { //Standard main method public static void main(String[] args) { /* Prints Hello, World! on standard output. */ System.out.println("Hello World!"); } }
You can include required HTML tags inside the description part. For instance, the following example makes use of <h1>....</h1> for heading and <p> has been used for creating paragraph break −
Example
/** * <h1>Hello, World!</h1> * The HelloWorld program implements an application that * simply displays "Hello World!" to the standard output. * <p> * Giving proper comments in your program makes it more * user friendly and it is assumed as a high quality code. * * * @author Zara Ali * @version 1.0 * @since 2014-03-31 */ public class HelloWorld { //Standard main method public static void main(String[] args) { /* Prints Hello, World! on standard output.*/ System.out.println("Hello World!"); } }
- Related Articles
- Java comments.
- /** and /* in Java comments
- Executable Comments in Java
- Java documentation comments
- Types of Java comments.
- Java single line comments.
- Java multi-line comments
- What are comments in Java language?
- Best practices for Java comments.
- Pattern COMMENTS field in Java with examples
- What is the difference between /* */ and /** */ comments in Java?
- How to add different comments in the Java code?
- Comments in Python
- Comments in C#
- Comments in Perl

Advertisements