Identifiers in JAVA


Identifiers are symbols used to name a language entity in different programming languages. You can also say that the identifiers are the name of a computer variables, methods, classes, packages, subroutines, labels, and interfaces.

Certain computer languages don’t allow you to use any or all the characters as Identifiers. For example, the earlier versions of C and C++ only allowed the use of characters such as underscores, digits, and some of the ASCII letters to be used as identifiers. However, the versions of these languages available today along with many other modern-day computer languages allow the use of all Unicode characters in an identifier. These languages still don’t allow the use of white space characters and language operators.

Some of us at times get confused between an identifier and a literal. Unlike literals, identifiers are the way literals are referred to. For example in the famous HelloWorld program, that most of us know, HelloWorld, String, args, main and println are identifiers.

In the Java language, all identifiers must begin with a letter, an underscore (_), the dollar sin ($), or a Unicode currency character. These identifiers don’t allow the use of any other symbol, such as a number and displays error message, if used. Also, Java does not permit the use of a reserved word as an identifier.

All the variables used in a program have specific names. Try assigning mnemonic names to your variables that are closely related to the values they hold. Also, remember that the variables names used in some programming languages such as C are case sensitive. For example, a variable named YourCounter is not the same as the variable named yourcounter. Like many other programming languages, variable names in java can be as long as you want them to be.  Some examples of valid variable names in Java are:

CounterMy,       validvariable,     COUNTER, $counter, _countermy, a, c, _10pen, andjas

The following on the other hand can be an example of a long variable name:

This_is_such_a_long_variable_namethat_goes_on_and_on_to_give_you_an_idea_of_how_long_a_variable_name_can_be.


However, the following variable names are not valid and cannot be declared:

•           Your Counter — as it contains a space

•           20pens —  as it starts with a digit

•           b+d — as the plus sign is not an alphanumeric character

•           testing_testing1-2-3 –  as the hyphen character used is not an alphanumeric character

•           Paul _&_Associates — as an ampersand is not an alphanumeric character

To begin a variable name with a numeric value, prefix it with an underscore. For example  _20whiteroses. Not only this, underscores can also be used as a space in very long variable names.

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>