⏱️ 6 min read • Beginner Level • Lesson 12
Completed on . You can revise this lesson or continue to the next topic.
Identifiers in Java are programmer-defined names used for variables, methods, classes, packages, interfaces, and other program elements. They help make Java programs more readable, meaningful, and professional.
Before learning identifiers, you should understand Java keywords and variables in Java, because identifiers are commonly used to name variables, methods, and classes.
In Java, an identifier is a name given by the programmer to identify program elements such as variables, classes, methods, interfaces, packages, and objects.
Think of identifiers like names assigned to people.
Instead of calling someone "Person 1" or "Person 2",
we use names such as John or Sarah.
Similarly, in Java we use identifiers such as
studentAge or totalMarks
to identify data and program elements.
Identifiers are programmer-defined tokens used to give names to program elements.
Examples include names of variables, methods, classes, interfaces, and packages.
Good identifiers improve readability and make code easier to understand and maintain.
Java identifiers must follow certain rules. If these rules are not followed, the compiler will show an error.
_),
and dollar sign ($).
age, Age, and
AGE are different identifiers.
class,
public, static, or int.
$ and _ are allowed in identifiers,
they should generally be avoided in normal variable and method names unless required.
These identifiers are valid because they follow Java identifier rules.
public class LegalIdentifiers {
public static void main(String[] args) {
int studentAge = 20;
int marks40 = 85;
int s_count = 10;
int totalMarks = 450;
System.out.println(studentAge);
System.out.println(marks40);
System.out.println(s_count);
System.out.println(totalMarks);
}
}
studentAge follows camelCase naming convention.marks40 contains digits but does not start with one.s_count uses an underscore.These identifiers are invalid because they break Java naming rules.
int 1stNumber; // Invalid: starts with a digit
int student age; // Invalid: contains a space
int oh!god; // Invalid: contains illegal symbol !
int class; // Invalid: class is a Java keyword
1stNumber starts with a digit.student age contains a space.oh!god contains an invalid character.class is a reserved Java keyword.
Always choose meaningful names for identifiers. For example,
use studentAge instead of x.
Naming conventions are not mandatory rules, but they are strongly recommended because they make Java code professional and easier to read.
camelCase
(for example, studentAge, totalMarks).
camelCase
(for example, getStudentName(), calculateTotal()).
PascalCase
(for example, StudentRecord, EmployeeDetails).
UPPER_CASE with underscores
(for example, MAX_VALUE, PI).
com.prowessapps.java).
| Identifier Type | Convention | Example |
|---|---|---|
| Variable | camelCase | studentAge |
| Method | camelCase | getStudentName() |
| Class / Interface | PascalCase | StudentRecord |
| Constant | UPPER_CASE | MAX_VALUE |
| Package | lowercase | com.prowessapps.java |
studentAge instead of x.
📥 Download the Java Identifiers and Naming Conventions Cheatsheet (PDF)
age and Age are different.🧠 Test your understanding with a quick quiz
Topic: Identifiers | Language: Java
🎉 Great job! Continue learning Java step by step.
Mark this lesson as completed to track your learning progress. To keep track across devices, please login and save your learning progress.
Discussion
Ask questions, share suggestions, or discuss this lesson.