We’ll cover the following
- Introduction
- Java Identifiers Naming
- Example
Introduction
An identifier is a word to refer to a Java programming element.
The indentifiers are most commonly used for the following elements:
- Classes
- Methods
- Variables and fields, which hold data used by your program
- Parameters, which pass data values to methods
Identifiers are also sometimes called names.
Identifiers are used for class names, method names, and variable names. An identifier
may be any descriptive sequence of uppercase and lowercase letters, numbers, or the
underscore and dollar-sign characters. They must not begin with a number, lest they be
confused with a numeric literal. Again, Java is case-sensitive, so VALUE is a different
identifier than Value.
Java Identifiers Naming
You must follow a few simple rules when you create identifiers:
- Identifiers are case-sensitive. As a result, Test and test are distinct identifiers.
- Identifiers can be made up of upper- or lowercase letters, numerals, underscore characters (_), and dollar signs ($). Thus, identifier names such as Port1, SalesTax$, and Total_Value.
- All identifiers must begin with a letter. Thus, a21 is a valid identifier, but 7Life isn’t because it begins with a numeral.
- An identifier can’t be the same as any of the Java keywords. Thus, you can’t create a variable named for or a class named public.
The Java language specification recommends that you avoid using dollar signs in names you create, because code generators use dollar signs to create identifiers.
Example
Some examples of valid identifiers are
AvgTemp
count
a4
$test
this_is_ok
Invalid identifier names include these:
2count //cannot start with digit
high-temp //cannot have -
Not/ok //cannot have /
Beginning with JDK 8, the use of an underscore by itself as an identifier is not recommended.
That’s it!
You have successfully completed the post. Do Share : )
Peace Out!
Also Read – Java Keywords and Statements
Check Out Deals on -> Amazon , Flipkart , Myntra , Adidas , Apple TV , Boat , Canva , Beardo , Coursera , Cleartrip , Fiverr , MamaEarth , Swiggy
[…] Also Read – Java Identifiers […]
[…] Variable names follow the same rules as other Java identifiers. […]
[…] Also Read – https://codingtimes.in/category/java/ […]
[…] Java Identifiers […]