In the process of program execution, the amount whose value cannot be changed is called a constant, and the amount of its value can be changed is called a variable.
I'll use the following code to introduce identifiers and keywords, variables and constants (///,/* These two symbols represent comments):
Public class test{//Create Class
/**
* Identifier: The so-called identifier is actually a name (class name, variable name, method name, array name, file name and other valid character sequences).
* Keywords: keywords are words (int, boolean, public, static) that have been given a particular meaning in the Java language, and these words cannot be used as identifiers.
* About identifiers and keywords is about this, about Java have what keyword and identifier how to count valid character sequence, please Baidu, here do not introduce too much.
* But here I will briefly describe the following specific keywords and identifiers to understand.
* Static keyword: Statically, is created at the time of program initialization, valid range of the entire application, so-called global, the disadvantage is not to be destroyed, has occupied a piece of memory.
* Final keyword: The final keyword usage is more, if a variable is added to the final keyword, then the variable can only be assigned once in the entire program, so it is called a constant.
* Final keyword can also be modified class, decoration method and so here I give you an article link if writing in-depth understanding final can look at.
* Final keyword Article link (personal recommendation not to see, because too deep): http://www.cnblogs.com/dolphin0520/p/3736238.html
* Myint1 Identifier: MYINT1 is the identifier of the constant, the name is taken by itself, as long as the valid sequence of characters can be.
* Variable: The amount of value that can be changed during the execution of a program is called a variable.
* Defining variables requires telling the compiler the data type of the variable (for example, int) so that the compiler knows how much space it needs to configure and what data it can hold.
* During the process of running the program. The value in the space is changed, and the value stored in the memory space is called the variable value, and the space is given a name to be the variable name.
* The variable can be declared without assignment, or it can be directly assigned to the initial value.
* Constant: The amount of value that cannot be changed during the execution of a program is called a constant.
* Constants are variables that are added to the final keyword and can only be assigned once throughout the program.
*/
static final int myint1 = 1; Declares the global constant myint1, which needs to be assigned, otherwise it will be an error.
static int myint2 = 1; Declares a global variable myint2 and assigns it a value, and the variable is not assigned an error.
Public static void Main (string[] args) {//Main method
//myint1 = 2; Here is the error code so I commented, because Myint1 is a constant and can only be assigned once.
Myint2 = 2; All variable Myint2 are assigned here, at which point the Myint2 is 2.
final int myint3; Declares a local constant myint3.
myint3 = 1; The local constants are assigned here.
int myint4 = 1; Declares a local variable myint4 and assigns a value to it.
}
}
PS: The things here are relatively key, some things want to understand the need to know the deep meaning, so here a lot of things need to learn Java later to further understand,
Learn to use it for the time being, be sure to look at the Baidu to see What keywords and identifiers in Java are valid character sequences, this is very important.
<java Basics > Variables and Constants <4>