First, identifiers
second, naming norms
third, the data type
1. Classification by data type
- · Defines specific data types for each type of data, allocating different sizes of memory space in memory
- · The basic data Types in Java have fixed representation ranges and field lengths that are not affected by the specific OS to ensure the portability of Java programs.
2. integer type: Byte, short, int, long
- · Java's shaping constants are int, declaring a long constant, and adding ' l ' or ' l ' if the number does not exceed the int range, or ' l '
3. Float type: float, double
- · The Java floating-point constant defaults to double, declaring a float constant, followed by ' F ' or ' F '
- · There are two types of expressions for floating-point constants:
- Decimal number form: such as 5.12 512.0f. 512 (must have decimal points)
- Scientific notation form: for example 5.12e2 512E2 100E-2
4. character type: char
- · Represents a character in the usual sense, with a fixed occupancy of two bytes
- · Essentially an integer that can be operated on, representing the Unicode number of the character, the character that is not in the 65536 number, a char cannot be represented, and two char is required.
- · Multiple assignment methods:
- char c = ' horse '
- char C = 39532; Decimal constant
- char C = 0x9a6c; 16 Binary constants
- char c = ' \u9a6c '; Unicode characters
Above, the latter four kinds are the same, the essence is the Unicode number 39532 is assigned to the character.
- · is an unsigned number, the signed right shift >> and the unsigned right shift >>> result are the same.
- · To see the binary representation of a char, you can use the integer method, as follows:
char c = ' horse '; System.out.println (Integer.tobinarystring (c));
Output is 1001101001101100
5. Boolean type: Boolean
- · Applies to logical operations, generally used in the process air: if, while, Do-while, for
- · Only values of true and false are allowed, and it is not possible to replace true and false with integers of 0 or not 0, which differs from the C language
Iv. type Conversion
1. Automatic type conversion:
- · Small-capacity types are automatically converted to large data types. The data types are sorted by capacity size:
- · When there are multiple types of data blending operations, the system first automatically converts all data into the type of data with the largest capacity before it is calculated.
- · Byte, short, char do not convert to each other, the three of them in the calculation, first converted to int type.
- · When the value of any base type is concatenated with a string value (+), the value of the base type is automatically converted to the string type.
2. Force type conversions:
- · The inverse process of automatic type conversion converts a large-capacity data type into a small-capacity data type. Using the cast character (()) may result in a decrease in precision or overflow, especially when you are aware of it.
- · In general, strings cannot be converted directly to basic types , but wrapper classes that correspond to basic types can be implemented to convert strings to basic types. Such as:
String a = "n"; int i = Integer.parseint (a);
- · The Boolean type cannot be converted to another data type.
Java Basic syntax