A Variable in java is like a container in which we can store values.

A variable in Java must be a specified data type.

Data Types in Java are defined as specifiers that allocate different sizes and types of values that can be stored in the variable or an identifier. For example ,  I can fill a water bottle with water. In which water bottle is a data type and water is a value.



Declaring a Variable

To create a variable, you must specify the type and assign it a value:
Syntax:
type variable = value;

Where,
   type is one of Java's Data types (such as int or String),
   variable is the name of the variable (such as x or name),
   The "=" sign is used to assign values to the variable.

For example,
   To create a variable age and of data type integer and assign it the value 18:
     int age = 18;

Types of Variables

1)Local Variables 
Local Variables are a variable that are declared inside the body of a method. A local variable cannot be defined with "static" keyword.


2)Instance Variables
A variable declared inside the class but outside the body of the method, is called an instance variable. Instance variables are defined without the STATIC keyword .
It is called an instance variable because its value is instance-specific and is not shared among instances.

3) Static Variables
Static variables are initialized only once, at the start of the program execution. These variables should be initialized first, before the initialization of any instance variables.

Example :
class AJBlogs
{
         static int a=100; // Static variable
         int b =20; // instance vaiable
         void method () {
                 int c=18; // local variable
}


Final Variables

You can final keyword if you don't want others to overwrite existing values ( this will declare the variable as "final" or "constant", which means unchangeable and read-only):

example-
final int num= 20;
num=25; // will generate an error: cannot assign a value to a final variable

Java Identifiers

All Java variables must be identified with unique names. These unique names are called identifiers. Identifiers can be short names (like x and y) or more descriptive names (age, sum, year).

Note: It is recommended to use descriptive names in order to create understandable and maintainable code: