A Java identifieris any name in a Java program that are used to define a package, class, interface, method, or a variable. But technically, these identifiers must be composed of Unicode characters, numbers, currency symbols and connecting characters.
The following are the
rules in declaring a Legal Java Identifier.
- Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). It can not start with a number.
- After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers.
- There is no limit to the number of characters an identifier can contain.
- Java reserved words are not to be used.Check this list of Java Keywords to not be used in declaring identifiers.
- Identifiers in Java are case-sensitive.Variable SUM and sum are different when being read by the Java Compiler.
Examples of legal Identifier
int weight;
int $money;
int _temp;
String _$;
String _temp_container;
String a_very_long_name_for_an_identifier;
String label01;
Examples of illegal identifier;
int .hh;
double money.sum;
int :identifier;
int -c;
int f#;
int 01label;
String volatile;
Walang komento:
Mag-post ng isang Komento