Comments In Java | Java Tutorial
In Java, we have two types of comments. We use comments to write some text within our code. The compiler will ignore these comments.
Syntax:
1 |
// Single line comment |
1 2 3 |
/* Multi line comments – Line 1 Multi line comments – Line 2 */ |
Note: Comments in between the code gives more readability
Do you want to show auto-generated code whenever you create a new class as shown below?
Follow the below steps:
I assume you are using Eclipse IDE.
1. In eclipse, Go to Window – Preferences
2. From the left panel, Select Java – Code style – Code template
3. Under ‘Configure generated code and comments’, Expand Comments – Select Files and Click Edit and Enter your text and click OK.
Whenever you create a new class, you can see comments.
Sample Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
package classOneGeneral;  public class Comments { public static void main(String [] args){ // Single line comment - Below statement outputs the string "I am learning Java from SoftwareTestingMaterial" System.out.println("I am learning Java from SoftwareTestingMaterial"); /* Multi line comments – Below statement outputs the string Multi line comments – "I am learning Java from SoftwareTestingMaterial" */ System.out.println("I am learning Java from SoftwareTestingMaterial"); }  } |
Must Read:Â Java Tutorial