Important Java Concept

Data Types in Java

 

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.

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.

int a = 3;
System.out.println(a);

 

OUTPUT:
3

 

Double Data Type

 

Double stores decimal numbers like 3.2 , 1,2 ,etc.

double a = 3.4;
System.out.println(a);

 

OUTPUT:
3.4

 

Char Data Type

 

Char is ued to store a single character/letter

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.

 

String a = "Aniket";
System.out.println(a);

 

OUTPUT:
Aniket

 

 

 

Do you want

Java Tutor?

Aniket Malik

Aniket Malik

ORACLE CERTIFIED JAVA TUTOR

🟢 Oracle Certified Java Expert

🟢 300 + ⭐ ⭐ ⭐ ⭐ ⭐

🟢 B.tech & M.tech in CSE

🟢 6+ Years of Teaching Experience

🟢 Worked as SE in Virtusa and Digidez

Do you want

Java Tutor?