Java Identifiers

HomejavaJava Identifiers

Course Curriculum

  • Java Programming Language
  • How to start learning Java
  • Beginning Java programming with Hello World Example
  • Java Naming Conventions
  • How JVM Works – JVM Architecture?
  • Java Virtual Machine (JVM) Stack Area
  • JVM Shutdown Hook in Java
  • Java Class File
  • Differences between JDK, JRE and JVM
  • Does JVM create object of Main class (the class with main())?
  • How is Java platform independent?
  • JDBC Drivers
  • Is main method compulsory in Java?
  • Myth about the file name and class name in Java
  • How to run java class file which is in different directory?
  • Microservices Introduction
  • Using predefined class name as Class or Variable name in Java
  • Java Identifiers
  • Data types in Java
  • enum in Java
  • Enum with Customized Value in Java
  • StringBuffer appendCodePoint() Method in Java with Examples
  • Variables in Java
  • Scope of Variables In Java
  • Blank Final in Java
  • Bounded types with generics in Java
  • Loops in Java
  • For-each loop in Java
  • For Loop in Java
  • Decision Making in Java (if, if-else, switch, break, continue, jump)
  • Switch Statement in Java
  • String in Switch Case in Java
  • Widening Primitive Conversion in Java
  • Type conversion in Java with Examples
  • Comments in Java
  • null in Java
  • Using _ (underscore) as variable name in Java
  • Currying Functions in Java with Examples
  • Binary Search in Java
  • Sorting in Java
  • Classes and Objects in Java
  • How are Java objects stored in memory?
  • How to swap or exchange objects in Java?
  • Inheritance in Java
  • Encapsulation in Java
  • Abstraction in Java
  • Dynamic Method Dispatch or Runtime Polymorphism in Java
  • Association, Composition and Aggregation in Java
  • Access and Non Access Modifiers in Java
  • Access Modifiers in Java
  • this keyword in java
  • Overloading in Java
  • Overriding in Java
  • Understanding “static” in “public static void main” in Java
  • Can we Overload or Override static methods in java ?
  • Shadowing of static functions in Java
  • Static methods vs Instance methods in Java
  • Assigning values to static final variables in Java
  • Covariant return types in Java
  • Object class in Java
  • Static class in Java
  • Flexible nature of java.lang.Object
  • Overriding equals method in Java
  • Overriding toString() in Java
  • Instance Variable Hiding in Java
  • Static blocks in Java
  • The Initializer Block in Java
  • Instance Initialization Block (IIB) in Java
  • Static vs Dynamic Binding in Java
  • Why Java is not a purely Object-Oriented Language?
  • Understanding Classes and Objects in Java
  • Java and Multiple Inheritance
  • Java Object Creation of Inherited Class
  • Inheritance and constructors in Java
  • Interfaces and Inheritance in Java
  • Using final with Inheritance in Java
  • Parent and Child classes having same data member in Java
  • Object Serialization with Inheritance in Java
  • Referencing Subclass objects with Subclass vs Superclass reference
  • Does overloading work with Inheritance?
  • Operators in Java
  • Bitwise operators in Java
  • new operator in Java
  • Bitwise right shift operators in Java
  • Java instanceof and its applications
  • Comparison of Autoboxed Integer objects in Java
  • Addition and Concatenation in Java
  • Java Numeric Promotion in Conditional Expression
  • Character Stream Vs Byte Stream in Java
  • DoubleStream mapToObj() in Java
  • Command Line arguments in Java
  • Scanner Class in Java
  • Scanner and nextChar() in Java
  • Difference between Scanner and BufferReader Class in Java
  • Formatted output in Java
  • Fast I/O in Java in Competitive Programming
  • Ways to read input from console in Java
  • String class in Java
  • StringBuffer class in Java
  • StringBuilder Class in Java with Examples
Java Identifiers 14 May

Java Identifiers

|

java

|

In programming languages, identifiers are used for identification purposes. In Java, an identifier can be a class name, method name, variable name, or label. For example :

public class Test { public static void main(String[] args) { int a = 20; } }

In the above java code, we have 5 identifiers namely :

  • Test : class name.
  • main : method name.
  • String : predefined class name.
  • args : variable name.
  • a : variable name.

Rules for defining Java Identifiers

There are certain rules for defining a valid java identifier. These rules must be followed, otherwise we get compile-time error. These rules are also valid for other languages like C,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 contain ‘@’ special character.
  • Identifiers should not start with digits([0-9]). For example “123prutor” is a 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 while is a reserved word. There are 53 reserved words in Java.

Examples of valid identifiers :

MyVariable MYVARIABLE myvariable x i x1 i1 _myvariable $myvariable sum_of_two_nums prutor456

Examples of invalid identifiers :

My Variable // contains a space 456prutor // Begins with a digit x+y// 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

Any programming language reserves some words to represent functionalities defined by that language. These words are called reserved words.They can be briefly categorised into two parts : keywords(50) and literals(3). Keywords define functionalities and literals define a value. Identifiers are used by symbol tables in various analyzing phases(like lexical, syntax, semantic) of a compiler architecture.

Note: The keywords const and goto are reserved, even though they are not currently used. In place of const, the final keyword is used. Some keywords like strictfp are included in later versions of Java.

Using predefined class name as Class or Variable name in Java (Prev Lesson) (Next Lesson) Data types in Java

Tag » What Are Identifiers In Java