Note:
Single line comment ://
Multi-line comment :/**/
Document note :/***/
The document notes can be used to Export documents with the Export. The commonly used Javadox labels are as follows:
@ Author: specifies the author of the Java program.
@ Version: specifies the source file version.
@ Deprecated: code not recommended
@ Param: parameter description of the method
@ Return: specifies the return value of a method.
@ See: "see", used to specify the content for poor reference
@ Throws: the thrown exception, with @ exception consent
Example:
1. Class (interface) comments
For example:
/**
* Class description
* @ Author Administrator
* @ Time 2012-11-
*
*/
Public classTest extends Button {
......
}
2. Constructor comments
For example:
Public class Test extends Button {
/**
* Constructor description
* @ Param name
* Text displayed on the button
*/
Public Test (String name ){
......
}
}
3. Method annotation
For example
Public class Test extends Button {
/**
* Add a color for the button
* @ Param color
Button color
* @ Return
* @ Exception (add if the method has an exception)
* @ Author Administrator
* @ Time2012-11-20 15:02:29
*/
Public voidaddColor (String color ){
......
}
}
4. Global variable comments
For example:
Public final class String
Implements java. io. Serializable, Comparable <String>, CharSequence
{
/** The value is used for characterstorage .*/
Private final char value [];
/** The offset is the first index of thestorage that is used .*/
Private final int offset;
/** The count is the number of charactersin the String .*/
Private final int count;
/** Cache the hash code for the string */
Private int hash; // Default to 0
......
}
5. Field/attribute comments
For example:
Public class EmailBody implements Serializable {
Private String id;
Private String senderName; // sender's name
Private String title; // cannot exceed 120 Chinese characters
Private String content; // mail body
Private String attach; // attachment, if any
Private String totalCount; // total number of senders
Private String successCount; // number of successfully sent students
Private Integer isDelete; // 0. Do not delete 1. Delete
Private Date createTime; // currently, timing is not supported. Therefore, it is sent immediately after creation.
PrivateSet <EmailList> EmailList;
......
}
In fact, the specifications are self-defined. As long as everyone in the team complies with the rules in a unified manner, the results will be good. I hope it will be helpful to friends who do not add comments at ordinary times.
Identifier:
Semicolon (;): each java statement must end with a semicolon
Curly braces ({}): defines a code block, which is logically a whole.
Square brackets ([]): used to access array elements immediately after the array variable name. The square brackets are the array indexes to be accessed.
Parentheses (): 1. When defining a method, parentheses declare the form parameters. When calling a method, parentheses pass in the real parameters.
2. Enclose a part of the expression as a whole and perform priority operations.
3. Forced type conversion operator
Space (): spaces can appear anywhere in java. Note that you cannot separate variable names with spaces.
Dot (.): used between a class/object and its members (member variables, methods, and internal classes) to call a specified member of a class/instance.
To sum up:
[1] Java identifiers can only contain numbers, letters, underscores (_), dollar signs ($), and Unicode character sets.
[2] Java identifiers must start with letters, underscores (_), dollar signs ($), and Unicode character sets.
[3] Java identifiers cannot be Java keywords, reserved words (const, goto), and word volumes (true, false, null)
[4] Java identifiers are case sensitive
Examples of valid identifiers:
_ Haha, haha, _ name, name, $ dollor, $123, and Ha 1
Example of invalid identifiers:
1 name, 1 Hello, H % llo
-- [$] Example of an identifier --
Import java. lang .*;
Public class IdentityTester {
Public static void main (String args []) {
// Because Chinese characters are Unicode character sets, they can be used as identifiers
String _ haha = "Hello ";
String haha = "You are very good ";
Int _ name = 0;
Int name = 0;
Float $ dollor = 0.0f;
String ha 1 ha = "Hello One Hello ";
String 1 Hello = "";
String H % llo = "";
}
}
The code above contains an invalid identifier: 1 Hello, H % llo. Therefore, an error: Java <wbr> identifier will appear in the running result of the program.
The compiler cannot recognize it.
When the program is changed:
Import java. lang .*;
Public class IdentityTester {
Public static void main (String args []) {
String _ haha = "Hello ";
String haha = "You are very good ";
Int _ name = 0;
Int name = 0;
Float $ dollor = 0.0f;
String ha 1 ha = "Hello One Hello ";
// String 1 Hello = "";
// String H % llo = "";
System. out. println (_ haha );
System. out. println (haha );
System. out. println (_ name );
System. out. println (name );
System. out. println ($ dollor );
System. out. println (HA 1 );
}
}
Running result: Java <wbr> identifier
Improve multi-row output:
Import java. lang .*;
Public class IdentityTester {
Public static void main (String args []) {
String _ haha = "Hello ";
String haha = "You are very good ";
Int _ name = 0;
Int name = 0;
Float $ dollor = 0.0f;
String ha 1 ha = "Hello One Hello ";
// String 1 Hello = "";
// String H % llo = "";
System. out. print (_ haha + _ name + name );
// System. out. println (haha );
// System. out. println (_ name );
// System. out. println (name );
// System. out. println ($ dollor );
// System. out. println (HA 1 );
}
}