Whenever we create variables, we always mention the type of data we’ll be putting into the variable using data type.
int a = 4;
There are 2 types of data types in Java.
1. Primitive data type
2. Non Primitive data type
Primitive data types
Primitive data types are also known as fundamental data types. Here we are going to cover some of the most important data types.
Boolean Data Type
Boolean can only store ither true or false values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean a = true; | |
System.out.println(a); |
OUTPUT:
true
Integer Data Type
Integers stores whole numbers. Whole numbers are non decimal numbers like -2, -1 , 0 ,1 ,2 , etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int a = 3; | |
System.out.println(a); |
OUTPUT:
3
Double Data Type
Double stores decimal numbers like 3.2 , 1,2 ,etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double a = 3.4; | |
System.out.println(a); |
OUTPUT:
3.4
Char Data Type
Char is ued to store a single character/letter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
char a = 'a'; | |
System.out.println(a); |
OUTPUT:
a
Non Primitive data types
Now, we’ll be covering non primitive data types. Major examples for data types include Arrays, ArrayLists, Interfaces, etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String a = "Aniket"; | |
System.out.println(a); |
OUTPUT:
Aniket