- Comments are meta-data in a program.
- While the code is the data, comments provide information about the code, making them meta-data.
- Compilers ignore comments and they don't affect the execution of the program.
- Single-line comments: Denoted by
// - Multi-line comments: Denoted by
/* ... */ - Documentation comments: Denoted by
/** ... */
- Syntax:
// This is a single-line comment - These comments are used for short explanations or notes and don't span multiple lines.
- Never compiles, Never included in docs.
- Example:
// This is a simple single-line comment int x = 10; // Variable initialization
- Syntax:
/* This is a multi-line comment */ - These comments span multiple lines and are useful for providing detailed descriptions.
- Never compiles, Never included in docs.
- Example:
/* This is a multi-line comment. It can span multiple lines without the need to use double slashes. */ int y = 20;
-
Syntax:
/** This is a documentation comment */ -
Used for generating documentation with tools like Javadoc.
-
These comments can be used to explain the purpose of classes, methods, or fields in detail.
-
Javadoc comments are typically used to generate HTML documentation for Java classes.
-
Never compiles, but included in docs.
-
Example:
/** * This method calculates the sum of two integers. * @param a First integer * @param b Second integer * @return The sum of a and b */ public int sum(int a, int b) { return a + b; }
Javadoc Tool: The javadoc command can generate HTML, CSS, and JavaScript documentation from these comments.
javac File.java
javadoc File.java- Free License: Java can be installed and used without cost.
- Free Libraries: Java provides a wide range of libraries for free.
- Free Documentation: Official Java documentation is freely available.
-
OpenJDK:
- Open-source version of Java SE.
- Free to use, modify, and distribute.
- Suitable for development and personal use.
-
Commercial JDK:
- Provided by Oracle.
- Required for production server use.
- May have licensing fees for enterprise features (e.g., Java Mission Control).
- Free to Use: OpenJDK is available at no cost and can be modified.
- Community Support: Java has a strong, active open-source community.
- Wide Adoption: Java is used widely due to its stability and scalability.