Java syntax--variables
There are two types of variables in Java: 1. Basic data types; 2. Reference types.
1. Basic data types (also called value types: 8 types):
1, byte //1 byte between 127 ~ -128
例:byte a = 127 //OK
Example: byte a = -129 //wrong, exceeded
2, short //2 bytes between 32767 ~ -32768
例:short a = 125 //OK
Example: short a = -32769 //wrong, exceeded
3. int //4 bytes between 2147483647 ~ -2147483648 (billion)
4, long //8 bytes (ten trillion trillion)
例:long a = 9 //OK
Example: long a = 9L //OK, Ll can be added after the long type
5, float //4 bytes signed floating point number (single precision)
Example: float a = 3.14 //wrong, f should be added after the floating-point decimal, it should be float a = 3.14f
例:float a = 40 //OK
6, double //8 bytes signed floating point number (double precision)
例:double a = 1.5d //OK
例:double a = 1 //OK
7. char //2 bytes can hold one character, which can be directly operated with numbers, the maximum is 65535
例:char a = 'A' //OK
Example: char a = 'medium' //OK
Example: char a = 'China' // wrong, beyond
Example: char a = "A" //wrong, use single quote
Example: char a = ' ' //OK, spaces can be
Example: char a = '' //wrong, char type null is not like this
Example: char a = '\0000' //OK, this is a null value of char type
例:char a = 'A' //OK
Example: char x = 'A' int y = 5 a = x + y //The output is 70
8. boolean //1 byte has only two values true and false
*Description: 1: 1 to 4 are integers, 5 to 6 are floats, 7 is char, and 8 is boolean
2: The default type of integer is int --> 90 is 90 of int
3: The default type of floating point is double --> 3.14 is 3.14 of double
The reference type
Description: In general, we declare a variable such as (array, interface, class)
For example: Object o = new Object();
Reference type - actually creates a reference ( Object o ) and an object ( new Object ), there are two spaces in the Java memory model, heap and stack
Put the reference into the stack, put the object into the heap, the value of the reference is the address of the object in the heap, the value of the object is the real data, this is the reference type