---
title: "Java: Comments"
date: 2015-01-01
description: "Tom Johnson’s blog on technical writing and AI: agent skills, docs for AI agents, docs-as-code, tech comm careers, and an API documentation course."
canonical_url: https://idratherbewriting.com/java-comments/index
---

> For AI agents: a documentation index is available at https://idratherbewriting.com/llms.txt. Markdown versions of all pages are available by appending .md to any page URL.

# Java: Comments

End of line comments:

```java
// comment
```

Convenient but if you write code after the //, it all gets grayed out.

Block comments:

```
/* comment */
```

Advantage is that they can appear anywhere, span multiple lines, etc.

> And here’s a line of code with a comment in the middle of it:
>
> int counter /* comment */ = 0; Please don’t do that. It’s legal, but it’s poor coding practice, because it makes the code harder to read. – Java 7 for Absolute Beginners

Note that Javadoc comments are similar to block comments but with an extra asterisk at the beginning:

> /** * This method makes a Cat object chase the given Mouse object. * [@param](https://github.com/param) mouse an instance of the Mouse class for our cat to chase */’ – Java 7 for Absolute Beginners

Really important tip: Don’t worry about line breaks when you’re writing comments. Press Command + Shift + F and it formats everything. You want to keep comments to about 80px. Get into the issue of line breaks with code. Sometimes line breaks with commands can be problematic – such as wrapping comment code.
