1. Introduction to Java data types
Reference principle:
The preferred description number must be int (integer) and double (decimal);
For data transmission or text encoding conversion, byte type (binary processing operation) is used;
The most convenient operation for processing Chinese is to use char (optional)
long can be used to describe the memory or file size and the primary key column (automatic growth) of the table.
2. Integer data
1.int type
//Int variable = the value of int; int max = Integer.MAX_VALUE;//Gets the maximum value of int int min = Integer.MIN_VALUE;//Gets the minimum value of int System.out.println(max);//2147483647 System.out.println(min);//-2147483648 // Int type variable + int type constant = int type calculation result System.out.println(max + 1); // -2147483648 max. + 1 System.out.println(min- 1);// 2147483647 min - 1
If the number exceeds its maximum storage range during processing, it is called data overflow in Java. If you want to solve this overflow, you can continue to expand the scope of use,
2.long type
Example: solving data overflow
Estimate the data range during operation. If the range is found to be insufficient
//Receive with long //long long variable = the value of long; long max = Integer.MAX_VALUE;//Gets the maximum value of int long min = Integer.MIN_VALUE;//Gets the minimum value of int System.out.println(max);//2147483647 System.out.println(min);//-2147483648 // Long type variable + int type constant = long type calculation result System.out.println(max + 1); // 2147483648 max. + 1 // Long variable - int constant = long calculation result System.out.println(min- 1);// -2147483649 min - 1
- In addition to variables that can be defined as long, they can also be processed directly on constants. The default integers are int types, so you can append the letter "L" to them or directly use "(long)" conversion.
int max = Integer.MAX_VALUE;//Gets the maximum value of int int min = Integer.MIN_VALUE;//Gets the minimum value of int System.out.println(max);//2147483647 System.out.println(min);//-2147483648 // int type variable + long type constant = long type calculation result System.out.println(max + 1L); // 2147483648 max. + 1 // int type variable - long type constant = long type calculation result System.out.println((long)(min- 1));// -2147483649 min - 1
Data types with a small range can be directly converted to data types with large data. To convert a large data type to a data type with a small range, a strong processing mode must be adopted. Colleagues also need to consider the possible data overflow
3. Floating point data
When all data types are automatically transformed, they are automatically transformed from small types to large types.
float x = (float) 10.2; float y = 10.1F; System.out.println(x * y);//float type = 103.020004, there are bug s in all java versions.
4. Character data
In any programming language, characters can be associated with int Convert each other, that is, at this time, the contents described in the characters can be converted through int Get the system code corresponding to its content.
example:
char c = 'A';//A character variable int num = c; //The encoding of characters can be obtained System.out.println(num);//
It can be seen from the code obtained by the above program that several ranges need to be noted as follows:
""Upper case letter range": A(65)~Z(90); "Lowercase range: a(97)~Z(122); "Number range: 0 (48)~9(57)
Through the coding range, it can be found that there is a difference of 32 digits between upper and lower case letters, in which case lower case letters can be changed into upper case letters.
char c = 'x';//A character variable int num = c ;//The encoding of the characters can be obtained num = num -32 ;//Reduce your content by 32 System.out.println((char)num);//int strong knowledge transformation to char
The char type in java can save Chinese data because java uses unicode, a hexadecimal code. The feature of this code is that it can include any text content, making program development easier.
5. Boolean data
Boolean is the name of a mathematician. The value range of Boolean is only two data: true and false.
6.String string
Define variables for String
string Variable name = "constant"; String str = "Hello world";
Use the "+" sign as the connection processing