KUKLEE GK PRO

Comments in Java

Java Tutorial - Comments in Java
Comments in Java

Introduction

Java में Comments का उपयोग दूसरे Programmers को program के codes को समझाने या स्वयं याद रखने के लिए किया जाता है, कि वे codes किस लिए लिखे गए हैं तथा उसके क्या काम है, जिससे दूसरे Programmer को समझाने या स्वयं याद रखने में आसानी होती है। इसका उपयोग प्रोग्राम के codes को hide (छिपाने) करने के लिए भी किया जा सकता है, क्योंकि Comments को Compiler नज़रअंदाज़ कर देता है।


Types of Comments in Java

Java में तीन प्रकार के Comments होते हैं -

  1. Single Line Comment
  2. Multi Line Comment
  3. Documentation Comment

1. Single Line Comment

जब एक line का या छोटे - छोटे comments लिखने होते है, तब Single Line Comments का उपयोग किया जाता हैं।

Creating a Single Line Comment
Double slash लगाकर Single Line Comments बनाया जाता है।

//This is single a line comment

Example :
class HelloWorld { 

public static void main(String args[]){  

         //This is single a line comment

         System.out.println("Single line Comment");
      } 


2. Multi Line Comment

जब कई Lines के या बड़े - बड़े comments लिखने होते है, तब Multi Line Comments का उपयोग किया जाता हैं।

Creating a Multi Line Comment
Multi Line Comment बनाने के लिए comments को /*.......*/ के बीच में लिखा जाता है।

/* This is a Multi Line Comment.
Comment 2
Comment 3
Comment 4
.......
.......
*/

Example :
class HelloWorld { 

public static void main(String args[]){  

 /* This is a Multi Line Comment
Comment 2
Comment 3
Comment 4
.......
.......
*/

         System.out.println("Multi line Comments");
      } 


3. Documentation Comment

Documentation Comment का उपयोग Documentation API बनाने के लिए किया जाता है।  javadoc tool का उपयोग Documentation API बनाने के लिए किया जाता है।

Creating a Documentation Comment
Documentation Comment बनाने के लिए comments को /**.......*/ के बीच में लिखा जाता है।

/** This is a Documentation Comment.
Comment 2
Comment 3
Comment 4
.......
.......
*/

Example :
class HelloWorld { 

public static void main(String args[]){  

/** This is a Documentation Comment
Comment 2
Comment 3
Comment 4
.......
.......
*/
         System.out.println("Multi line Comments");
     } 
🏠Home 📝Quiz