
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to add different comments in the Java code?
The Java comments are statements that are not executed by the compiler and interpreter. The comments can be used to provide information about the variable, method, class or any statement. It can also be used to hide program code for a specific time.
Types of Java Comments
There are three types of comments in Java.
- Single line comment
- Multi-line comment
- Documentation comment
Single line Comment
Single line comment begins with // and ends at the end of the line.
Example 1
public class SingleLineComment { public static void main(String[] args) { // To print output in the console System.out.println("Welcome to Tutorials Point"); } }
Output
Welcome to Tutorials Point
Multi-Line Comment
Multi-line comment begins with /* and ends with */ that spans multiple lines.
Example 2
public class MultiLineComment { public static void main(String[] args) { /* To print the output as Welcome to Tutorials Point in the console. */ System.out.println("Welcome to Tutorials Point"); } }
Output
Welcome to Tutorials Point
Documentation Comment
Documentation style comments begin with /** and terminate with */ and that spans multiple lines. Documentation comments must come immediately before a class or an interface or a method or a field definition.
Example 3
/** This is a documentation comment. This class is written to show the use of documentation comment in Java. This program displays the text "Welcome to Tutorials Point" in the console. */ public class DocumentationComment { public static void main(String args[]) { System.out.println("Welcome to Tutorials Point"); } }
Output
Welcome to Tutorials Point
- Related Articles
- How to add comments in MySQL Code?
- How to add comments in the style sheet blocks
- How to add code input in React.js?
- Java comments.
- What are the several ways to add comments in MySQL query?
- /** and /* in Java comments
- Comments in Java\n
- Executable Comments in Java
- How to add jQuery code to HTML file?
- How can we add different font style items to JList in Java?\n
- Java documentation comments
- How to use labels in Java code?
- How to Avoid Errors in Java Code?
- Types of Java comments.
- Java single line comments.

Advertisements