Each variable has a name, which is an identifier. Similarly, each class has a name, which is also an identifier - like the name of the method and the name of the package. There are restrictions on how an identifier can look - for example, it cannot start with a number or include spaces.
So, for example, in this program:
public class Test {
public static void main(String[] args) {
int x = 0;
System.out.println(x);
}
}
The following identifiers are used:
TestmainargsxSystemoutprintln
However, only argsand xare the variables declared in the code you provided. outis also a variable, but declared in a type System.
The same identifier can refer to different things in different contexts, even within the same program. For instance:
public void method1() {
String x = "";
System.out.println(x);
}
public void method1() {
int x = 0;
System.out.println(x);
}
Here, the identifier is xused in both methods - but each time it refers only to a variable declared inside the method.
, , .
, , , , ... , , . , ( ) .