Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are Java comments different colors in Eclipse?

I'm new to Eclipse and I'm using for some Android development. Eclipse is making me increasingly aware of poor habits I've formed (I.E. not capitalizing class names, etc.).

One thing I've noticed is that when I use the // characters to comment, the text turns green, but when I use the /** **/ characters, the text turns light blue. Is there a reason for this? Some type of comment specification that I missed somewhere? Are these supposed to serve as different functions for different types of comments?

I'm running Helios Service Release 1 (Build 20100917-0705) for Win 7(x64) if that makes any difference.

like image 856
josh-cain Avatar asked Mar 24 '11 02:03

josh-cain


People also ask

What are the differences of Java comments?

Java supports two types of comments: /* multiline comment */ : The compiler ignores everything from /* to */ . The comment can span over multiple lines. // single line : The compiler ignores everything from // to the end of the line.

What are the two types of Java comments?

Java programs can have two kinds of comments: implementation comments and documentation comments. Implementation comments are those found in C++, which are delimited by /*... */, and //. Documentation comments (known as "doc comments") are Java-only, and are delimited by /**...

What are three different types of comments used in Java?

In Java there are three types of comments:Single-line comments. Multi-line comments. Documentation comments.


2 Answers

Block comments that start with /** in java are javadoc comments. Eclipse colors them differently to set them apart from normal comments.

Here's a guide that discusses how to write documentation comments for java: http://www.oracle.com/technetwork/java/javase/documentation/index-137868.html

When you hover over a class/method/field that has a javadoc comment in Eclipse, you'll see a little documentation popup that contains a formatted version of the javadoc comment for that class/method/field.

You can also use the javadoc command-line tool to generate HTML documentation for your packages and classes. When you do this, the tool uses the javadoc comments in your source code to build the documentation.

like image 142
Greg Avatar answered Oct 11 '22 14:10

Greg


Eclipse comment defaults:

  • // and /* .. */ are standard comments and show up in one color, green
  • /** ...... **/ are javadoc comments and show up in a different color, blue
like image 21
Andy Avatar answered Oct 11 '22 13:10

Andy