private int x = 0; String colorBlue = â€œblueâ€;
There are also different kinds of variables:
Instance Variables: Instance variables are so named because they are variables that are associated with instances of a class; each instance of a class has its own set of instance variables.
Class Variables: Class variables are static, no mater how many instances of the class there are, there is only instance of a class variable.
Local Variables: Local variables have no meaning outside their method. I often refer to them as â€œtrash variablesâ€ because after they are used in a method, they are discarded as â€œtrash.â€
1. A variable can consist of any alphanumeric character and must begin with a letter, a dollar sign, or an underscore. The use of a dollars sign is highly discouraged and so is the underscore. However, it is becoming a popular trend to define instance variables with an underscore.
2. Variables are case sensitive. MyVariable is NOT the same as myvariable.
3. It is convention to start your variable names with a letter, and each subsequent word capitalize. It is also a bad programming practice to use abbreviations as variables and ambiguous variables.
Poor program practices would be
int [B]MyVar [/B]= 0; //var??? int [B]x[/B] = 0; //what is x?
Perfred programming practices
int [B]myVariable [/B]= 0; int [B]xLocation [/B]= 0;