Comments in java:
Comments in java:- Who does not know the situation? A longer calculation has been carried out, wrote an article, or worked out any sketch – and must do this work now explain to other people. Unfortunately, the invoice, the article, or the Sketch a few days old and you can’t remember every detail every logical step. How can you quickly understand your work?
In important cases, it was therefore ensured that someone else (or oneself) can understand this work later. Marginal notes, footnotes and explanatory diagrams are used for this purpose – additional comments in java that are not part of the actual paper are. Our programs are also getting bigger over time. We, therefore, need the possibility to provide our text with explanatory comments in java. However, since highlighters do badly on the monitor, the language has Java their own way of dealing with comments in java:
Suppose we have written a line of the program and want to work on it later remember what it’s all about. The simplest way would be to use an Insert a remark or a single line comment directly into the program text. In our example this is done as follows:
a = b + c; // a comment begins here
As soon as the Java compiler finds the characters // on a line, it recognizes a single line Comment. Everything that follows after these characters is “none of your business” and Java is ignored by the translator. The comment can therefore be from all possible There are characters that Java provides as input characters. The comment ends with the end of the line in which it started. However, sometimes there may be comments in java on more than one Line should extend. We can of course add a comment character to each line provided something like this:
// Line 1
// Line 2
// line n
This means, however, that we also add further multiline comments do not forget to put the comment characters at the beginning of each line. For this reason, Java provides a second form of comments in java.
We start a multiline comment in java with the characters / * and end him with * /. Text of any length can be placed between these characters (the, Of course, the character string * / must not contain, otherwise the comment in java will already be would be ended at this point), as the following example shows:
/ * Comment …
still comment …
last comment line …
We want to get down to the habit of commenting on our programs make it as sensible as possible and comment frequently. So lose we also use a large number of programs that we in at least one If you have to store an equally large number of files, the overview is not that easy. To give us the right style when commenting on Java source texts To get used to it, we want to stick to the so-called JavaDoc format. JavaDoc is a very helpful additional program that every JDK (Java Development Kit) or JSDK (Java Software Development Kit)  is included free of charge. With the help of JavaDoc, after a successful programming, generate complete documentation for the programs created, which can save you a lot of work in retrospect, provided you follow your program has commented diligently. The functional scope of JavaDoc is of course much larger than what we see in the Within the scope of this section. However, it would make little sense to to go into this point more closely – after all, we want to learn to program!
Apart from that, the program is constantly being developed – interested Readers should therefore read the JavaDoc documentation, which is included in the Online documentation for each JDK is included, is warmly recommended. JavaDoc comments, like general comments in java, always begin with the character string / ** and end with * /. It has become natural, at the beginning everyone Line of the comment to put an additional * to include comments in java visually different from the rest of the source code. A typical JavaDoc comment at the beginning would be, for example, the following:
* This program calculates the lottery numbers for the next
* Week. In doing so, it achieves an accuracy on the cut
* of 99.5%.
* @version 1.0
Let’s take a look at the details in this example:
- The first few lines contain a general description of this Program. It is important to ensure that the information is also provided without the source text at hand should make sense, as JavaDoc from these comments in java separate files is created later – ideally, someone has to who reads the help documents generated by JavaDoc without looking at it on the source code can understand what the program does and how to it calls.
- Next, we see various comment commands that always start with the Characters @ are introduced. Here you can find certain predefined information for this program. The order plays a role the information does not matter. JavaDoc now also recognizes a lot more Comment commands than those listed here, but let’s get down to business first focus on the essentials.