This is the third day of my participation in Gwen Challenge
Writing programs requires not only efficient code, but also comments. ** A qualified source code includes at least 1/3 of the comments! 支那Copy the code
Why are comments so important?
So we first need to know what comments are for. Comments are used to explain the purpose of the code. They can explain what a class does, what a method does, what a variable does, and so on.
So why do you have to write comments? Because when you’re on the right track, it’s easy to write code, but when you look at the code you’ve written after a while, what do you see? This is the code I wrote?? The human brain is limited, and there’s a huge chance that you won’t be able to read the code you wrote. This is a pain in the ass, so get in the habit of writing comments early on.
There are three Java document annotation methods
- Single-line comments
2. Multi-line comments 3
Single-line and multi-line comments
Single-line comment is to add (//) at the beginning of the line. Multi-line comment is to add (/ *) at the beginning of the required comment and (*/) at the end, for example: public class Hello {/* Here is a multi-line comment. Welcome to Java! */ public static void main(String[] args){// system.out.println (" this is a single line comment "); }}Copy the code
Documentation comments
The Java language also provides document annotations, which are even more powerful!! It uses the JAVadoc tool provided by the JDK to extract the document annotations directly from the source code into a system API document, which can be opened through the web page.
Speaking of API, this should be a necessary skill for every programmer. Java API contains the introduction of Java classes and methods. Learning to view API is of great help for us to learn Java, there are so many classes in Java, we can not remember them all. We can open the API documentation to query the class and the specific use of the methods contained in the class.
Back to the topic, what is the format of a document comment? Document comments start with (/**) and end with (*/), with the contents of document comments in between
Public class Hello {/** * Welcome to the Java world! */ public static void main(String[] args){// system.out.println (" this is a single line comment "); }}Copy the code
So how do you generate API documentation?
The javadoc command is required. The syntax is as follows: Javadoc parameters Java source files/packages Javadoc parameters are as follows:
-d folder; // To specify the directory to place the generated API file -windowTitle title; // Use to specify a title as the title of the API document browsing window -doctitle title; // Use to specify the browser page title -header header; // Used to specify the header for each pageCopy the code
The following is an API document I generated, we also hurry to try it!
If the above content is wrong, welcome to correct. Comments are welcome!Copy the code