Recognize variables
There are two types of variables: primitive data types and references.
declaring variables
Java focuses on variables. It will not let you put the floating-point type variable into an integer-type variable unless you first confirm with the compiler that the number can lose precision.
In order for type safety to work, you must declare the types of all variables.
There are two types of variables: primitive master data type and object reference.
The primitive primary data type is used to hold the values of the base type, including integers, booleans, and floating-point numbers, while object references hold references to objects.
Rules for declaring variables:
Variables must have type
Variables must have type
Variables must has a name
Variable must have a name
A variable is like a cup, is a container, carries certain things, he has size and type.
Primitive main data types like coffee cups, they have different sizes, and each university has a noun, such as a small cup, a big cup, a medium cup, etc.
Each primitive main data type variable has a fixed number of digits (cup size), and the primitive master data type that holds the value has the following 6 sizes
Byte:8, Short:16, int:32, long:64, float:32, double:64
Primitive assignment of the primary data type
Make sure that the variable can save the saved value.
You can't put a big value in a small cup.
For example, you can't load an int size into a byte container.
You can assign values to variables in several ways:
Directly after the equals sign
Assigning values to other variables
The combination of the above two methods
Avoid keywords (keyword)
Naming rules for Java:
The name must begin with a letter, underscore, or $ symbol and cannot begin with a number
In addition to the first character, a number can be used behind it. As long as it's not for the first character.
As long as the two rules above are met, you can name them arbitrarily, but avoid Java reserved words.
List of reserved words
Object reference
We already know how to declare a primitive main data type variable and assign it to her, but what about a variable of a non-primitive master data type? That
"Head First Java reading notes" (iii) primitive master data types and references