JAVA VARIABLES:
- Variables are containers storing data values
- We use assignment operator (=) to assign a value to a variable.
Following rules must be followed:
⮚ The first character must always be an alphabet or an underscore.
⮚ It should be formed using only letters, numbers, or underscore.
⮚ uppercase and lowercase are distinct
⮚ A keyword cannot be used as a variable name.
⮚ It should not contain any whitespace character.
⮚ The name must be meaningful.
Declaring the variable
To create a variable, you must specify the data type and assign it a value:
Syntax
Data Type variable = value;
Declaring the variable
To create a variable, you must specify the data type and assign it a value:
Syntax
Data Type variable = value;
Program:
public class variable{
public static void main(String args[])
{
int a = 10;
System.out.println(a);
}
}
Output:
10
Explanation:
In the above program, we have created a simple class named variable in that we are creating a variable named by the above syntax, using the data type as integer and we're assigning a value to it. By using the output statement we're printing the value.