-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learn Java with Projects
By :

If you want to store a value for later use, you need a variable. Therefore, every programming language provides this feature via variables. In this section, we will learn what a variable is and how to declare one. The area in your code where you can use a particular variable is known as the variable’s scope. This is a very important concept and will be covered in detail in Chapter 4.
Variables are locations in memory that have a name (called an identifier) and a type. They resemble named pigeonholes or post office boxes (see Figure 2.1). The variable’s name is required so that we can refer to the variable and distinguish it from other variables.
A variable’s type specifies the sort of values it can store/hold. For example, is the variable to be used for storing whole numbers such as 4 or decimal numbers such as 2.98? The answer to that question determines the variable’s type.