Variable
A variable is a space for temporarily storing data. So we have the data in the memory space inside, how to take it?
To illustrate:
We can think of the hotel room as a storage space, the name of the room "101" as the variable name, the room type "Standard room", "business" as the variable type, the guest of the occupancy as a variable value.
If we can quickly through the room variable name to know the number of guests staying in the room ( variable value ). Then we can also quickly find the data stored by the variable name.
Summary: Declaring a variable is a space in memory that is used to store data.
Basic data types
In Java, you can divide data types into two kinds of numeric types and Boolean types:
It is worth pointing out that a string is not a data class, and a string type is a class, that is, a reference type.
Integral type
int shaping
"Long Integer type
"Bype a byte 8bit value range: -128--127
"Short shorter integer type"
Floating point Type
Double-precision floating-point type
"Fload single-precision floating-point type
Boolean type
"Booleam true and False return values are true and false
Character type
"Char character stores a single character
Variable name
Simply put, like a human name, can be called "Zhang San" or "John Doe", in the programming we have to take some meaningful variable names.
Variable naming rules
1. Variables must begin with a letter, an underscore "-" or a "$" symbol
2. Variables can include numbers, but cannot start with a number
3. In addition to the "-" or "$" symbols, variable names cannot contain special characters.
4. Keywords that cannot be used in the Java language, such as int, class, public, etc.
Specification: The variable name is short and can clearly indicate the function of the variable, which can be composed of one or more words, usually the first letter in lowercase, followed by the first letter of the word capital.
For example:
Note Frequently Asked Questions:
1. Variables not assigned value first use
2. Use of illegal variable names
3. Variable cannot have duplicate name
java--variables and data types