Each language will be designed to a lot of data, so you will be exposed to different data types, the initial contact data type is also dizzy, in the Java language, finally a little understand, comb, and June mutual encouragement.
Concept of variables
A storage area in memory
variable name + data type
can vary within the same type of range
Why define a variable:
is used to keep constant of the same type, and can be reused
Use variables Note:
The scope of the variable, valid
initialization value
between a pair of {} defines the format of the variable:
data type variable name = initialization value
Eg:int x = 4
Note: Format fixed
Understand: variables are like unknowns in mathematics.
Data type:
integer default type: int
decimal number default type: Double
takes up memory and range
Integer
Occupy storage (bytes)
size range
Byte
1
-128 ~ 127
Short
2
-215 ~ 215-1
int
4
-231 ~ 231-1
Long
8
-263 ~ 263-1
Floating-point
float
4
- 3.403e38~3.403e38
Double
8
-1.798e308~1.798e308
Character type
Char
2 (Unicode encoded)
Boolean type
Boolean
1 (actually 1/8byte)
Parse: Why Byte occupies a byte, the value range is -128~127
first need to understand in binary, the highest bit is the sign bit, 0 means positive, 1 is negative, the other bits are data bits.
Byte is a total of 8 bits, representing 256 numbers (28). The
maximum value is 01111111, and the minimum value of 127
to decimal is 10000000,1 is the sign bit, which indicates negative numbers, and goes to decimal 128. So the minimum value is -128
exactly why is-128? How are binary and decimal converted at the bottom? Will involve the original code, anti-code, complement, and listen to the next chapter analysis.
Summary:
After all, the most important thing in a software system is the data, which is the core of the enterprise. Although some of the underlying things we do not need to be proficient, but only to understand these, later use can be handy, and then!
Article by http://yy.china.com.cn/shnk/xb/szqpz/reorganization reprint
Java Fundamentals-variables and data types