Showing posts with label Identifier. Show all posts

Which of the following are valid identifiers?

ca$h T
total_number         T
all@hands F
Java2share T
_______ T
$$$$$$$ T
_$_$_$ T
int F
Int T
Integer T
Read more »

Can we use predefined Class/Interface name as Identifier?

class Identifier8
{
public static void main(String alt[])
{
int System=20;
System.out.println(System);
}
}
/*
O/P:- Complitation Error
Explanation :- Once any predefined class/interface name is behaving like a variable
then that identifier can only behave like a variable and cannot be used
as a class/interface name. In line 7 System is behaving like a class name.
*/
Read more »

Can we use predefined Class/Interface name as identifier?

class Identifier7
{
public static void main(String alt[])
{
int String=20;
int Runnable=30;
System.out.println(String);
System.out.println(Runnable);
}
}
/*
O/P:- 20 30
Explanation :- All predefined java class names and inteface names we can use as identifier.
Eventhough it is legal to use predefined class and interface name as identifier
it is not good programming practice.
*/
Read more »

Can we use Reserved literals as identifier?

class Identifier6
{
public static void main(String alt[])
{
int if=25;
System.out.println(if);
}
}
/*
O/P:- Compilation Error
Explanation :- We cannot use reserved words as an identifier.
There are total 53 reserved words in Java.
*/
Read more »

Can we use Reserved words as identifiers?

class Identifier5
{
public static void main(String alt[])
{
int if=25;
System.out.println(if);
}
}
/*
O/P:- Compilation Error
Explanation :- We cannot use reserved words as an identifier.
There are total 50 reserved words in Java.
*/
Read more »

Upto how long characters we can take identifiers?

class Identifier4
{
public static void main(String alt[])
{
int abcdefghijklmnopqrstuvwxyzabcdefg=30;
System.out.println(abcdefghijklmnopqrstuvwxyzabcdefg);
}
}
/*
O/P:- 30
Explanation :- There is no length limit of java identifiers but it never recommended
to take lengthy identifiers because it reduces readability of the code.
*/
Read more »

Identifiers are case sensitive or not?

class Identifier3
{
public static void main(String alt[])
{
int number=10;
int Number=20;
int NUMBER=30;
System.out.println(number);
System.out.println(Number);
System.out.println(NUMBER);
}
}
/*
O/P:- 10 20 30
Explanation :- Java Identifiers are case sensitive.
*/
Read more »

Can any identifier be start with digit?

class Identifier2
{
public static void main(String alt[])
{
int 123total=10;
System.out.println(123total);
}
}
/*
O/P:- Compilation Error
Explanation :- Identifiers should not start with digit.
*/
Read more »

Can we use "@" symbol as identifier?

class Identifier1
{
    public static void main(String alt[])
    {
        int total@number=10;
        System.out.println(total@number);
    }
}
/*
O/P:- Compilation Error
Explanation :- The only allowed characters in Java Identifier are
A-Z, a-z, 0-9, _(underscore) and $(dollar)
*/
Read more »