Data Types

1 min read ·

In Java, a data type defines what kind of value a variable can store.
When you declare a variable, you must tell Java what type of data it will hold. This helps Java:
  • Allocate proper memory
  • Perform correct operations
  • Prevent invalid data usage
Example:
Each variable stores a different type of data. If you try to store a decimal number inside an int, Java will give an error.
Java data types are divided into two main categories:
  • Primitive Data Types
  • Non primitive Data Types
In Next section, we focus on primitive types first.