Variables and rules in JAVA
Posted by
Ravi Kumar at Tuesday, March 3, 2009
Share this post:
|
0 Comments
In Java we declare a variable by placing the type first, fallowed by the name of the variable. Semicolon at the end of each declaration is necessary.
Rules for a variable name:
A variable name must begin with a letter, and must be a sequence of letters or digits.
A letter is defined as 'A'–'Z', 'a'–'z', '_', or any Unicode character that denotes a letter .
Digits are '0'–'9' and any Unicode characters that denote a digit.
Symbols like '+' or '©' cannot be used inside variable names, nor can spaces.
All characters in the name of a variable are significant and case is also significant. The length of a variable name is essentially unlimited.
Examples:
Int days;
Double salary;
Long population;
Char name;