String name = "Deepak";
// here name is identifierint rollno = 101;
// here rollno is identifierclass Test {-}
// here Test is identifierint roll no; // Error: Spaces are not allowed
String user name; // Error: Spaces are not allowed
int rollno;
String username;
_
and $
) can be used in an identifier.
_
) or dollar signs ($
), but other special symbols like @
, #
or !
are not allowed.
int roll-no; // Error: '-' is not allowed
double @price; // Error: '@' is not allowed
int roll_no;
double $price;
int 1rollno; // Error: Cannot start with a digit
double 3value; // Error: Cannot start with a digit
int rollno1;
double _123value;
class
, public
, if
, etc.) cannot be used as identifiers.
int class; // Error: 'class' is a reserved keyword
String public; // Error: 'public' is a reserved keyword
int my_class;
String _if;
int println = 5; // Valid but confusing, as 'println' is used in System.out.println()
MyVariable
and myVariable
are treated as distinct identifiers.
int MyVariable = 10;
int myVariable = 20; // Different from 'MyVariable'
int thisIsAnExtremelyLongVariableName = 100; // Valid but not recommended
int x = 10; // Valid but not descriptive
int age = 10; // Better: Descriptive and meaningful
Your feedback helps us grow! If there's anything we can fix or improve, please let us know.
We’re here to make our tutorials better based on your thoughts and suggestions.