Java Non Primitive Data Types
✅ Java Non-Primitive Data Types
In Java, non-primitive data types (also called reference types) are used to store references (memory addresses) to objects rather than actual values.
They are more complex than primitive types and provide methods to perform operations.
Characteristics of Non-Primitive Types
| Feature | Description |
|---|---|
| Memory | Stored in heap memory |
| Default Value | null |
| Methods | Have built-in methods (unlike primitives) |
| Examples | String, Arrays, Classes, Objects, Interfaces |
Common Non-Primitive Data Types
String – Stores text
Arrays – Stores multiple values in a single variable
Classes & Objects – User-defined types
Interfaces – Blueprint for classes
1️⃣ String Example
Output:
2️⃣ Array Example
Output:
3️⃣ Class & Object Example
Output:
4️⃣ Interface Example (Basic Concept)
Output:
🔹 Key Points
Non-primitive types store references, not actual values.
Default value is
nullif not initialized.Can call methods (like
length(),toUpperCase()) on them.Include Strings, Arrays, Classes, Objects, Interfaces.
