Java Variables

Introduction to Variables in Java:

Variables in Java are containers for storing data values. They have a type that defines what kind of data they can hold and a name that identifies them within a program. Java is a statically typed language, meaning that you must declare the data type of each variable before you can use it.

1. Declaring Variables:

Variables in Java are declared using the following syntax:
int  age ;
Here, type is the data type (int) of the variable, and name  (age)is the identifier for the variable.

2. Declare Variable and Initialization Value:

Variables can also be declared and initialized in a single step:

Declare-Variable-and-Initialization-Value
Example:

Scenario of Integer Variable:

1.In the First step Declare an integer variable named age then initialize the value in the second step.
// Declare an integer variable named ‘age’. It is currently uninitialized.
int age;
// Assign the value 25 to the variable ‘age’.
age = 25;

2. Declare and initialize an integer variable named age with the value 20 in a single step.
// Declare an integer variable named ‘age ’ and initialize it with the value 20.
int age = 20;

Course Video

YouTube Reference :