java data type
There are two types of data in java:
Basic data types (value types)
Reference data type
basic data type
There are eight basic data types, divided into:
number:
<pre>整型: byte、short、int、long 默认值:0
浮点型: float、 double 默认值:0.0</pre>
Character type: 16-bit Unicode characters
<pre>char 默认值: 'u0000'
</pre>
Boolean value:
<pre>boolean 默认值: falsue
</pre>
Reference data type
There are five types of reference data:
Array, class, interface Default value: null
Enumeration type (introduced by jdk1.5), annotation type (introduced by jdk1.5)
The number of bytes and the range occupied by the java basic data type NO. data type byte data range
1
long (long integer)
8
-92233728(-2^63) ~ 92233727(2^63 -1)
2
integer (integer)
4
-2147483648 (-2^31) ~ 2147483647 (2^31 - 1)
3
short (short integer)
2
-32768 (-2^15) ~ 32767 (2^15 - 1)
4
byte (bit)
1
-128 (-2^7) ~ 127 (2^7 - 1)
5
character (character)
2
0 ~ 65536 (2^32)
6
floating point number (single precision)
4
-3.4E38(-3.410^38) ~ 3.4E38(3.410^38)
7
double (double precision)
8
-1.7E308(-1.710^308) ~ 1.7E308(1.710^308)
Regarding the boolean type, in the "Java Virtual Machine Specification", the size of the boolean is not clearly stated. Although the boolean data type is defined, its support is very limited. There are no Boolean bytecode instructions in the Java Virtual Machine. The boolean value of the Java language expression operation is replaced by the int data type in the Java virtual machine after compilation. The java data type java is divided into data: basic data type (value type), and the boolean array will be encoded. It is a byte array of the Java virtual machine, and each element boolean element occupies 8 bits". This way we can conclude that the boolean type occupies 4 bytes for personal use and 1 byte in the array.
Automatic conversion rules for data types
When performing mathematical calculations on types with small data ranges and types with large data ranges, they will be automatically converted to types with large data ranges.
If a type with a large data range wants to become a type with a small data range, a cast must be used.
If it is a literal constant for coercion, there are two types: 1. Constant mark (L,l); 2. Use (data type) form coercion;
The integer literal constant defaults to the int type . In java, int occupies several bytes , and the floating-point literal constant defaults to the double type;
For byte type java int occupies several bytes , java has optimized, that is, when directly assigning a constant value to a byte type variable, if the set value is within the byte range, the data type conversion will be performed automatically, from int to byte type .
<pre>文章来源:segmentfault,作者:shenlanzifa。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:sean.li#ucloud.cn(邮箱中#请改为@)进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。</pre>
Background - System Settings - Extended Variables - Mobile Ads - Bottom of Content Body