Variables and constants are fundamental building blocks in Java. Variables store changeable data, while constants store fixed values that cannot be modified once assigned.
final keywordfinal
// Declaring and using variables in Java
int age = 20;
double salary = 45000.50;
char grade = 'A';
boolean isStudent = true;
System.out.println(age);
System.out.println(salary);
System.out.println(grade);
System.out.println(isStudent);
// Declaring constants using final keyword
final double PI = 3.14159;
final int MAX_USERS = 100;
System.out.println(PI);
System.out.println(MAX_USERS);
Variables like age and salary can be changed during program execution. Constants such as PI remain fixed and cannot be reassigned once initialized.