Comments in Java

Comments in Java, writing comments in Java programs, Java single line comments, Java multi-line comments, and Java documentation comments.

Comments are English words used for code readability and code documentation.

Java Comments – Java for Selenium

1. Purpose of Comments

The Java comments are the statements that are not executed by the compiler and interpreter.

The comments can be used to provide information or explanation about the variable, method, class, or any statement.

The comments can be used to hide program code.

Note: The primary purpose of comments is to make the code understandable and the secondary purpose of comments is to make the code prevent execution.

2. Comments Syntax in Java

In Java there are three types of comments:

a. Single – line comments.
b. Multiline comments.
c. Documentation comments.

a. Use // for Single line comment

b. Use /*………….
…………………
…………………
………………*/ for Multiple line comment

Or
Comment Multiple Lines

(Eclipse IDE)
Select Statements/Steps
Source Menu -> Add Block Comment

Uncomment

(Eclipse IDE)
Select Comment block
Source Menu -> Remove Block Comment

c. Documentation Comments

This type of comments are used generally when writing code for a project/software package since it helps to generate a documentation page for reference.

Syntax:

/**Comment start
*
*tags are used in order to specify a parameter
*or method or heading
*HTML tags can also be used
*such as <h1>
*
*comment ends*/

3. Example:

public class Sample2 {

public static void main(String[] args) {
int a, b; //Variables Declaration
a =10; b=20;
int c = a+b;
//Display the Addition value of a and b
System.out.println(“Addition of a, b is: “+c);
System.out.println(“”);

/*if (a > b) {
System.out.println(“A is a Big Number”);
}
else
{
System.out.println(“B is a Big Number”) ;
}*/

}
}

4. Usage of Comments in Test Automation

a) To Write Test case header

b) To Write Method header

c) To Explain Complex Logic


Selenium Tutorial for Beginners

0. Selenium Tutorial – 0. Prerequisites to Learn Selenium
1. Selenium Tutorial – I. Introduction – 1. Selenium Syllabus
2. Selenium Tutorial – I. Introduction – 2. An Overview of Selenium
3. Selenium Tutorial – II. Java for Selenium – 1. Introduction to Java
4. Selenium Tutorial – II. Java for Selenium – 2. An overview of Java
5. Selenium Tutorial – II. Java for Selenium – 3. Java Environment Setup
6. Selenium Tutorial – II. Java for Selenium – 4. Java Keywords and Identifiers
7. Selenium Tutorial – II. Java for Selenium – 5. Java Basic Syntax
8. Selenium Tutorial – II. Java for Selenium – 6. Java Program Structure
Follow me on social media: