Tuesday, 12 January 2016

IDENTIFIERS IN JAVA

All Java components require names. Name used for classes, methods, interfaces and variables are called Identifier. Identifier must follow some rules. Here are the rules:
  • All identifiers must start with either a letter( a to z or A to Z ) or currency character($) or an underscore(_).
  • After the first character, an identifier can have any combination of characters.
  • A Java keyword cannot be used as an identifier.
  • Identifiers in Java are case sensitive, off and Off are two different identifiers.
There are two types of identifiers
  • Legal
  • Illegal
The following are legal variable names:
  • MyVariable
  • myvariable
  • MYVARIABLE
  • x
  • i
The following are illegal variable names;
  • My Space //Contains a space
  • 9pins6s // Begins with a digit
  • k+h // The plus sign is not an alphanumeric character testing
  • 61-72-83 // The hyphen is not an alphanumeric character

No comments:

Post a Comment