Java Comments

Java Comments

When you create a New Project in NetBeans, you’ll notice that some text is greyed out, with lots of slashes and asterisks:

The Java coding window

The greyed-out areas are comments. When the programme runs, comments are ignored. So you can type whatever you want inside of your comments. But it’s usual to have comments that explain what is you’re trying to do. You can have a single line comment by typing two slashes, followed by your comment:

//This is a single line comment

If you want to have more than one line, you can either do this:

//This is a comment spreading
over two lines or more

Or you can do this:

This is a comment spreading
over two lines or more

In the comment above, note how it starts with /*. To end the comment, we have */ instead.

There’s also something called a Javadoc comment. You can see two of these in the coding image on the previous page. A Javadoc comment starts with a single forward slash and two asterisks (/**) and ends with an asterisk and one slash ( */ ). Each line of the comment starts with one asterisk:

This is a Javadoc comment

Javadoc comments are used to document code. The documented code can then be turned into an HTML page that will be helpful to others. You can see what these look like by clicking Run from the menu at the top of NetBeans. From the Run menu, select Generate Javadoc. There’s not much to see, however, as you haven’t written any code yet!

At this stage of your programming career, you can delete the comments that NetBeans generates for you. Here’s our code again with the comments deleted:

Coding Window - Java Comments Deleted

In the next part, you’ll learn about the structure of the above code, and how to run your programmes.


One thought on “Java Comments”

  1. Ahaa, itts plewasant dicussion abot this article aat this plqce att this weblog, I
    have resd all that, sso noww me alsso commenting here.
    Ahaa, iits pleasant disecussion rregarding thbis posdt aat thiss place att thjis
    webpage, I have reaad all that, sso att tgis tikme me
    also commenting aat tnis place. Thanhk you ffor thhe auspiciouss writeup.
    It inn fat was a amusemernt acxcount it. Loook adbanced tto ffar
    addded agreeable from you! By thee way, how coulod wee communicate?


Give A message for us

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s