1+ /**
2+ * Day 01 - Comments.java
3+ * Understanding Comments in Java
4+ *
5+ * This program demonstrates the three types of comments in Java:
6+ * 1. Single-line comments
7+ * 2. Multi-line comments
8+ * 3. Documentation comments (JavaDoc)
9+ */
10+
11+ /**
12+ * This is a documentation comment (JavaDoc)
13+ * It's used to generate documentation for your code
14+ *
15+ * @author Your Name
16+ * @version 1.0
17+ * @since 2025
18+ */
19+ public class Comments {
20+
21+ // This is a single-line comment
22+ // It starts with // and continues to the end of the line
23+
24+ /*
25+ * This is a multi-line comment
26+ * It starts with /* and ends with */
27+ /*
28+ * You can write multiple lines
29+ * of comments like this
30+ */
31+
32+ /**
33+ * Main method - demonstrates different comment types
34+ * @param args command line arguments
35+ */
36+ public static void main (String [] args ) {
37+ // Print information about comments
38+ System .out .println ("=== Java Comments Demo ===" );
39+ System .out .println ();
40+
41+ // Demonstrate single-line comments
42+ System .out .println ("1. Single-line comments:" );
43+ System .out .println (" // This is a single-line comment" );
44+ System .out .println ();
45+
46+ // Demonstrate multi-line comments
47+ System .out .println ("2. Multi-line comments:" );
48+ System .out .println (" /* This is a multi-line comment */" );
49+ System .out .println ();
50+
51+ // Demonstrate documentation comments
52+ System .out .println ("3. Documentation comments:" );
53+ System .out .println (" /** This is JavaDoc comment */" );
54+ System .out .println ();
55+
56+ // Show best practices
57+ System .out .println ("Best Practices:" );
58+ System .out .println ("- Use comments to explain WHY, not WHAT" );
59+ System .out .println ("- Keep comments up to date with code changes" );
60+ System .out .println ("- Use meaningful variable and method names" );
61+ System .out .println ("- Write self-documenting code when possible" );
62+
63+ // Calculate and display a simple example
64+ int number = 42 ; // This is the answer to everything
65+ System .out .println ("\n Example: The number is " + number );
66+ }
67+
68+ /**
69+ * This method demonstrates how to use JavaDoc comments
70+ * for documenting methods
71+ *
72+ * @param name the name to greet
73+ * @return a greeting message
74+ */
75+ public static String greet (String name ) {
76+ return "Hello, " + name + "!" ;
77+ }
78+ }
0 commit comments