Identifiers are the
names that are provided by programmer. These names can be assigned to any
variables, methods, classes, interfaces, etc., java identifiers helps compilers
to identify them. Java identifiers can be of any length up to 255 characters.
Java identifiers can start with a letter or an undersigned character “_” or a
dollar sign “$”. Subsequent characters can be alphabets (both capital and small
letters) and numbers from 0 to 9. Space characters or any other special
character found on keyboard is not allowed. The only other limitation is that
java keywords cannot be used as java identifiers.
Examples of valid
identifiers,
- HelloWorld
- Hello_World
- $HelloWorld
- HelloWorld
- HELLOWORLD
Examples of invalid
identifiers,
- Hello World
- HelloWorld #
- short
- Hello-World
In the above
examples, first have space and space is not allowed in java identifiers. In
second “#” and space is present which again not allowed. The third example is
invalid as “short” is a java keyword. The last example has “-” symbol and it is
also not supported in java identifiers.
The naming
conventions above are imposed on the programmer by the compiler. In addition to
the above naming conventions, there are certain types of rules that are widely
accepted and followed by the programmer community.
It is widely
accepted convention to start a class name with capital letter.
Using naming
conventions in a java program is a good habit as it makes your program easily
readable and understandable to other programmers.
No comments:
Post a Comment