Java learning from scratch (data type), java from scratch
I. Java Data Type Division
Ii. Basic Data Types
| No. |
Data Type |
Size/Bit |
Data range that can be expressed |
| 1 |
Long (long integer) |
64 |
-9223372036854775808 ~ 9223372036854775807 |
| 2 |
Int (integer) |
32 |
-2147483648 ~ 2147483647 |
| 3 |
Short (short integer) |
16 |
-32768 ~ 32767 |
| 4 |
Byte (BIT) |
8 |
-128 ~ 127 |
| 5 |
Char (character) |
2 |
0 ~ 255 |
| 6 |
Float (single precision) |
32 |
-3.4E38 (-3.4 '000000 )~ 3.4E38 (3.4 '1038) |
| 7 |
Double (double) |
64 |
-1.7E308 (-1.7 '123 )~ 1.7E308 (1.7 '10308) |
Default Value
| No. |
Data Type |
Default Value |
| 1 |
Byte |
(Byte) 0 |
| 2 |
Short |
(Short) 0 |
| 3 |
Int |
0 |
| 4 |
Long |
0L |
| 5 |
Float |
0.0f |
| 6 |
Double |
0.0d |
| 7 |
Char |
\ U0000 (null ,'') |
| 8 |
Boolean |
False |
2.1 Integer type when the data does not contain decimals or scores, it can be declared as an integer variable such as: 3,-147 integer can be divided into long, int, short and byte4
byte b=8; short s=100; int i=2; long v=1000;
2.2 character type the character type occupies 2 bytes in memory and can be used to save English letters and other characters. The characters must be enclosed by a pair of single quotes ('').
char ch1='a'; char ch2=97; System.out.println("ch1= "+ch1); System.out.println("ch2= "+ch2);Result: substring = a, ch2 = a is also an integer.
Common escape characters:
| No. |
Escape characters |
Description |
No. |
Escape characters |
Description |
| 1 |
\ F |
Form feed |
2 |
\\ |
Backslash |
| 3 |
\ B |
One step backward |
4 |
\' |
Single quotes |
| 5 |
\ R |
Homing |
6 |
\" |
Double quotation marks |
| 7 |
\ T |
Tab |
8 |
\ N |
Line feed |
char ch1='\"'; char ch2='\\'; System.out.println("ch1= "+ch1); System.out.println("ch2= "+ch2); System.out.println("\"Hello World\"");
Result:
Operator ="
Ch2 = \
"Hello World"
2.3 float (double): in mathematics, these numeric values with decimal points are called real numbers. in Java, such data types are called floating point numbers. in java, the default value is double.
double num1=3.14; float num2=7.3F; System.out.println("num1="+num1); System.out.println("num2="+num2);2.4 boolean (boolean) type variables, only true and false. That is to say, when a variable is defined as a boolean type, its value can only be true or false. In addition, no other value can be assigned to this variable.
boolean flag = true; System.out.println("flag ="+flag);
Result: flag = true;