Java Reference
In-Depth Information
The following line is a single-line comment. It has a valid package declaration as the comment's text. It will be
treated as a comment, not as a package declaration.
// package com.jdojo.intro;
The second type of comment is called a multi-line comment. A multi-line comment may span multiple lines.
It starts with a forward slash immediately followed by an asterisk ( /* ) and ends with an asterisk immediately followed
by a forward slash ( */ ). An example of a multi-line comment in a Java source code is as follows:
/*
This is a multi-line comment.
It can span more than one line.
*/
The above comment can also be written using two single-line comments, as follows:
// This is a multi-line comment.
// It can span more than one line
The style of comment that you use in the source code is your personal choice. A multi-line comment may be
inserted in the middle of Java code as shown below. The compiler ignores all text starting from /* to */ .
package /* A correct comment */ com.jdojo.intro;
The third type of comment is called documentation (or Javadoc) comment, which is also a multi-line comment.
It is used to generate documentation for Java programs. This kind of comment begins with a forward slash that is
immediately followed by two asterisks ( /** ) and ends with an asterisk that is immediately followed by a forward slash
( */ ). The following is a simple example of a documentation comment:
/**
This is a documentation comment. javadoc generates documentation from such comments.
*/
Note
Writing documentation comment is a big topic. it is covered in appendix B in detail.
The simplest class declaration in a Java program may look like
class Welcome { }
This time, I have placed the whole class declaration in one line. You can place the keyword class , the name of
the class Welcome , and the two braces in any position you want, except that you must include at least one whitespace
(space, newline, tab, etc.) between the keyword class and class name Welcome . Java allows you to write source code in
a freeform text format. All of the following three class declarations are the same:
Class Declaration #1
class
Welcome { }
 
 
Search WWH ::




Custom Search