Identifier in Java
In programming languages, identifiers are some keywords used for any specific purpose called identifier. For example when a programmer declares some variables or functions/methods then identifier useful for these situations. The Java compiler detects illegal identifier and reports syntax errors. In other words, the identifier is a name used to identify any block of code or variables.
Example
int number1;
float AvgMarks;
void sum();
In this example keyword number1, AvgMarks, sum are identifiers. number1 is an integer type variable identifier. AvgMarks is a float type variable identifier and the sum is a function/method identifier that has a void return type.
- Java is case sensitive programming language.
- In java variable zoetropefilm, zoetropefilm, zoetropefilm and zoetropefilm are all different identifier.
- The identifier is used for naming variables, classes, methods, constants, and packages
- A descriptive identifier makes source code or programs easy to read and understand.
Identifiers rules
- The identifier may include letters, numbers, and underscores (_) and the dollar sign ($).
- The first character of an identifier must be a letter, underscore (_) or a dollar sign ($) like apple, _apple, $apple.
- The identifier can not start with any number digit like 4student, or 12student.
- Blank spaces are not allowed in identifiers like num 1, num 2, num 3, etc.
- Both upper and lower cases are allowed in identifier like a number, Number or numBer but all have a different
- The constants are conventionally written in upper case.
- Special symbols cannot be used in identifiers except underscore (_) and the dollar sign ($) like #num, &marks, and %zoetropefilm, etc.
- Resaved words cannot be used as identifiers like “System”, “void”, “true” or “null”.
- Identifiers can be up to 31 characters long for many compilers. If an identifier consists of more than 31 characters, only the first 31 characters will be used. The remaining characters will be ignored.
Identifiers can be declared only for one data type and one time only.
Example
int marks;
float marks;
string marks;
char marks;
This is wrong for identifiers rules