Share your knowledge with other learners . . . Write As Guest

Comments program में line of code होता है जो कि execute नहीं होता है। Comments को code को explain करने के लिए use किया जाता है , जिससे कि जब दुबारा हम उस program पर काम करे तो हर step हमें समझ आ सके कि हमने इसमें किया क्या था।

Types of comments in Java

Java में Comments दो तरह के होते है -

  1. Single Line Comments
  2. Multi Line Comments

Java Single Line Comment

Java में single line comment को double slashes // की help से लिखा जाता है , जैसा कि आप नीचे example में देख सकते हैं ।

File : HelloWorld.java

CopyFullscreenClose FullscreenRun
class HelloWorld 
{
   // this is single line comment.
   public static void main(String[] args) 
   {
      // print hellow world.
      System.out.println("Hello World!"); 
   }
}
Output
javac HelloWorld
java HelloWorld
Hello World!

Java Multi Line Comment

multi line comment लिखने के लिए slash asterisk /* से start करते हैं और asterisk slash */ से end करते है।

File : HelloWorld.java

CopyFullscreenClose FullscreenRun
class HelloWorld 
{
   /**
   * this is multi line
   * comment
   */
   public static void main(String[] args) 
   {
      System.out.println("Hello World!"); 
   }
}
Output
javac HelloWorld
java HelloWorld
Hello World!

Java Advantages Of Using Comments

  • किसी भी project पर काम करने के बाद हमें जरूरत के हिसाब से समय के साथ उसमे changes करने पढ़ ही जाते हैं तो जब हम update करें तो हमें proper पता चले कि हमने किया क्या था।

  • या जब कोई दूसरा programmer हमारे द्वारा develop किये गए project को देखे या update करे तो उसे भी पता चले।

  • Comments लिखना आपकी Coding Standardization को भी बताता है।

  • Comments लिखने से Coding Readability भी बढ़ती है।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers