Showing posts with label Identifiers in java. Show all posts
Showing posts with label Identifiers in java. Show all posts

Friday, 11 January 2013

Java Identifiers

Identifiers in Java

Basics in using Identifiers in Java Programming

Identifiers are programmer-designed tokens. They are used for naming classes, methods, variables, objects, labels, packages and interfaces in a program. Java identifier’s basic rules are as follows:
  1. They can have alphabets, digits, and the underscore and dollar sign characters.
  2. They must not begin with a digit.
  3. Uppercase and lowercase letters are distinct.
  4. They can be of any length.
Identifier must be meaningful, short enough to be quickly and easily typed and long enough to be descriptive and easily read. Java developers have followed some naming conventions.
  • Names of all public methods and instance variables start with a leading lowercase letter. 
  • When more than one word are used in a name, the second and subsequent words are marked with a leading uppercase letters. 
  • All private and local variables use only lowercase letters combined with underscores.
  • All classes and interfaces start with a leading uppercase letter(and each subsequent word with a leading uppercase letter).
  • Variables that represent constant values use all uppercase letters and underscores between words.
We may follow our own conventions as long as we do not break the basic rules of naming identifiers. 
The following table shows some valid and invalid identifiers:

Hello World (uses a space)
Hi JAVA! (uses a space and punctuation mark)
3value(begins with a number)
short (this is a Java keyword)
#age (does not begin with any other symbol except _ $ )

It is standard Java practice to name multiple-word identifiers in lowercase except for the beginning letter of words in the middle of the name.