When I started learning the Java basics. One of the first things I came across was data types. it’s very important.
Let me share what I understood so far.
Data Types:
I simple words, Data types nothing but what kind of data we want to store in a variable.
In real time when we shift our home to another home, we might have different types of boxes where we wanted to store our house hold items and name those boxes accordingly(Ex: Toys, Books, Tools), so java want to know what kind box we are using for numbers, letters etc.
Java has two main types of data types:
Primitive Data Types.
Non-Primitive (Reference) Data Types.
In this post I will give the outline Primitive Data Types.
There are 8 Primitive Data Types:
| Data Type | Size | What It Stores | Example |
| --------- | ------- | ------------------------- | --------------------------- |
| byte | 1 byte | Small whole numbers | byte a = 10; |
| short | 2 bytes | Bit bigger numbers | short b = 1000; |
| int | 4 bytes | Most common whole numbers | int age = 25; |
| long | 8 bytes | Huge whole numbers | long stars = 123456789L; |
| float | 4 bytes | Decimal numbers | float price = 12.5f; |
| double | 8 bytes | More accurate decimals | double pi = 3.14159; |
| char | 2 bytes | Single character | char letter = 'A'; |
| boolean | 1 bit | True or False | boolean isJavaFun = true; |
My Personal Suggesion:
First start with int for numbers and double for decimals.
Top comments (0)