A declaration starts with the type of the variable, followed by the name of the variable. A variable name starts with a lower-case, then is proper-cased.
When declared inside of a method, a scope is not specified. These are automatically local variables.
When declared outside of a method, the scope should be specified.
Statement of scope comes before the type. Scope applies only to variables declared outside of the methods, also known as class-level variables. The types of scope are:
- public - can be seen outside of and inside the class
- private - can only be seen inside the class
- protected - can be seen inside the class and by child classes (classes that extend)
Class level variables without a statement of scope are protected.
It is a good habit to set a variable to a value, even if it is null, at the time it is declared. On occasion, variables declared inside a method that are not initialized will cause a compile-time error.