1. Data type classification
2. Basic data types
3. Integer data type
A. Basic Concepts
Int x=0;
Allocate 4 bytes of memory, one byte to 8 bits, value range 2 31 to 2 31
bytex=-12;
Allocate one byte, machine code
shortx=12;
Allocate 2 bytes, emphasizing type, using method (short) 12;
The long type is denoted by the suffix l
Long width=12l;
Allocate 8 bytes to 64 bits
B. Data overflow
public class Demo1 {
public static void Main (string[] args) {
int max=integer.max_value;
System.out.println ("Shaping Max:" +max);
System.out.println ("max+1:" + (max+1));
System.out.println ("max+2:" + (max+2));
}
}
Results:
Plastic max:2147483647
The max+1:-2147483648//value becomes the smallest
max+2:-2147483647//value becomes sub-smallest
Workaround:
int max=integer.max_value;
System.out.println ("Shaping Max:" +max);
System.out.println ("max+1:" + (max+1));
System.out.println ("max+2:" + (max+2l));
System.out.println ("max+2:" + ((long) max+2));
If this is a Long data type overflow, it cannot be resolved.
4. Character types
Constant: ' 123 ' A '! ' Hello
General use of Char declarations
Code:
Converting between characters and shaping
Char ch1= ' a ';
Char ch2=97;
System.out.println (ch1+ "---" +ch2);
Commonly used escape characters:
Code:
Char chinaword=' good ',japanword='? ';
Char you =' \u4f60 ';
int position= 20320;
System. out. Print (" Kanji:" +chinaword+ " position:"+ (int) Chinaword);
5. Floating-point types
Float type
Must have F or F in the back, usually 8-bit valid data reserved
Allocate 4 bytes
Double type
Suffix d or D after, can be omitted
Allocate 8 bytes
float num=3.0f;
System.out.println ("num*num=" +num*num);
6. Boolean type
Constant: True, False
Variable: bool on=true;
Code:
Boolean flag=true;
SYSTEM.OUT.PRINTLN (flag);
System.out.println (!flag);
7. Default values for data types
Role: Sometimes there are variables in the Java program that are not assigned, which makes sense, and defines the default values to prevent this from happening.
Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21
Java Basic data types