ALL LESSONS Module 3

Java Variables and Data Types

Apr 5, 2026 1 min read

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.

Need help with this lesson? Visit the Discussion Forum