Courses Tutorials Practice Jobs Search...
Sign In
Java Course Java Arrays Java Strings Java OOPs Java Collection Java 8 Tutorial Java Multithreading Java Exception Handling Java Programs Sign In
Explore GfG Courses
Java Identifiers
Share Your Experiences
Last Updated : 15 Apr, 2025
Java Identifiers
An identifier in Java is the name given to Variables, Classes,
Java Keywords
Methods, Packages, Interfaces, etc. These are the unique names 00:04
Java Variables used to identify programming elements. Every Java Variable must
be identified with a unique name.
Java Operators
Example:
Decision Making in Java (if, if-
else, switch, break, continue, public class Test
jump) {
public static void main(String[] args)
Java Loops {
int a = 20;
Java Methods, Arrays, }
Strings & Regex }
Java OOPs & Interfaces In the above Java code, we have 5 identifiers as follows:
Test: Class Name
Java Collections
main: Method Name
String: Predefined Class Name
Java Exception Handling
args: Variable Name
Java Multithreading and a: Variable Name
Synchronization
Rules For Naming Java Identifiers
Java File Handling, I/O,
There 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++.
198k+ interested Geeks 2k+ interested Ge
The only allowed characters for identifiers are all alphanumeric
C Programming Course Online Gate CSE 2027 [
characters([A-Z],[a-z],[0-9]), '$'(dollar sign) and '_' (underscore).
- Learn C with Data Structures Placement Prep
For example, "geek@" is not a valid Java identifier as it contains
Explore Explore
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 Identifiers
MyVariable
MYVARIABLE
myvariable
x
i
x1
i1
_myvariable
$myvariable
sum_of_array
geeks123
Examples of Invalid Identifiers
00:05
My Variable // contains a space
123geeks // Begins with a digit
a+c // plus sign is not an alphanumeric
character
variable-2 // hyphen is not an alphanumeric
character
sum_&_difference // ampersand is not an alphanumeric
character
Reserved Words in Java
Any programming language reserves some words to represent
functionalities defined by that language. These words are called
reserved words. They can be briefly categorized into two parts:
Related searches
Java Identifiers and Classes Java Class Keyword Java Identifiers and Keywords
Keywords (50): Keywords define functionalities.
literals (3): Literals define value.
Identifiers are stored by symbol tables and used during the
lexical, syntax, and semantic analysis phase of compilation.
List of Java Reserved Words
abstract continue for protected transient
Assert Default Goto public Try
Boolean Do If Static throws
break double implements strictfp Package
byte else import super Private
case enum Interface Short switch
Catch Extends instanceof return void
Char Final Int synchronized volatile
class finally long throw Date
const float Native This while
Note: The keywords const and goto are reserved, even though
they are not currently used in Java. In place of const, the final
keyword is used. Some keywords like strictfp are included in
later versions of Java.
Comment More info
Next Article
Campus Training Program
Java Keywords
Similar Reads
1. Java Features
2. enum in Java
3. Coding Guidelines in Java
4. Encapsulation in Java
5. Enumeration Interface In Java
6. Collections in Java
7. Introduction to Java
8. Collection Interface in Java
9. Interesting Facts About Java
10. Naming Conventions in Java
Company Explore Tutorials DSA Data Science & Web
About Us Job-A-Thon Python Data Structures ML Technologies
Corporate & Legal O!line Classroom Java Algorithms
Communications Address: Data Science With HTML
Privacy Policy Program C++ DSA for Beginners Python CSS
A-143, 7th Floor, Sovereign
Corporate Tower, Sector- Careers DSA in JAVA/C++ PHP Basic DSA Problems Machine Learning JavaScript
136, Noida, Uttar Pradesh In Media Master System GoLang DSA Roadmap ML Maths TypeScript
(201305) Contact Us Design SQL DSA Interview Data Visualisation ReactJS
Corporate Solution Master CP R Language Questions Pandas NextJS
Registered Address: Campus Training Videos Android Competitive NumPy NodeJs
K 061, Tower K, Gulshan Program Programming
Vivante Apartment, Sector NLP Bootstrap
137, Noida, Gautam Buddh Deep Learning Tailwind CSS
Nagar, Uttar Pradesh, 201305
Python Tutorial Computer DevOps System Design School Subjects Databases
Python Examples Science Git High Level Design Mathematics SQL
Django Tutorial GATE CS Notes AWS Low Level Design Physics MYSQL
Python Projects Operating Systems Docker UML Diagrams Chemistry PostgreSQL
Python Tkinter Computer Network Kubernetes Interview Guide Biology PL/SQL
Web Scraping Database Azure Design Patterns Social Science MongoDB
OpenCV Tutorial Management System GCP OOAD English Grammar
Advertise with us Python Interview So"ware Engineering DevOps Roadmap System Design
Question Digital Logic Design Bootcamp
Engineering Maths Interview Questions
Preparation More Tutorials Courses Programming Clouds/Devops GATE 2026
Corner So"ware IBM Certification Languages DevOps Engineering GATE CS Rank
Company-Wise Development Courses C Programming with AWS Solutions Booster
Recruitment Process So"ware Testing DSA and Placements Data Structures Architect GATE DA Rank
Aptitude Preparation Product Web Development C++ Programming Certification Booster
Puzzles Management Data Science Course Salesforce Certified GATE CS & IT Course -
Company-Wise Project Management Programming Java Programming Administrator Course 2026
Preparation Linux Languages Course GATE DA Course 2026
Excel DevOps & Cloud Python Full Course GATE Rank Predictor
All Cheat Sheets
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our
Got It !
Cookiereserved
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights Policy & Privacy Policy