Que: What is Identifier in JAVA?
Ans: Any name in a java program is called identifier. It can be a class name, variable name, method name, label name.
example:-
Q. How many identifiers are in the following program?
Ans is
(D)
Description:-
Test, String & System are class names means 3.
main() & println()are methods means 2.
args is a reference variable of String[] means 1
Hence there are total 3+2+1= 6 identifiers..Rules For Defining Java Identifier
Rules For Defining Java Identifier
Rule 1.
a to z
A to Z
0 to 9
$ and _
a to z
A to Z
0 to 9
$ and _
example:-
total_number (valid)
total# (invalid)
Rule 2.
The identifier should not begin with a digit.
example:-
123total (invalid)
total123 (valid)
Rule 3.
Java identifiers are case sensitive of course java language itself is created as case sensitive language.
example:-
int number=10; (valid)
int Number=20 (valid)
int NUMBER=30; (valid)
Above three are different values.
Rule 4.
We can't use reserver words as identifiers.if we are trying to do then we will get compile time error.
int x=10; (valid)
int if=20; (invalid)
int else=30; (invalid)
Rule 5.
Rule 5.
All predefined java class name and interface name we can take as Identifiers.
example 1:-
example 2:-
Rule 6.
There is no length for java identifiers but it is not recommended to take lengthy identifiers.
example:-
int aaacscsvsvsscvascvncmgacvshgavg=10; (valid)
Now you have to decide which one is a valid identifier in java.
Problem Practice:-
total_number
total#
123total
total123
Ca$h
_$_$_$_$
all@hands
JavaByChetan
Integer
Int
int
Now scroll down To check your answers:-
total_number (valid)
total# (invalid)
123total (invalid)
total123 (valid)
Ca$h (valid)
_$_$_$_$ (valid)
all@hands (invalid)
JavaByChetan (valid)
Integer (valid)
Int (valid)
int (invalid)
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home