Monday, June 11, 2018

Technical Tip #20 - Technical Tip of the day....


T20: Knowledge Tip Of The Day....
Java Identifiers
identifiers are used for identification purpose. In Java an identifier can be a class name, method name, variable name or a label.
example:
public class Test
{
public static void main(String[] args)
{
int n = 20;
}
}
In the above java code, we have 5 identifiers namely :
- Test : class name.
- main : method name.
- String : predefined class name.
- args : variable name.
- a : variable name.
Reserved Words
Any programming language reserves some words to represent functionalities defined by that language. These words are called reserved words.They can be briefly categories into two parts : keywords(50) and literals(3).
Rules for defining Java Identifiers
These rules must be followed, otherwise we get compile-time error.
* The only allowed characters for identifiers are all alphanumeric characters([A-Z],[a-z],[0-9]), ‘$‘(dollar sign) and ‘_‘ (underscore).For example “geek@” is not a valid java identifier as it contain ‘@’ – special character.
* Identifiers should not start with digits([0-9]). For example “123geeks” is a not a valid java identifier.
* Java identifiers are case-sensitive.
* There is no limit on the length of the identifier but it is advisable to use an optimum length of 4 – 15 letters only.
* Reserved Words can’t be used as an identifier. For example “int while = 20;” is an invalid statement as while is a reserved word. There are 53 reserved words in Java.








No comments:

Post a Comment