Data that can be allocated directly in the stack is the base data type. Reference data type: the reference to the data is in the stack, but his object is in the heap.
Basic data type, small size turn large, big turn to be smaller will lose precision
First Class: Logical Type Boolean
Type II: Text Char
Class III: Integer type (byte, short, int, Long) class fourth: float (float, double)
Integer has a byte short int long char, denoted by 8, 16, 32, 64, 16bits, respectively. In some places, char may not be included in an integer category, but essentially a char type is a subset of Int.
A byte short int long is signed, denoted by the 2 complement (s-complement). Char, in 16-bit notation, is unsigned and represents the UTF-16 encoding set.
A byte is represented by a 1-byte 8-bit, which is the smallest integer type. Mainly used to save memory space key. The byte type is particularly useful when manipulating data flows from networks, files, or other IO. The values range from: [-128, 127].
Short
with
-
bit, the value range is:
[-2^15, 2^15-1]
.
Short
It's probably the least common type.
Short
when the type participates in the operation, the same is promoted to
int
or a higher type.
Int bits, [-2^31, 2^31-1].
a signed binary complement represents an integer.
Long
+ bits
,
[-2^63, 2^63-1,
The default value is
0L].
When you need to calculate a very large number, if
int
insufficient to accommodate size, can be used
Long
type. If
Long
is not enough, you can use
BigInteger
class.
Char
[ 0, 65535], [0, 2^16-1],
from
' \u0000 '
to the
' \uffff '
. Unsigned, the default value is
' \u0000 '
.
Java
Use
Unicode
Character sets represent characters,
Unicode
is the complete national
a character set that can represent all the characters in a human language.
Unicode
need to
-
bit width, so
Java
in the
Char
type is also used
- bit
representation. When
Char
when the subtraction operation is performed, it is also converted to
int
type, you must explicitly convert it back.
float
Use
+ bit
indicates that the corresponding single-precision floating-point number, compared to the operating speed
Double
faster, takes up less memory, but becomes imprecise when the value is very large or very small. Can be used when the accuracy requirement is not high
float
type
double64
to indicate that a floating pip face is assigned to a variable if it is not displayed after the literal value and
F
or
F
, the default is
Double
type.
Java.lang.Math
are used in the functions in
Double
type.
if
Double
and the
float
cannot achieve the desired accuracy, you can use
BigDecimal
class.
Boolean
type has only two values
true
and the
false
, the default is
false
.
Boolean
and whether it is
0
There is no relationship, but you can convert according to the logic you want.
Automatic Conversion
a larger type, such as
int
) to save a smaller type, such as
byte
), memory is always sufficient and does not require a cast.
Forcing type conversions
If you want to turn the big into small, or in
Short
with the
Char
must be cast, also known as a narrowing conversion (
Narrowing Conversion
)
,
because the numeric value must be explicitly smaller to accommodate the target type.
JAVA second day basic data type