Java TUTORIAL for beginners
It is always a good idea to add lots of comment in the source code. This makes the program easy to understand for others. More importantly, it is easy for youself, should you need to refer your own code a couple of years later.
Adding comments in Java is no different than adding comments in C or javascript. There are two ways you can add comments in Java. The single line comments start with // and can be instered at the end of a Java statement. Look at the following example
|
There is absolutely no difference in the way the program compiles or gives output. Everything is same. All we have done is addes two comments. In complex programs, comments do wonders in enhancing the readability of the code.
A multiline comment starts with /* and ends with */. See how a multiline comment looks like.
|
As you can see, the multiline comments come handy if you wish to provide more information about your source code.
There is yet another type of comment that starts with /** and ends with */. In terms of functionaliry it is same as the one that starts with /* and ends with */. The only difference is it is called a documentation comment. The JDK javadoc tool uses doc comments when preparing automatically generated documentation.
In the next post we will spend a little bit of time understanding the code behind our Hello World program