Back to Lessons

Java Variables and Data Types

April 5, 2026

Java Variables and Data Types

Java supports primitive types and reference types with strict typing.

Primitive Types Example

int age = 25;
double salary = 75000.50;
char grade = 'A';
boolean isActive = true;
String name = "John Doe";

Key Points

  • 8 primitive types: byte, short, int, long, float, double, char, boolean.
  • Declare before use: type variableName = value;.
  • String is reference type, immutable.
  • Type casting: int num = (int)9.7; // truncates to 9.