- Introduction to Comments in Java in Hindi
- Types of Comments in Java in Hindi
- Java single line comment
- Java Multi-Line comment
- Java documentation comment

Introduction to Comments in Java
जावा comments वह बयान है जो कि compiler और interpreter द्वारा निष्पादित नहीं किये जाते हैं। Comments का उपयोग variable , method, class या किसी statement के बारे में जानकारी या स्पष्टीकरण प्रदान करने के लिए किया जा सकता है । इसका उपयोग प्रोग्राम कोड को छिपाने के लिए भी किया जा सकता है।
जावा comments के प्रकार? (Types of Comments in Java in Hindi)
Java में तीन प्रकार की comments हैं।
- Single line comment
- Multiline comment
- Documentation comment
1) Java single line comment
सिंगल लाइन comment का उपयोग केवल एक लाइन comment करने के लिए किया जाता है।
Syntax:
//This is single line comment
उदाहरण:
public class CommentExample1 {
public static void main(String[] args) {
int i=10;//Here, i is a variable
System.out.println(i);
}
}
आउटपुट:
10
2) जावा मल्टी लाइन comment
मल्टी लाइन comment का उपयोग कोड की कई लाइनों पर comment करने के लिए किया जाता है।
Syntax:
/*
This
is
multi line
comment
*/
उदाहरण:
public class CommentExample2 {
public static void main(String[] args) {
/* Let's declare and
print variable in java. */
int i=10;
System.out.println(i);
}
}
आउटपुट:
10
3) जावा documentation comment
Documentation comment का उपयोग documentation API बनाने के लिए किया जाता है। Documentation API बनाने के लिए, आपको javadoc टूल का उपयोग करना होगा ।
Syntax:
/**
This
is
documentation
comment
*/
उदाहरण:
/** The Calculator class provides methods to get addition and subtraction of given 2 numbers.*/
public class Calculator {
/** The add() method returns addition of given numbers.*/
public static int add(int a, int b){return a+b;}
/** The sub() method returns subtraction of given numbers.*/
public static int sub(int a, int b){return a-b;}
}
इसे javac टूल द्वारा compile करें:
javac Calculator.java
Javadoc टूल द्वारा documentation API बनाएं:
javadoc Calculator.java
अब, वर्तमान directory में आपके calculator class के लिए बनाई गई HTML फाइलें होंगी । HTML फाइलें खोलें और documentation comment के माध्यम से प्रदान की गई कैलकुलेटर class की explanation देखें।