Java data types are divided into basic data types and reference data types,
Today is a summary of the basic data types. In Java, a total of eight basic data types are integer types (byte, short, int, long), floating-point type (float, double), character type (char) and boolean (boolean).
1. integer type
Category : byte , Short , int , Long four types.
Storage requirements: each one byte, two bytes, four bytes, eight bytes.
Range: only need to know byte -2 ^ 7-2 ^ 7-1, i.e., -128 to 127 , Short -2 ^ 15 to 2 ^ 15-1, is about negative 30,000 to 30,000,
int -2 ^ 31 to 2 ^ 31-1, is about negative 2 billion to 2 billion, Long -2 ^ 63-2 ^ 63-1, know better than int more can be.
Default value is: byte ( 0 ), Short ( 0 ), int ( 0 ), Long ( 0L )
Packaging: byte (Byte), Short (Short), int (Integer), Long (Long)
Usage: used to represent integer data.
Integer types without suffix defaults to int.
Normally we would choose int type to use (size range is sufficient for everyday use). Int range than use long data types, byte, and is typically short for a particular situation.
Since the Java program must ensure that all the machines are able to get the same results of the operation, so each data type the range must be fixed.
2. floating point type
Classification: a float (single-precision) and Double (double precision) two.
Storage requirements: are four bytes, eight bytes.
Range: We need to understand that the float effective number of bits for the 6-7 position, and double to 15 bits.
Default value : float ( 0.0f ), Double ( 0.0d )
Packaging: float (Float), Double (Double)
Usage: used to indicate the data with decimal.
If the fractional data with data later if no suffix F (e.g. 1998.09) the default is for the double type.
Normally we choose to use the double type, i.e., a double-precision floating point type (float is twice the numerical precision).
Starting JDK 5.0, you can use hexadecimal representation of floating-point values. P represents a number, and the mantissa in hexadecimal, decimal index, the index is the radix 2. e.g. 0.25 0x1.0p-2.
Because the binary system is not accurate to 1/10, it is not suitable for floating point values involved in the calculation error is banned.
3. Character Types
Category: Here's character type refers to the char type.
Storage requirements: two bytes.
Value range: \ u0000 - \ uFFFF
Default: char type value with Unicode encoding related, it defaults 'u0000' .
Packaging: Character
Uses: char type is used to represent a single character, typically used to represent a character constant.
Note that 'A' represents the coding for the 65 character constants (single quotes), and "A" represents containing A string (double quote) characters.
Unicode encoding unit may represent hexadecimal values.
Because Java in the char type in addition to the UTF-16 encoding to describe a unit of code, we use less, and I'm just a white, yet here I was not too much to understand.
4. Boolean
Category: boolean type is the boolean type.
Storage requirements: a byte / four bytes.
Value range: it has only two values: to true and false ,
Default value: false
Packaging: Boolean
Uses: Boolean logic for determining issue.
Not mutual conversion between integer and Boolean values.
Summary Table:
Java basic data types
Integer type | Floating-point type | Character Types | Boolean | |||||
classification | byte | short | int | long | float | double | char | boolean |
Storage requirements | 1 byte | 2 bytes | 4 bytes | 8 bytes | 4 bytes | 8 bytes | 2 bytes | 1 byte / 4 bytes |
Ranges | -2 ^ 7-2 ^ 7-1 | -2 ^ 15 to 2 ^ 15-1 | -2 ^ 31 to 2 ^ 31-1 | -2 ^ 63 to 2 ^ 63-1 | Effective Number of Bits 6-7 | 15-bit effective number of bits | \ U0000 - \ uffff | true and false |
Default value | 0 | 0 | 0 | 0L | 0.0f | 0.0d | \ U0000 | false |
Wrapper class | Byte | Short | Integer | Long | Float | Double | Character | Boolean |
use | Represent integer data | Decimal represent data | Represent a single character | Problem determination logic |
Since the foundation was still in the learning stage of knowledge, if wrong, please point out!