Java Data Types: Primitive & Non-Primitive Explained

Day 9- What I Learned In a Day(JAVA) What is a Data Type? A data type in Java defines the type of value a variable can store and how much memory is allocated for it. Types of Data Types in Java: Java data types are divided into two categories: 1️⃣ Primitive Data Types Primitive data types store simple values directly in memory. They are predefined by Java and have fixed size. Java has 8 primitive data types: 1️⃣ byte Size: 1 byte (8 bits) Range: -128 to 127 2️⃣ short Size: 2 bytes (16 bits) Range: -32,768 to 32,767 3️⃣ int Size: 4 bytes (32 bits) Range: -2,147,483,648 to 2,147,483,647 4️⃣ long Size: 8 bytes (64 bits) Range: -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 5️⃣ float Size: 4 bytes (32 bits) Range: Approximately ±3.4 × 10³⁸ 6️⃣ double Size: 8 bytes (64 bits) Range: Approximately ±1.7 × 10³⁰⁸ 7️⃣ char Size: 2 bytes (16 bits) Range: 0 to 65,535 (Unicode characters) 8️⃣ boolean Size: JVM dependent (typically 1 bit logically) Values: true or false Note:The number datatype in increasing order the capacity byte<short<int<long<float<double Non-Primitive Data Types: Non-primitive data types store references (addresses) of objects, not the actual value. They do not have fixed size. Examples: String Arrays Classes Objects Interfaces Note:In java,every class name is considered as a Non-Primitive Datatype. Practiced the primitive datatype declaration: 👇 #Java #JavaProgramming #CoreJava #LearnJava #CodingJourney #DailyLearning

To view or add a comment, sign in

Explore content categories