Comments in Java
Comments in Java
Comments in any programming language are ignored by the compiler or the interpeter. The programmer uses it to
either explain a block of code or to avoid the execution of a specific part of the code while
testing.
There are two types of comments:
- Single-line comment
- Multi-line comment
Single/In-line comment
To write a single-line comment just add a ‘//’ at the start of the line.
Example
public class Main {
public static void main(String[] args) {
//This is a single line comment
System.out.println("Hello learnwithvaigandla");
}
}
Output
Hello learnwithvaigandla
Multi-line comment
To write a multi-line comment just add a ‘/*…….*/’ at the start of the line.
Example
public class Main {
public static void main(String[] args) {
/*This
is
a
Multi-line
comment
*/
System.out.println("Hello learnwithvaigandla");
}
}
Output
Hello learnwithvaigandla
Data types in Java
Data types in Java Data types represent the different values to be stored in the variable. There are two forms of Data types in Java.
Syntax of Java
Simple program in Java | Hello world Example We will create a file called Main.java and we use the following code to print "Hello learnwithvaigandla" to the screen.
Comments
Post a Comment