Java Essentials - Commenting techniques in java
2K views
Nov 18, 2024
Java Essentials - Commenting techniques in java Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Arnab Chakraborty, Tutorials Point India Private Limited
View Video Transcript
0:01
In this video we are discussing commenting techniques in Java
0:05
There are multiple different ways in which we can do the commenting in our Java program
0:11
So in programming comments are used to write some information or notes for code or problem discussion
0:17
So what is the purpose of a certain segment of the code? We can mention that one in the comment
0:22
So comment will produce or will keep some documentation in the source code itself
0:28
So that's why commenting is a good program. practice and it is one of the best programmers practice in this case so comment
0:35
lines are totally ignored by the compiler and it has got no effect in the output
0:40
of the program during the execution so comment lines will be totally ignored by
0:45
the compiler so no machine code will be produced in the compiled version of the
0:49
program but commenting and keeping this comments in our code is a good programmer's
0:54
practice it will depict that what is the purpose of this statement why you are
0:58
writing this next line and what is the respective algorithm we are going to use
1:02
So such documentation we can embed in our source code. So there are three types of comments available in Java
1:09
The first one is the traditional multi-line comment. So the comment line must be enclosed in between slash-star and start-slash
1:18
In this way, in between this slash-star and start-slash, we can keep multiple lines in the comment body
1:23
So single line comment so only a single line which will be preceded by the slash slash double slash will indicate and you can find there the font slashes so double font slash will indicate that there is a single line comment
1:36
next one is the java documentation comment it is very important you know so that is our slash
1:41
start start this is a documentation comment body and here we're having start slash so this is a
1:49
very important one because here we can produce the respective the documentation against our program
1:56
those lines which will be enclosed within this documentation comment the documentation comment is used to create documentation API to create
2:07
documentation API you need to use the Java doc tool so that will be one file
2:12
that is a Java doc.exc in our Windows environment if you load Java you can find
2:17
that this Java doc.exe this is a file there which will capable to produce the
2:22
documentation against the code let us suppose you have written one program
2:26
the program name is my class. Java. So these are source code and obviously the class is having the
2:33
name my class here. So within this my class, we have written this documentation comment in
2:38
multiple different places and this documentation comment must be enclosed within slash star star
2:43
and star slash. So this is a documentation comment which has got embedded in the different zone
2:48
of my code. So which will depict the purpose of different segments. And now if we use the command
2:54
that is a Java doc myclass java then it will create the HTML file and if you run those HTML files you can get that you are getting the documentation of the respective code so now there will be HTML files created for your my class class
3:10
in the current directory and open the HTML files and see the explanation of my class
3:16
class provided through documentation comment so whatever you'll be writing in this documentation
3:21
comment that will be coming in the HTML body for the documentation so let us go for one demonstration
3:27
for the better understanding on this commenting techniques in our in our Java
3:32
programming in case of Java we can have the single-line comment that means one
3:38
comment line can be inserted in our code we know that comment line will not have
3:43
any effect in the outcome when the program will be in execution comment line
3:47
will be simply ignored in the execution so here to have the single-line
3:52
comment we are supposed to put slash slash that is a double front slash and this is
3:57
a single line comment and up to the end of the line the comment will be maintained
4:02
So that is a way to have the single end comment here. So let us suppose I want to put them in the single and comment as a block I want to put them
4:09
in eclipse where having an option that is a source toggle comment
4:13
You can find that this full block, this full line of codes, whatever the number of lines you
4:18
have selected they will be under this single end comment and that is a toggle type one
4:23
So you can mark them and you can go for. toggle comment so they become uncommented you can make them as comment so that is our single end comment but if you want to go for the multi comment so that can be done in this way You see the lines are not commented here
4:41
So you can go for this and go for add block comment. So in this way you can find that in case of block comment
4:47
all these lines will be enclosed within slash start and start slash here
4:52
And that is known as the block comment. So in this way you can also do that one
4:56
You can remove it if you require to do so. Eclipse is giving us. that option to do. There is a remove block comment
5:04
Respective shortcut keys are also given. You can apply them. So that is removing the
5:10
block comment. Otherwise we can also go for this. You can mention that slash star. Now in
5:16
this way you can put multiple lines under this comment. So I'm just copying this one
5:25
If I'm to put it here, you can easily find that you can easily put these lines under the
5:29
comment so that is another way you can do it there is another way you can do it
5:34
so that is our multi-line comment and you can go on expanding so in this way you can
5:48
also go for block comment in our Java so this demonstration is for how to make a
5:54
single-line comment and multi-land comment and how to take the help of eclipse editor
5:59
the respective ID with the help of which you can do the same as when required. Thanks for watching this video
#Java (Programming Language)