---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 14 Edition"
java_version: 14
chapter: "Chapter 3. Lexical Structure"
section: "3.7"
heading: "3.7. Comments"
parent: "Chapter 3. Lexical Structure"
source: https://docs.oracle.com/javase/specs/jls/se14/html/jls-3.html#jls-3.7
id: "3.7"
url: https://jvm.obfuscated.software/jls/se14/3.7.html
raw: https://jvm.obfuscated.software/jls/se14/3.7.md
---

# 3.7. Comments

There are two kinds of comments:

- `/*` *text* `*/`

  A *traditional comment*: all the text from the ASCII characters `/*` to the ASCII characters `*/` is ignored (as in C and C++).

- `//` *text*

  An *end-of-line comment*: all the text from the ASCII characters `//` to the end of the line is ignored (as in C++).

```
Comment:
  TraditionalComment
  EndOfLineComment

TraditionalComment:
  / * CommentTail

CommentTail:
  * CommentTailStar
  NotStar CommentTail

CommentTailStar:
  /
  * CommentTailStar
  NotStarNotSlash CommentTail

NotStar:
  InputCharacter but not *
  LineTerminator

NotStarNotSlash:
  InputCharacter but not * or /
  LineTerminator

EndOfLineComment:
  / / {InputCharacter}
```

These productions imply all of the following properties:

- Comments do not nest.
- `/*` and `*/` have no special meaning in comments that begin with `//`.
- `//` has no special meaning in comments that begin with `/*` or `/**`.

As a result, the following text is a single complete comment:

```
/* this comment /* // /** ends here: */
```

The lexical grammar implies that comments do not occur within character literals ([§3.10.4](3.10.4.md)) or string literals ([§3.10.5](3.10.5.md)).
