in the Java in
A variable of type Int is 4 bytes
A Long variable accounts for 8 bytes
A program is a world, and a variable is the basic unit of the program.
Java Basic data Types
1. integer Type
2. decimal (floating-point) type
3. Boolean type
4. Character Type
Integer type
An integer type can represent an integer, and the commonly used integer types are: Byte,short,int,long
BYTE a byte-128 to 127
Note: 0 has two representations 0000 0000 positive 1000 0000 Negative 0, minus 0 is taken as-128 1111 1111-127
Formula: -2^n-1 ~ 2^n-1-1
Short two bytes-32768 to 32767
Int four bytes-2147483648 to 2147483647
A Long eight bytes
Number of bits 0 in binary decimal 1
1 1 1 0
10 2 2 1
100 4 3 2
1000 8 4 3
10000 16 5 4
100000 32 6 5
1000000 64 7 6
10000000 128 8 7
100000000 256 9 8
1000000000 512 10 9
10000000000 1024 11 10 2^10 = 1024 (10 x 0)
Decimal (floating-point) type
Float (single-precision floating-point number)
Double (dual-precision floating-point number)
Boolean type
Boolean types can represent true or false
Boolean
Character type
The character type can represent a single character, the character type is Char,char is two bytes, and 1 char variables can hold 1 kanji.
More than one character we call a string, represented in Java by a data type such as String, but the string is not the base data type, but the class, which is a composite data type.
Int test1= ' A ' + ' B '; Output: 195
means: the ASCII number corresponding to a is added to the ASCII number corresponding to character b and stored as a number in the INT type variable test1
Char test1= ' A ' + ' B '; Output:? (not found) char test1= '! ' + '! '; Output: B
Indicates that the ASCII code number corresponding to a is added to the ASCII number corresponding to character B, and the ASCII code corresponding to the added number is stored in the Char type variable test1.
Conclusion: In Java , the character when the operation is performed, it is directly ASCII yards or Unicode code corresponding to the number of calculations (plus and minus), and save the variable corresponding to the data type, if the shape is to save the number, if the character type, the number corresponding to the character.
Automatic conversion
Data types can be automatically converted from low-precision to high-precision, but not automatically converted from high-precision to low-precision.
Float a = 3.4; Error
Float a =3.4f; No error, plus F indicates decimal with float type
Note: The decimal in Java is double by default, because it is automatically converted from high precision to low precision so it will be an error.
Forced conversions
int a = (int) 1.2; Write parentheses in front of numbers, type of cast in parentheses
int a = (int) 1.2;
int b = (int) 1.9;
System.out.println ("a=" +a+ "," + "b=" +b); Output:
Note: Forcing type conversions in Java is not rounded, and floating-point type casting to reshape forces the number after the decimal point to be removed.
Int a = 3;
Int b =a+3.4; Error
int a = 3;
Double b = 3.1;
b = a+b;
System.out.println (b); Output: 6.1
Note: When a low-precision number is compared to a high-precision digital phase, the low-precision number goes to high precision.
Java data type vs. binary