Variables

index
BASIC

A variable is a name that has a value. A variable can have different values at different times.

All variables must be declared. When a variable is declared, it is given a type that tells what kind of values it can have. It may also be given an initial value. An int variable can only have an integer value, a String variable can only have a character string as its value, and so on.

Java is case-sensitive; that is, result, Result, and RESULT are three different variables. Type names must be capitalized correctly: int, not Int; String, not string; etc.

STYLE

There are strict conventions for variable names:

Many kinds of things in Java have names, not just variables. Proper naming and capitalization helps the experienced Java programmer know what kind of thing is being named. The names of classes and interfaces always begin with a capital letter, and constants are written using all capitals, with underscores to separate words.