Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials
  

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Java Comments

                         

To comprehend any programming language, there are several kind of comments which are used. These comments are advantageous in the sense that they make the programmer feel convenient to grasp the logic of the program. Although these comments are ignored by the Java compiler, they are included in the program for the convenience of the user to understand it. To provide the additional information about the code, use comments. These comments give the overview of the code in the form of the information which is not available in the code itself. 

There are three types of comments used in Java. These are:

1. // text
   
To add a comment to the program, we can use two slashes characters i.e. //. The line starting from slashes to the end is considered as a comment. We can write only a single line comment use these slashes. For instance

/
/ This comment extends to the end of the line.
// This type of comment is called a "slash-slash" comment

2. /* text */
   To add a comment of more than one line, we can precede our comment using /*. The precise way to use this is to start with delimiter /* and end with delimiter */.  Everything in between these two delimiters is discarded by the Java compiler. For instance

/* This comment, a "slash-star" comment, includes multiple lines.
* It begins with the slash-star sequence (with no space between 
* the '/' and '*' characters) and extends to the star-slash sequence.
*/
Slash-star comments may also be placed between any Java tokens:
int i = /* maximum integer */ Integer.MAX_VALUE;

3. /** documentation */
   
This is a special type of comment that indicates documentation comment. This type of comment is readable to both, computer and human. To start the comment, use /** instead of /* and end with */. This type of comment is a documentation which is interpreted as an official document on how the class and its public method work. For instance

/** 
* These are used to extract documentation from the Java source. 
*/

Comments in String Literals
Comments occurring in string literals are not parsed as comments. Like,
String text = "/* This is not a comment */";

Unicode Characters in Comments
Remember that Java still interprets Unicode sequences within comments. For example, Java compiler processes the Unicode sequence \u002a\u002f (whose codepoints correspond to */) of the source file, even before comments are processed. So we can use this format for Unicode characters.

/* This is a comment. \u002a\u002f
String statement = "This is a comment.";

and is lexically equivalent to

/* This is a comment. */
String statement = "/* This is a comment. */";
(The '*' character is Unicode 002A and the '/' character is Unicode 002F).

This also applies to newline characters in slash-slash comments.
For example:

//This is a single line comment \u000a This is code
That is because the \u000a is the Unicode for a new line, here the compiler thinks that you have added a new line.
This may be useful when declaring more than one thing on a line and you still wish to use // type comments
int x = 0; //X is the value of the carr \u000a int y=0; //Y is the intrest

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.