Keywords in 1.JAVA:
Java keywords are case-sensitive Oh! So void is the keyword, but void is not the ~ ~
2.JAVA identifiers:
Identifiers are symbols that are used to name variables, classes, methods, and so on in a Java program.
There are several rules to follow when using identifiers:
1. Identifiers can consist of letters, numbers, underscores (_), dollar symbols ($) , but cannot contain other special characters, such as @,%, space, etc. , and cannot begin with a number . For example: 123name is not legal drop
2. Identifiers cannot be Java keywords and reserved words (Java reserved keywords, which may be used as keywords in later versions of the upgrade), but can contain keywords and reserved words. For example, void may not be used as an identifier, but myvoid can
3. Identifiers are strictly case-sensitive . So nirvana, be sure to distinguish between Chu Imooc and Imooc is two different identifiers Oh!
4. The name of the identifier should best reflect its role, to be known .
Public class helloworld{ publicstaticvoid main (string[] args) { System. out. println ("hello Imooc");} }
3. Variables:
In Java, we describe variables by three elements: variable type, variable name , and variable value .
The punctuation in Java is in English . For example, the end of the sentence semicolon, is a semicolon of English symbols, tens of millions of tables written in Chinese Oh ~ ~
Public class helloworld{ publicstaticvoid main (string[] args) { " mu class net "; System. out . println (hobby); }}
4. data Types in Java:
The Java language is a strongly typed language. The popular point is that the data stored in Java is typed and must be determined at compile time. There are two kinds of data types in Java:
Public classhelloworld{ Public Static voidMain (string[] args) {String name="Adoration Class"; Charsex='male'; intnum= -; DoublePrice=120.5; Boolean IsOK=true; System. out. println (name); System. out. println (Sex); System. out. println (num); System. out. println (price); System. out. println (IsOK); }}
5.rules for using variables in Java:
Variables in Java need to be declared before they are used;
When a variable is used, it can be initialized while declaring the variable;
It is also possible to declare and assign values first;
A variable can only be assigned one value at a time, but may be modified more than once;
The variables defined in the main method must be assigned before they can be output;
Although there is no error in the syntax, but in the actual development, the variable name is not recommended to use Chinese, easy to create security risks, such as the late cross-platform operation garbled and so on;
6.Automatic type conversion in Java:
Automatic type conversions are required to meet specific conditions :
The target type can be compatible with the source type, such as a double type compatible with int, but the char type cannot be compatible with the int type;
The target type is greater than the source type, such as a double type of 8 bytes and an int type of 4 bytes, so a variable of type double can directly hold data of type int, but not in the opposite way;
Public classhelloworld{ Public Static voidMain (string[] args) {Doubleavg1=78.5; intRise=5; Double avg2=avg1+Rise; System. out. println ("average score of exams:"+avg1); System. out. println ("adjusted average score:"+avg2); }}
7.forced-type conversions in Java:
Syntax:(data type) values
Forcing type conversions can cause data loss.
8.Application of Java constants:
The so-called constant, which we can understand as a special variable, whose value is set, is not allowed to change during program Operation .
Syntax:final constant name = value;
Constant names generally use uppercase characters
9. How to use annotations in Java:
When you write a program, you often need to add some comments to describe the role of a piece of code.
In general, for a specification of the program source code, the note should be accounted for more than 1/3 of the source code. Therefore, note is an important part of the program source code, we must pay attention to Oh!
There are three types of annotations in Java: single-line comments, multiline comments, document annotations
We can use the Javadoc command to extract the content from the documentation comments and generate the program's API help documentation.
10.
Java Learning < two >