Java Identifiers Last Updated : 06 Oct, 2025 Suggest changes Share 724 Likes Like Report An identifier in Java is the name given to Variables, Classes, Methods, Packages, Interfaces, etc. These are the unique names used to identify programming elements. Every Java Variable must be identified with a unique name. Java class Geeks { public static void main { int x = 9; } } The image below describes Identifiers in this program: Rules For Naming Java IdentifiersThere are certain rules for defining a valid Java identifier. These rules must be followed, otherwise, we get a compile-time error. These rules are also valid for other languages like C and C++. The only allowed characters for identifiers are all alphanumeric characters([A-Z],[a-z],[0-9]), '$'(dollar sign) and '_' (underscore). For example, "geek@" is not a valid Java identifier as it contains a '@', a special character.Identifiers should not start with digits([0-9]). For example, "123geeks" is not a valid Java identifier.Java identifiers are case-sensitive.There is no limit on the length of the identifier, but it is advisable to use an optimum length of 4 - 15 letters only.Reserved Words can't be used as an identifier. For example, "int while = 20;" is an invalid statement as a while is a reserved word.Note: Java has 53 reserved words (including 50 keywords and 3 literals), that are not allowed to be used as identifiers.Examples of Valid IdentifiersMyVariableMYVARIABLEmyvariablexix1i1_myvariable$myvariablesum_of_arraygeeks123Examples of Invalid IdentifiersMy Variable // contains a space123geeks // Begins with a digita+c // plus sign is not an alphanumeric charactervariable-2 // hyphen is not an alphanumeric charactersum_&_difference // ampersand is not an alphanumeric characterRelated Article:Reserved Words in Java Java Keywords G gaurav miglani 724 Article Tags : Java java-basics Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings8 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java9 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages7 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java5 min readJava Comparator Interface6 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java10 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management4 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like