Keyword & identifier
The concept and features keyword
The concept: Java is pre-defined keywords for the Java compiler has a special meaning, they are used to represent a data type, or shows the structure of a program like keyword can not be used as variable names, method names, class names, package name and parameters.
feature:
- Completely lowercase
- In the enhanced version Notepad (e.g., Notepad ++) have special color
The concept of the rule identifier
- What is the identifier?
Anything that can be named by the places themselves are called identifiers.
Example: project name, package names, class names, method names
2. naming convention
① not use java keywords and reserved words, but can contain keywords and reserved words.
② can use 26 the capitalization, 0-9, $, and _.
③ numbers may be used, but not in the first place.
④ length theory there is no limit, but named best reflect its role, follow the "hump form", see life EENOW
⑤ package name all lower case, all the big names like Camel
⑥ variable names, method names first letter lowercase, if the name consists of multiple words, the first letter of each word should be capitalized
⑦ constant ( especially the final modification of the constants ) name in all caps, if it is a single letter, capital needs, if it is more than one word, need to be separated with an underscore. And both uppercase
Example: Write a program example of ajax,
Project name: ajaxtest package name: com.liu.ajax class name: AjaxDemo
Constants & Variables
Constant concept: During the program run. A fixed amount unchanged.
Constant Category:
1. A character constant: those who caused the single quotes to a single character , to do a character constant. For example:, 'b', 9 ' ,' medium
2. String constants: Any double quotes portion , called the string constants. For example: "ABC", "the Hello", "123"
3. integer constants: the direct digital write, without a decimal point . For example: 100,200,0, -250
4. Float constant: to write directly on the numbers, decimals. For example: 2.5, -3.14,0.0
5. Boolean constant: There are only two values true | false
Basic data types:
Type the number of bytes of binary digits
byte (byte) 18
short (short integer) char (char) 216
int (integer) a float (single-precision floating-point) 432
Long (long integer) Double (double precision floating point) 864
- The default type in Java: integer type is int, float type is double
- The number of bytes of data does not necessarily correlate with the range of, for example, a wider range than the data float long, but float is 4 bytes, 1ong 8 bytes.
- Float may only be an approximation, not an exact value.
- Among the default floating-point type is double. If you must use a float, you need to add a suffix F.
- String is not a basic type, but reference types
- If is an integer, the default type int, if we must use the long type, you need to add a suffix L. We recommend the use of capital letters suffix.
Variable: the program is running, the amount of content can be changed.
Create a variable and use format:
Data type variable name; // create a variable
Data variable name = value; // assign the data value on the right, to the left of the variable assignment
One-step format:
Data type Data variable name = value; // create a variable at the same time, immediately placed in the specified data value