Variables

What are variables and why do we need variables in programming? 

Variables are like boxes to store items. In Java, you need to know the sizes of the boxes so that the item can be stored properly. In another words, you need variables to store your data (item) and need to know the datatype(size) of the variables(box).

We need this variable to perform some operations and it would be better to change the value of the variable and then print them out rather then hard-coding in the println method. When we hard-code the data in the println, there might be some possibilities that the data might change and we might need to check the whole document to see if we got mention the data anywhere.

So now the question will be, how to write and declare a variable in Java? 
Answer:

datatype variableName = data;

String name = ‘Bob’;
int age = 23;
boolean checker = True;
double price = 23.33;

The actual code to play with the variables:

vaiables
The actual codes of variables with comments

Leave a comment