Declaring variables
All applications process data. Data comes in, data is processed, and data goes out.
Data usually comes into our program from files, databases, or user input. Data can be put temporarily in variables that will be stored in the memory of the running program. When the program ends, the data in memory is lost. Data is usually output to files and databases or to the screen or a printer.
When using variables, you should think about, first, how much space it takes in memory, and, next, how fast it can be processed.
We control this by picking an appropriate type. You can think of simple common types such as int
and double
as being differently sized storage boxes. A smaller box would take less memory but may not be processed as quickly.
Naming variables
There are naming conventions for variables and it is best practice to follow them, as shown in the following table:
Naming convention |
Examples |
Usage |
---|---|---|
Camel case |
|
Local variables and private members... |