"Exploring Data Types in Java: Primitive and Non-Primitive"

☕ Day 9 of my “Java from Scratch” Series – “Data Types in Java” In Java, we should tell the compiler what type of data we want to store. There are 2 main types of Data Types 👇 🔹 1️⃣ Primitive Data Types These are the basic data types — the foundation of Java. There are 8 primitive data types: 1. byte - 1 byte (1 byte = 8bits) 2. short - 2 bytes 3. int - 4 bytes 4. long - 8 bytes 5. float - 4 bytes 6. double - 8 bytes 7. char - 2 bytes 8. boolean - 1 bit 💡 In Java, everything is a class except these 8 data types. 🔹 2️⃣ Non-Primitive Data Types These are user-defined data types, and they are classes. ✅ Examples: String, Array The size of a String depends on the number of characters in it. Example: String name = "Java"; 👉 Number of characters = 4 👉 Size of each character = 2 bytes ✅ Total = 8 bytes + overhead (20–30 bytes depending on the system) 💡 Key takeaway: ➡️ Primitive data types ❌ are not classes. ➡️ Non-primitive data types ✅ are classes. 👉 Which data type do you use most often in your projects? Let me know in the comments 👇 #Java #Programming #Coding #Learning #SoftwareEngineering #JavaDeveloper #DataTypes #JavaFromScratch #InterviewQuestions #DataTypesInJava #Tech #JavaInterviewTopics #NeverGiveUp

To view or add a comment, sign in

Explore content categories