Home / Questions / What is a datatype?
Explanatory Question

What is a datatype?

👁 90 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

  • A datatype defines what kind of data a variable can hold in Java.

  • Example:


int age = 25;       // age can store integer values
double salary = 5000.50; // salary can store decimal values
char grade = 'A';   // grade stores a single character
boolean isPassed = true; // stores true/false

Java datatypes are mainly two categories:

  • Primitive typesint, double, boolean, char, byte, short, long, float

  • Reference types → classes, arrays, interfaces, enums, etc.