2.4 Identifiers and Keyword in Java
2.4 Identifiers and Keyword in Java
Identifiers in Java are symbolic names used for identification. They can be a class name,
variable name, method name, package name, constant name, and more. However, In Java,
There are some reserved words that can not be used as an identifier.
For every identifier there are some conventions that should be used before declaring them.
Let's understand it with a simple Java program:
o A valid identifier must have characters [A-Z] or [a-z] or numbers [0-9], and
underscore(_) or a dollar sign ($). for example, @javatpoint is not a valid identifier
because it contains a special character which is @.
o There should not be any space in an identifier. For example, java tpoint is an invalid
identifier.
o An identifier should not contain a number at the starting. For example, 123javatpoint
is an invalid identifier.
o An identifier should be of length 4-15 letters only. However, there is no limit on its
length. But, it is good to follow the standard conventions.
o We can't use the Java reserved keywords as an identifier such as int, float, double,
char, etc. For example, int double is an invalid identifier in Java.
o An identifier should not be any query language keywords such as SELECT, FROM,
COUNT, DELETE, etc.
1. double marks;
in the above statement, double is a reserved word while marks is a valid identifier.
Although the const and goto are not part of the Java language; But, they are also considered
keywords.
o TestVariable
o testvariable
o a
o i
o Test_Variable
o _testvariable
o $testvariable
o sum_of_array
o TESTVARIABLE
o jtp123
o JavaTpoint
o Javatpoint123
Invalid identifiers: