Home >Java >javaTutorial >How to add different comments in Java code?
#Java comments are statements that are not executed by the compiler and interpreter. Comments can be used to provide information about variables, methods, classes, or any statement. It can also be used to hide program code at a specific time.
Annotations in Java are divided into three types.
Single-line comments begin with // Start and end at the end of the line.
public class SingleLineComment { public static void main(String[] args) { // To print output in the console System.out.println("Welcome to Tutorials Point"); } }
Welcome to Tutorials Point
Multi-line comments end with /*starting with*/ and span multiple lines.
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"); } }
Welcome to Tutorials Point
Documentation style comments end with /**&*/ and span multiple lines. Documentation comments must immediately precede a class, interface, method, or field definition.
/** 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"); } }
Welcome to Tutorials Point
The above is the detailed content of How to add different comments in Java code?. For more information, please follow other related articles on the PHP Chinese website!