identifiers in java

In this article, we are going to discuss about identifiers.

Identifiers are the names given to variables, methods/functions, classes, interfaces.

For example:-

int number=1231;

String str=”identifiers in java”;

In the above example “number” and “str” are the identifiers.

Rules for identifiers in java:-

There are some rules for declaring identifiers in java. if identifiers are not according to rules then it will cause compile time error. Following are the rules for declaring identifiers in java.

  • The most important rule for an identifier is that it cannot be a keyword.
  • identifiers must be composed of letters [a-z] [A-z], numbers[0-9], underscore “_” and the dollar sign $. except these characters no other characters are allowed.
  • Identifiers cannot begin with numbers. for example:- “9gfc” it is not a valid identifier.
  • There is no limit to the length of a java variable name.
  • All variable names are case sensitive, for example:”Identifier_in_java” is not the same as “identifier in java”.

Examples of valid keyword in java:-

  • GangForCode
  • gangforcode
  • _gangforcode
  • $gangforcode
  • _8gangforcode

Invalid keywords in java:-

  • Gang For Code
  • 8gangforcode
  • gang+code
  • gang1-2-3

Data types in java
Keywords in java

5 thoughts on “identifiers in java”

Leave a Comment