Annotations
What are annotations?
Comments are explanatory text for a certain piece of code, a certain method, or a certain class when we write code to facilitate everyone's reading of the code. The commented content will not be compiled or executed.
Java comments are divided into three types: single-line comments, multi-line comments, and document comments.
Single-line comments and multi-line comments
Single-line comments comment on a line of text or code in the program. In Java, use "//" for single-line comments. Multi-line comments can comment multiple lines of code at one time. In Java, "/*" is used to indicate the beginning of a multi-line comment, and "*/" is used to indicate the end of a multi-line comment.
Example:
public class CommentTest{ public static void main(String[] args){ //这是单行注释 /* 多行注释第一行 第二行 */ //System.out.PRintln("被注释的代码不会编译和运行"); System.out.println("未被注释的代码"); } }
Eclipse comment shortcut key: Ctrl+/ single-line comment and uncomment; Ctrl+Shift+/ to add /* */ comments; Ctrl+Shift+ to eliminate /* */ comments
Documentation comments
Comments added using documentation comments can be used to generate API documentation through the documentation generation tool javadoc, which is only processed by the javadoc tool Comments in front of classes, interfaces, methods, Fields, constructors and internal classes modified with public and protected in the document source text.
Documentation comments end with "/**"Start with "*/". The middle part is the documentation comment, which will be generated into the API documentation.
Example:
/** * 这是一个文档注释的测试类 * @author ping * */public class Test { /** 这是一个Filed */ public int i; /** * 这是程序的main方法 * @param args */ public static void main(String[] args) { } }
Regarding generating Java API documentation, you can refer to the following two articles:
Use the javadoc command to generate api help documentation
How to generate javadoc with eclipse
Identifiers and keywords
Separators
In Java Delimiters include semicolons (;), braces ({}), square brackets ([]), parentheses (()), spaces, and dots (.). All symbols are English symbols. This is when writing Pay special attention when coding.
Semicolon: In Java, a newline cannot represent the end of a statement. Only a semicolon represents the end of a statement. Therefore, it is theoretically possible to write multiple statements in one line, but this is not recommended as it will affect the readability of the code. Makes the code look cluttered.
Braces: A pair of curly braces represents a statement block and needs to appear in pairs.
Square brackets: used for arrays, used when defining arrays and accessing array elements. They also need to be used in pairs.
Parentheses: Used to include formal parameters when defining methods, calling methods and constructors, requiring parentheses.
Space: Used to separate multiple parts of a statement.
Dots: Used as members of objects and classes.
Identifiers
Identifiers are symbols used to name classes, methods, and variables in a program. Java identifiers have the following characteristics:
Case-sensitive.
Must start with a character, underscore, and dollar sign, and can be followed by four elements: characters, underscore, dollar sign, and numbers. Characters are not limited to English characters, but can be characters from various countries such as Chinese characters.
Cannot contain special symbols other than underscores and spaces.
cannot be a keyword in Java.
public class Test{ //Test is an identifier
public static void main(String[] args){ //main args is also an identifierint a = 1;
int A = 1; //a and A are Two different identifiers int $i = 2; //The identifier is correct int 123 = 123; //The identifier is wrong int i123 = 123; //The identifier is correct int i_1 = 1; //The identifier is correct int i.1 = 1; //Error int class = 2; //class is a keyword, error}
}
Keywords
Java contains a total of 48 keywords and two reserved words (goto/const).
The above is [Java Introduction Notes] Java Language Basics (1): Comments, identifiers and keywords. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!