Java Comments


The computer programs use comments to embed information in its source code. Different programming languages have their own set of rules defined in the program’s specification. Not only this, the syntax for writing comments varies from one programming language to the other. Most of the programming languages ignore comments when their compiler debugs a programming language.

Java uses comments to document the computer program. The comments also act as a reference point for other programmers of things the code contains. The comments in any programming language help programmers in debugging a code. Not only this, they can also be used by a large program for documentation purposes.  Comments help in integrating the source in with source code management systems and other kinds of external programming tools.

On the other hand, a program with awkward comments can even lead to errors in a code that can be difficult to debug. Also, a comment with improper syntax, can lead the debugger using it as a normal programming code.  Many times a lot of unwanted information is also stored as comments.

An example of a comment is given below:

max = 1000;   // This is the default value.

/* check input for valid values and print error message for if problems exist.  */

This program code uses two different types of comments, namely the end-of-line comments and the block comments. An end-of-line comment terminates at the end of the line where it is specified. The block comment on the other hand can continue for several lines or end in one single line depending on its terminator.

Programmers have been using comments for a long time now.  Programs such as BASIC and COBOL use remarks, which are nothing but comments. Similarly, the language ALGOL 60 uses the reserved word comment to start the comment and a semicolon to end or terminate it.

Comments are important and should be used with utmost care. Consider the following issues when designing comments

  • Where do comments start from? Do they start from a particular place in the computer program or are placed anywhere inside a computer program?
  • How do they end or terminate? You can end or terminate the comments by using a comment terminator like Java */.
  • Is it possible to form nested comments? If it is possible, then what is the syntax for doing it?

Modern programming languages do answer some of these questions, while others still remain unresolved.

Some examples of comments in the Java programs are:

  • // text: When a debugger comes across // symbol, it ignores all the characters from // to the end of the line.
  • * text *: When a debugger comes across /* or */symbol, it ignores all the characters from /* to */ to the end of the line.
  • /** text */ : A debugger treats the /** text */ in an exclusive  manner, especially if it comes across these characters before any variable or constant or any other data type is defined.  Such comments are exclusively reserved for declaration and should not be used in any other part of the code.  The /** text */ comments indicate that the text enclosed in /** text */ symbol should be included in a documentation as a description of the declared item.

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>