Understanding Variable and Primitive Data Type

In this class, We discuss Understanding Variable and Primitive Data Type.

The reader should have basic knowledge of program execution and memory. Click Here.

In our last class, we discussed our java program execution.

During the execution, if the processor needs data, it will get it from the random access memory.

The question here is what type of data is needed for the program?

Different types of data are needed for the program execution.

So we need to inform the compiler of the data type needed to be stored.

Using some keywords in the java language, we inform the compiler of the data type needed.

List of primitive data types in java:

1) Byte

2) Short

3) int

4) long

5) float

6) double

7) char

8) boolean

Variable:

A variable is a container to hold data.

Variable decleration:

int a;

The above line execution creates a space in Random access memory.

The below diagram shows the memory allocation and symbol table to identify the variable.

The symbol table stores the list of variables and their memory locations.

Why a symbol table?

Take the next line of code a=20;

The next line assigns value to the variable.

The compiler will check the symbol table and find the memory location allocated to the variable a to assign a value.

First, declare a variable, then assign a value to that variable.

Without declaring a variable, we can not assign a value.

Declaring a variable will provide memory space for that variable.