Saturday, May 5, 2007

Java Language Basics - Conventions used for Naming Variables

Every programming language has its own set of rules and conventions for the kinds of names that you're allowed to use.The rules and conventions for naming your variables as far as Java is concerned are given below:

1.Variable names are case-sensitive

2.A variable's name can be an unlimited-length sequence of Unicode letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_".
Note: Normally the convention is to start a variable name with letter & not with $ or underscore (_) character.

3.White space in variable name is not permitted.

4.Subsequent characters after first letter may be letters, digits, dollar signs, or underscore characters

5. Use full words instead of cryptic abbreviations; this will make your code easier to read and understand.
e.g. use variable name as 'speed' instead of 's' etc..

6.Variable name can't be standard keywords/reserved words
Visit the following Link to see the list of Java Keywords & Reserved words
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/_keywords.html

7.If variable name is a single word name that in lowercase
e.g. int speed;

8.If a variable name has more than one word, then start with lowercase and then capitalize the first letter of each subsequent word
e.g. int numberOfGears; or double capitalPrice;

9.If your variable stores a constant value (in Java constants are marked with attaching a 'final' keyword before variable name)such as
static final int NUMBER_OF_GEARS = 6;
(NUMBER_OF_GEARS is a constant static class variable whose value can't be changed)

the convention changes slightly, capitalizing every letter and separating subsequent words with the underscore character. By convention, the underscore character is never used elsewhere.


In the next post we will have a look at "Primitive Data Types" in Java.

2 comments:

Dhanashree said...

thanks for sarting the training.i am regular reader of your blog. Keep writing.

Shrinivas Mujumdar said...

Thanks for your support

 
online degree programs
visit us .