In: Computer Science
Describe the rules governing identifiers. Can identifiers be re-used in the same Java class file? Provide three examples of different kinds of invalid identifiers.
Java
Java identifiers are in java programming language are used for the indenfication propose.in java programming language the identifiers are contains the a class name,method name,variable name,or label.we will discuss the rules governing identifiers this mainly maid for valid java identifier.there need tobe followed else it getting the compile time error.
Identifiers can have only alphanumeric characters like a-z,A-Z and 0-9 digits and underscore that is _.for example "welcome@" is not valid java identifier as it conatin the @ sign.
The first character of an identifier is conatin the only alphabet that is a-z and A-Z.or underscore _.for example "123example" it is not valid java identifier.
Identifiers are also contain sensitive.that is welcome and Welcome are two different identifiers.
There is no limit for length of identifiers but in case ot contain the optimal length that 4 to 15 letters.
Reverse word can not used as identifier.example int while=10;it is invalid statement because it contain while is reverse word.
Keyword are not allowed to ne used as identifiers.
No special characters such as semicolon ,space and comma are permitted to be used or as identifier.
Can identifiers be re-used in the same Java class file the answer is no because in program the it conatin uniqueness.it can used for identification process identifies conatin method name,class name or a variable name.in the java program conatin unique identifier .also you can not create as same class name.also it applicable for method and variable.for example
Public class addition
{
Public static void main(String args[ ])
{
int num1=10;// this is valid identifier.
int num1=30//In this line num1 variable is used allready used you cannot reuse it will provide generate an error as a duplicate variable.
}
}
Three example of invalid identifiers
1.add number- this is invalid identifier because you can not keep space if you going to run the program with this identifier this will generate error.
2.123add -this is invalid identifier you can not use identifier which begin with the digit.
3. A+B this is invalid identifier because + sign is not an alphanumeric character.