In this tutorial, you’ll learn about Data types in Java.
In computer science, data is information that is stored or processed by a computer.
There are many data points we use in everyday life. Your name, your age, the number of apples in your pantry, whether your kitchen light is on or off. These can all be considered pieces of data, and we represent pieces of data in code using data types. Similar to other programming languages, Java classifies different pieces of data with data types based on their value.
For example, there’s a data type for letters and symbols, and there are various data types for numbers.
A data type provides a set of possible values, and if a piece of data is one of these values, it is classified as that specific type. Java separates its data types into two main categories that are
- Primitive data types: The primitive data types include boolean, char, byte, short, int, long, float, and double.
- Non-primitive data types: The non-primitive data types include Classes, Interfaces, and Arrays.
Let’s deeper into these primitive types,
• Integers This group includes byte, short, int, and long, which are for whole-valued signed numbers.
• Floating-point numbers This group includes float and double, which represent numbers with fractional precision.
• Characters This group includes char, which represents symbols in a character set, like letters and numbers.
• Boolean This group includes boolean, which is a special type for representing true/false values.
Let’s have a look at datatype’s default value and default size.
|Data Type||Default Value||Default size|