Java Basic Data Type VIII
byte = byte short = shortchar = Characterint = IntegerLong = longfloat = floatDouble = double Boolean = Boolean
This article connects the sequence through a few simple transition relationships
Run an instance to view the results of the output
byteb = ' a '; Shorts = ' a '; Charc = ' a '; inti = 5; LongL = 5l; floatf = 5.5f; DoubleD = 5.5; BooleanBo =true; System.out.println (b); System.out.println (s); System.out.println (c); System.out.println (i); System.out.println (l); System.out.println (f); System.out.println (d); System.out.println (bo);
Output
9797a555.55.5true
You can see that byte and short convert the characters to the AC code output. About char essentially char type is a subset of int
The following is a comparison transformation to understand the size problem
First try to convert to another type using byte
You can see that byte cannot be converted to another type, and you can see that byte is the smallest storage unit
Keep looking at short.
From which you can see that short can receive byte for direct conversion
Int
Long
Float
Double
Boolean (itself True/false only two values, so no other type can be converted)
Char (Char's particularity makes char unable to use other conversions)
One can see the difference
1. In addition to the other types of char can be converted from small to large, the view period source code is inherited, implemented the following ways
? extendsimplements
Have inherited the number class. Which is the digital type.
2.char different from other data types The reason is also here
Public Final class implements java.io.Serializable, comparable<character>
Using the Unicode character set to represent characters, Unicode is a fully internationalized character set that can represent characters in all human languages. Unicode requires a 16-bit width, so the char type in Java is also represented by a-bit. The assignment might be something like this:
char ch1 =N; char CH2 = ' A ';
The ASCII character set occupies the first 127 values of Unicode. Char is attributed to Integer because Java provides arithmetic operations support for Char, such as ch2++; then CH2 becomes Y. When Char is subtraction, it is also converted to an int type, which must be explicitly converted back.
Java Fundamentals-Basic data type conversion cases