In Java source code, which of the following is not a valid way to start a comment?

Difficulty: Easy

Correct Answer: /** **/

Explanation:


Introduction / Context:
Comments in Java source code allow developers to document their code and temporarily disable blocks without affecting compilation. Java supports several comment syntaxes, including single line comments, multi line comments, and documentation comments used by the Javadoc tool. This question asks you to identify which syntax is not a valid way to start or form a comment in Java, which helps you recall the exact structure required for each comment style.


Given Data / Assumptions:

  • We are working with standard Java comment syntax.
  • Single line comments start with two forward slashes.
  • Multi line comments start with /* and end with */.
  • Javadoc comments start with /** and end with */.
  • We must check whether each option forms a syntactically valid comment structure.


Concept / Approach:
Java recognises three basic comment forms. Single line comments start with // and continue to the end of the line. Traditional C style multi line comments start with /* and end with */; everything in between is ignored by the compiler. Javadoc comments are a special form of multi line comment that start with /** and also end with */; they are processed by the Javadoc tool to generate API documentation. Any pattern that does not match one of these forms or that is malformed (such as having extra characters in the closing delimiter) is not a valid comment structure and will cause compilation errors or unintended tokenisation.


Step-by-Step Solution:
Step 1: Examine //, which is the standard Java single line comment starter; this is valid and widely used. Step 2: Examine /* */, which is the standard multi line comment with correct opening and closing delimiters; this is also valid. Step 3: Examine /** */, which is the Javadoc comment form; it starts with /** and ends with */, which is valid both as a comment and for documentation tools. Step 4: Examine /** **/, which appears to have an extra asterisk near the closing delimiter; the correct form should still end with */, not **/. Step 5: Recognise that /** **/ does not match any defined Java comment syntax and is therefore not a valid way to form a comment.


Verification / Alternative check:
You can verify this by writing a small Java file and pasting /** **/ into it. The compiler is likely to interpret /** as the start of a Javadoc comment, but **/ will not close it properly, leading to an unterminated comment or unexpected token errors. In contrast, using //, /* */, or /** */ compiles correctly, with the commented section ignored as expected. This simple experiment confirms that /** **/ is not valid Java comment syntax.


Why Other Options Are Wrong:
Option //: This is a correct single line comment starter and is valid. Option /* */: This is a correct multi line comment form, valid in both C and Java. Option /** */: This is a correct Javadoc comment form, used to document classes, methods, and fields.


Common Pitfalls:
Developers sometimes accidentally type extra asterisks when writing Javadoc comments, which can confuse the compiler or documentation tools. Another pitfall is mixing up the order of the closing delimiter and writing /* **/ or other invalid combinations. It is important to remember that all multi line and Javadoc comments, regardless of the number of asterisks after the initial slash, must terminate with */. For exam purposes, you should be able to quickly recognise that /** **/ is not a supported comment syntax in Java.


Final Answer:
The option that is not a valid Java comment syntax is /** **/.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion