what are java identifiers
what are java identifiers
Identifier :
A name in java program is called identifier. It can be label name, variable name,method name and class name .
Example:
class ABC
{
public static void main(String[] args)
{
int x=10;
}
}
Principles or Rules to define java identifiers:
Principle 1:
The only permitted characters in java identifiers are:
1) a to z
2) A to z
3) 0 to 9
4)(underscore)
Principle 2: If we are using any other character then we can get compile time error.
Example:
1)
total number------valid
2)Total#------------invalid
Principle 3: java identifiers are not allowed to starts with digit.
Example:
1) ABC123----------valid
2) 123ABC----------invalid
Principle 4: The identifiers are case sensitive up course java language itself treated as case sensitive language.
Example:
class ABC
{
int number=10;
int Number=20:
int NUMBER=20; //we can differentiate with case.
int NuMbEr 30;
}
Principle 5: There is no length limit for java identifiers but it is not advised to take more than 15 lengths.
Principle 6: We cannot use reserved words as identifiers.
Example:
int if=10;----------invalid
Principle 7: All predefined java class names and interface names we use as java identifiers.
Example 1:
class ABC
{
public static void main (String[] args)
{
int String=10;
System.out.println(String);
}
}
Output:
10
Example 2:
class ABC
{
public static void mainString[] args)
{
int Runnable=10;
System.out.println(Runnable);
}
}
Output:
10
Even though it is legal to use class names and interface names as identifiers but it is not a good idea for programming practice.
Which of the following are valid java identifiers?
1) $_ (valid)
2)Ca$h (valid)
3)Java2share (valid)
4)all@hands (invalid)
5)123abc (invalid)
6)Total# (invalid)
7)Int (valid)
8)Integer (valid)
9)int (invalid)
10) tot123
Today's inspirational quotes:
"Don't limit your challenges, just challenge your limits. "
Happy Reading.Happy Learning!!! See you in next post :)
"Don't limit your challenges, just challenge your limits. "
Steps to Subscribe my blog in 15 secs:
1. Enter your mail id in "Subscribe" box.
2. Enter Captcha for verification.
3. A mail will be received with link in your mail id.Just Click on link and then Done .Thank you for subscribing :)
Happy Reading.Happy Learning!!! See you in next post :)
Post a Comment