Java Programming

Variables in Java ( Easy Concept )

When we store any value in our computer’s memory then we must have to decide that where the value is to be stored in the memory. Since memory is a very large element of a computer. There are hundreds of thousands of locations are available in a computer memory to store our data. So it is not possible to remember these locations of memory by its references due to which the concept of naming these memory locations are introduced.

Introduction to the variables

A Variable is a type of identifier which we use to name a particular memory location where we want to store our values.

For example-

For a memory address 00110100101, we simply give a variable name “number”. Now instead of using this memory location to use our values, we simply use the constant “number” to access the memory location.

NOTE – Variables are the constants, i.e., their name cannot alter during the execution of our program. We can declare a variable while creating our program only.

A variable can be declared using predefined syntax,

datatype variable_name;


Examples of Variables-

int number;

int roll;

float marks;

int a[50];

Rules For Naming a Variable

There are some certain rule which we have to follow while naming a variable,

  • It must be of alphabets(a to z), digits(0 to 9) & underscore(_) only.
  • No space is allowed i.e., we can not write num 1 instead if num1.
  • It must not begin with any digit (0 to 9).
  • Variable are case sensitive.
  • Keywords are not allowed as the name of the variable. Please refer – Tokens in Java (Keywords, Identifiers, Literals).
  • No limitation on the length of the variable.




Leave a Reply