Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Language Java Comments

Related Tutorials


 
 

Share on Google+Share on Google+

Java Comments

Advertisement
To comprehend any programming language, there are several kind of comments which are used.

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

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 9, 2007

Related Tutorials

Discuss: Java Comments   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:7
Ashok Kumar Singh
May 24, 2011
What are comments and its types?

Comments improve the readability of a program. They are ignored by the compilere and will not be executed. Single line comments: If a line of text begins with // , then it will be treated as a single line comment. Multi-line comments: Any text or lines of text written within /* ...*/ is treated as a comment.
zacharia mrisho
May 31, 2011
more powerfull language

hey guys. am an electronic scientist. i wanted to know, between java and C programming languages, which one is more powerful when it comes to direct communication with hardware devices?
Vinoth
June 18, 2011
Suggestion

I know c and c languages...i want to know java ..is it easy to learn or not:)
dhruva
October 25, 2011
syntax

import java.util.Scanner; public class test { public static void main(String args[]) { float quarter[]; int comAmt,i; float topup[],totaltopup=0,quarterBonus[],totalQuarter=0,annualBonus,totalquarterBonus=0; float totalBonus,total; quarter=new float[4]; topup=new float[4]; quarterBonus=new float[4]; addthis ob=new addthis(); verexchange a=new verexchange(); System.out.println("Quarterly Bonus Rate is: "+a.quarterlyRate); Scanner in = new Scanner(System.in); System.out.println("Enter Commited Amount "); comAmt = in.nextInt(); for(i=0;i<4;i++) {System.out.println("Enter Amount for Quarter"+(i+1)); quarter[i] = in.nextInt(); totalQuarter=totalQuarter+quarter[i];} ob.PrintArray(quarter); System.out.println(" The Commited Amount is"+comAmt); for(i=0;i<4;i++) {if(quarter[i]>(3*comAmt)) topup[i]=(float) (0.75*(3*comAmt)); else topup[i]=0;} for(i=0;i<4;i++) totaltopup=totaltopup+topup[i]; for(i=0;i<4;i++) {if(quarter[i]>(3*comAmt)) quarterBonus[i]=(float) (0.03*(3*quarter[i])); else quarterBonus[i]=0; totalquarterBonus=totalquarterBonus+quarterBonus[i];} if(totalQuarter>(12*comAmt)) annualBonus = (float) (0.05*totalQuarter); else annualBonus=0; totalBonus= ob.ArraySum(annualBonus, totalquarterBonus); total=totalBonus+totalQuarter+totaltopup; for(i=0;i<4;i++) System.out.println(" The Quarterly Bonus is"+quarterBonus[i]); System.out.println(" The Total Quarterly Bonus is"+totalquarterBonus); System.out.println(" The Annual Bonus is"+annualBonus); System.out.println(" The Total Bonus is"+totalBonus); System.out.println(" The Amount Paid at end of year is"+total); } }
Edossa Kenea
February 22, 2012
Freedom

/* Class i and my familie's by freedom keeping modern international rule of low bealive live{ Public string void main(string args[]){ String.out.printIn("i and my familie's by freedom keeping modern international rule of low live;"); } } */
anonimous
May 13, 2012
java programming

The dialog box will be centered over the component given in the first parameter. Typically you would give the window over which it should be centered. If your program doesn't have a window, you may simply write null, in which case the dialog box will be centered on the screen.
marion
July 13, 2012
where can i exercise in your site?

hello, where can i exercice programming in your site? it's will be better to me to exercise directly in your site, and not to download a java. Because in my country, Internet is expensive. and if i have problems issues in my programs, i could ask you directly. And i insist, try to create this site in french. I don't understand well english.
DMCA.com