Java Identifier
Java Identifier
Identifiers in java :-
Identifiers in Java are symbolic names used for identification.
They can be a class name, variable name ( local variables, instance and class variables), method name,
package name, lable name , constant name, and more.
However, In java There are some reserved words that can not be used as an identifier.
For every identifier there are some conventions that should be used before declaring them.
7. println (method)
There are some rules and conventions for declaring the identifiers in Java.
If the identifiers are not properly declared, we may get a compile-time error.
Following are some rules and conventions for declaring identifiers:
A valid identifier must have characters [A-Z] or [a-z] or numbers [0-9], and underscore(_) or a dollar
sign ($). for example, @javatpoint is not a valid identifier because it contains a special character which
is @.
There should not be any space in an identifier. For example, java tpoint is an invalid identifier.
An identifier should not contain a number at the starting. For example, 123javatpoint is an invalid
identifier.
Java Identifier 1
An identifier should be of length 4-15 letters only. However, there is no limit on its length. But, it is
good to follow the standard conventions.
We can't use the Java reserved keywords as an identifier such as int, float, double, char, etc. For
example, int double is an invalid identifier in Java.
All identifiers can begin with a letter, a currency symbol or an underscore (_). According to the
convention, a letter should be lower case for variables.
An identifier cannot be the same as a query language keyword. Here is a list of query language
keywords:
Some widely recognized best practices for naming in Java are given below.
1. Use Meaningful Names: Choose names that clearly and intuitively describe the purpose of the variable,
method, or class. For example, use employeeSalary instead of vague names like es or data.
Classes and Interfaces: Use CamelCase with the first letter capitalized, e.g. Student, BankAccount.
Java Identifier 2
Constants: Use all uppercase letters with underscores to separate words,
e.g. MAX_SIZE, DEFAULT_VALUE.
3. Start with a Letter: Although underscores and dollar signs are allowed, it's standard practice to start
names with a letter.
4. Avoid Using Single Characters: Except for temporary and loop variables (like i, j, x, y), avoid single-
character names. Descriptive names make the code more understandable.
5. Be Consistent: Use consistent naming patterns throughout your codebase. This consistency helps others
understand the structure and purpose of your code more quickly.
6. Avoid Abbreviations and Acronyms: Avoid using abbreviations unless the abbreviation is more widely
known than the full word (like URL). They can make the code less readable, especially for those unfamiliar
with the abbreviations.
7. Differentiate Clearly: Avoid using names that differ only by number or case, e.g. user1, user2,
or User, user, as they can be easily confused.
8. Use Pronounceable Names: Names that can be pronounced are generally easier to discuss, which can
be important during team discussions or code reviews.
9. Context Matters: Use names that provide enough information about their use. For
instance, saveEmployeeData is more informative than just saveData.
10. Avoid Redundancy and Noise Words: Avoid redundant information that doesn’t add clarity,
e.g. Customer class doesn’t need variables like customerName. Just the name is sufficient.
Identifier Explanation
Employee alphabets
EMP12 alphanumerics
Java Identifier 3
Student36Pro9 alphanumerics
A alphabet uppercase A
i alphabet lowercase i
$ Symbol $
Identifier Explanation
5 Is a numeric
DURGA SIR :-
All predefined java class name and interface names we can use as identifiers.
It is valid , but it is not programming practise , because it reduce redability and create confusion.
Java Identifier 4