Variables
In this lesson, you'll be introduced to variables in Java.
We'll cover the following...
Introduction
We store different kinds of information in computer memory. The layout of the computer’s memory (RAM or Random Access Memory) tends to be complex. We may not remember where we stored certain information in memory. A variable helps us remember.
A variable is the name we associate with a memory location in computers. For example, if you want to store a phone number in the computer memory, you can create a variable for it. When you need to read or update the phone number, you can simply access the variable you created for it instead of remembering where you stored the phone number.
Layout of RAM
Random Access Memory (RAM) temporarily stores the data during the runtime of an application. Do not confuse it with hard drives, which store data persistently. RAM is typically divided into multiple memory blocks. Each of these blocks is given sequential memory addresses.
So, whenever you store a variable, it is stored at one of these memory addresses. Due to the abstraction provided by a variable, you do not need to remember the memory address. Pretty convenient, right?
Declaring variables in Java
To declare a variable in Java, you need three things:
- Type of the variable
- Name of the variable
- Value of the