The above figure shows the classification of the data type, plus the Boolean type (Bealoon) is divided into four classes of eight data types, which constitute the basic Java data type, the connection between these data is also like the arrows in the diagram, there is a mechanism to automatically promote data types between data, You need to keep an eye on Java programming.
Let's look at a simple set of code examples:
byteA = 127; ShortB = 45; CharE = ' a '; floatf = 21.23f; Doubleg = 0.456; String Str= "Xuesheng"; String x= str+e+A; String Z= e+a+str; /*for the first expression xuesheng+ ' a ' +127, the first "Xuesheng" + ' A ' operation, will be ' a ' into a string, will be stitched into a string xueshenga, followed by the "Xueshenga" + 127 operation, which is also A string join operation, the result is xueshenga127. For the second expression, the ' a ' + 127 addition operation, where ' a ' is automatically promoted to the int type, to a corresponding ASCII value: 97, from 97 + 127 will get 224, then the 224 + "Xuesheng", 224 will automatically convert to a string, will become two strings Connection operation, resulting in 224xuesheng. */System.out.println (The result of "xuesheng+ ' a ' +127" is: "+x+" \ n "); System.out.println ("The result of ' a ' +127+xuesheng is:" +z+ "\ n"); //The data type is automatically promoted to int when the byte type and the short type have char operations//Conversion of char data into numbers based on the position of the characters in the ASCII code table intin = a + E;//arithmetic of byte type and character type automatically promoted to int typeSystem.out.println ("In" Value: "+in+" \ n "); intIn1 = a + b;//byte-to-short operation automatically promoted to intSystem.out.println ("in1" value is: "+in1+" \ n "); byteby = a + = 1; //data types are not automatically promoted when operating with the + = operator//The reason is that because + = is an operator in the Java language, the Java compiler will treat it specially, so it can compile correctlySystem.out.println ("By" value is: "+by+" \ n "); Doublem = f+G; //The result of the operation between float type and double type is double typeSystem.out.println (the value of "M:" +m);
The following table lists most of the data types, in fact, the data type is not limited to the four class eight, there are many, we understand the function functions, including a lot of methods can be seen as a kind of data, and then can operate on it, learning is still too little
Byte (byte type) |
0-255 |
Boolean (Boolean/logical type) |
True or False |
Integer (integral type) |
-32,768 ~ 32767 |
Long (length shaping) |
-2,147,483,648 ~ 2,147,483,647 |
Single (one-precision floating-point type) |
Negative range: -3.402823E38 ~ -1.401298E-45 Positive Range: 1.401298E-45 ~ 3.402823E38 |
Double (dual-precision floating-point type) |
Negative range: -1.797,693,134,862,32e308 ~-4.940,656,458,412,47e-324 positive range: 4.940,656,458,412,47e-324 ~ 1.797,693,134,862,32e308 |
Currency (variable ratio shaping/currency type) |
-922,337,203,685,477.5808~922,337,203,685,477.5807 |
Decimals (decimal type) |
When there is no decimal point: +/-79,228,162,514,264,337,593,543,950,335 has a decimal point: +/-7.922,816,251,426,433,759,354,395,033,5 the smallest non-0 value: +/- 0.000,000,000,000,000,000,000,000,000,1 |
Date (time date type) |
100 year January 1 ~9999 December 31 |
Object (Type) |
Any Object reference |
String (variable length) |
Length from 0 to about 2 billion |
String (fixed length) |
Length from 1 to about 65,400 |
Variant (number) |
Any numeric value, up to a range of Double |
Variant (character) |
With string length, variable length string has the same range |
Revisit basic data types and automatically raise data type issues