In this lecture, we'll run with you.
What comments are and what type of comments are available in Java source code and apart from that,
we'll talk together regarding Deep's and best practices while using comments.
First of all, let's come up with a common definition here.
The Java comments are statements that are not executed by GBM.
The comments can be used to provide information or explanation about the variable method class or any
statement.
It can also be used to hide program code temporarily.
Comments often used to live so-called to do comments mentions.
Do not forget to restructure code or to add something in the future.
There are three types of comments in Java.
Single line, multiline and Javadoc.
Let's take a closer look at how comments are looked like in our clip's workspace.
Here is our hello world application, which we all know, let's add a single line comment right after
console output.
That was to do at more court here in the future.
By the way, in the clips, if you want to find all to do comments in your code, just go to window
shoyu desks.
Here it is.
Just don't forget to save your file before that eclipse passes all to the comments and lists it here.
I used this too many times.
There is a hotkey for single line comment.
For example, you can comment this code line by pressing control plus slash and uncommented in the same
way.
You can select few lines, for example, the whole method, and call it the same way with hotkeys.
And uncommented, if you wish, with the hotkeys now let's create multiline common type slash asterisk
and enter.
You see how Eclipse helps us to write Multiline Command, you can type something like this, please
do not remove this quote.
And now let me show you, Javadoc, the first thing you should know about Javadoc is that this type
of comments can be converted to nice looking TAMAO pages in JDK.
We have Javadoc program which generates these e-mail pages out of our source code.
Let me show you example.
Here is official javadoc of string class.
You can see class description, constructor, fields' methods.
All of them are clickable.
For example, let me click here.
You can generate the same documentation.
Let's learn how to do this.
Let's create Java documentation for our main method.
Slash Nebel Asterisk Enter.
And here your comment goes the entry point to that program.
You can see the stack there, it is used to add parameter to parameter section in Javadoc, I will share
with you more tags to learn in the homework section.
Meanwhile, let's add clarification here.
Input arguments.
Let's also add Javadoc to our class.
You can see Ostertag here, I will leave the next comment here.
Hello, world application.
Now we can save the file, we are good to generate javadoc to generate javadoc from Eclipse Project,
generate javadoc you configurations you can configure output folder for your documentation.
I will leave default settings here and will press finish.
Now, you can see that dog directly appeared in our project, let's expand it, find index, dot Ashton,
nail file and open it.
You can open it in any browser or you can just use built in Eclipse browser.
Right.
Click open with Web browser.
And here we have our documentation, congratulations.
This is your first documentation to your first program.
You see our class here.
Here's our class description.
Orser Constructor's Method's, here is our main message description.
And here's our arguments description.
Let me share with you tips and best practices of using comments in Java.
The first thing you need to remember in case you want to comment, chunk of code to hide this code,
just remove it if you don't need this code.
That means you don't need this code.
I faced with this so many times when developers comments there or others code and leave it just in case.
Be smart, you will learn how to use version control systems.
And believe me, there is no such cases when you need to leave code just in case, especially when you
have a version control system, because this will end up having a lot of comment at code, which nobody
knows what is it for and you won't be able to support it.
My next advice always remember that comments require maintenance.
You need to keep them up to date and relevant.
Don't forget about this.
I'm trying to be a good tutor and I am saying that right in Javadoc is great.
But also I have to prepare you for real life.
In real life.
You would notice that not all developers write comments.
Why?
Because sometimes they are not needed because you have live documentation, your unit tests in your
test data as you change your code.
We'll discuss in later lessons Giggie approach and goals of unit testing.
But for now, just remember, in case you have solid unit test code coverage and you follow Jawa naming
conventions and choose meaningful names for variables and methods, sometimes javadoc in this case is
redundant so they will learn what comments are.
Now we also know what types of comments we have in Java.
You saw how to generate Javadoc from the source code and also I shared with you tips and best practices
of common usage in real life.
And your homework created Javadoc for your Hello World application and generate documentation from your
source code.
Also, during the lesson you saw only a few javadoc decks.
There are no need to go over each of them because most of them self describing, you know, already
how to use them.
Just take a look through this table to know what other text you can use.