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, Java language, finally a little understand, comb a bit, with June mutual encouragement.
- The concept of variables
- Variable name + Data Type
- Can be changed within the same type range
Using variables Note:
- variable scope, one pair {}
- definition The format of the variable:
- data type variable name = initialization value
- eg:int x = 4
- Understanding: Variables are like unknowns in mathematics.
- Data type :
the integer default type is :int
the decimal default type is :Double
Memory consumption and range of values
integral type |
Occupy storage space (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 ( adopted unicode encoding |
  |
Boolean type |
  |
  |
boolean |
1 ( 1/8byte) |
  |
parsing : Why byte takes one byte and the value range is -128~127
first you need to understand that in binary, the highest bit is the sign bit, 0 indicates positive, 1 represents a negative, and the other bits are data bits.
byte Total accounted 8 Bit , indicating the Number ( 2 8 ).
The maximum value is 01111111 , turn into decimal to 127
the minimum value is 10000000 , 1 is the sign bit, which represents a negative number, and turns it into decimal - . So The minimum value is -128 .
why exactly? -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:
In the final, the most important thing in software system is data, data 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!
Java Basics-Variables and data types