Non Primitive Data Types
2 min read ·
Non primitive data types are more complex data structures.
They do not store simple values directly.
They store references to objects.
Examples of non primitive types:
- String
- Arrays
- Classes
- Objects
- Wrapper Classes
String
String is used to store text.
Example:
String provides many built in methods.
Arrays
An array stores multiple values of the same type.
Example:
Arrays use index starting from 0.
Classes
A class is a blueprint for creating objects.
Example:
Objects
Objects are instances of classes.
In the previous example:
s is an object of the Student class.Objects store state and behavior.
Wrapper Classes
Wrapper classes convert primitive data types into objects.
Primitive → Wrapper
- int → Integer
- double → Double
- char → Character
- boolean → Boolean
Example:
This is called autoboxing.
Wrapper classes are useful when working with collections like ArrayList.
Type casting and non primitive types are important because they form the base of advanced Java concepts like OOP, collections, and memory management.