In Java, variables are used to store data. Every variable in Java must be declared with a data type. Here are some of the common data types:
public class VariablesExample {
public static void main(String[] args) {
int age = 25;
double salary = 55000.50;
boolean isEmployed = true;
char grade = 'A';
String name = "John";
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Salary: " + salary);
System.out.println("Employed: " + isEmployed);
System.out.println("Grade: " + grade);
}
}
This example demonstrates how to declare and use variables in Java. The program prints the values of the variables to the console.