Understanding Java Identifiers: Rules, Conventions, and Reserved Keywords

Programming languages or concepts

 All Java variables must be identified by a unique name.

These unique names are called identifiers.

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

Identifiers in Java are symbolic names used for identification. It can be class name, variable name, method name, package name, constant name and many more.

Identifiers can be short names (such as x and y) or more descriptive names (age, sum, total volume).There are some reserved words that can not be used as an identifier.


public class Java {  

    public static void main(String[] args) {  

        System.out.println("Hello Java Programmer");  

    }  

}  


From the above example, we have the following Java identifiers :

  1. HelloJava (Class name)
  2. main (main method)
  3. String (Predefined Class name)
  4. args (String variables)
  5. System (Predefined class)
  6. out (Variable name)
  7. println (method)

Rules for Identifiers in Java

  • 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:
  • 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.
  • 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 @.
  • An identifier should not be any query language keywords such as SELECT, FROM, COUNT, DELETE, etc.
  • An identifier should not contain a number at the starting. For example, 123javatpoint is an invalid identifier.
  • 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.
  • There should not be any space in an identifier.

Java Reserved Keywords 

Java reserved keywords are predefined words, which are reserved for any functionality or meaning. We can not use these keywords as our identifier names, such as class name or method name. These keywords are used by the syntax of Java for some functionality. If we use a reserved word as our variable name, it will throw an error.

Below is the list of reserved keywords in Java :


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

 


Tags:
close