Differentiate between a wrapper class and a Primitive Type.
Advertisements
प्रश्न
Differentiate between a wrapper class and a Primitive Type.
Advertisements
उत्तर
|
Wrapper Class |
Primitive Type |
|---|---|
|
1. A wrapper class is a predefined class in Java that represents a primitive data type as an object. |
1. A primitive type is a basic built-in data type in Java that is used to store simple values. |
|
2. A wrapper class represents a primitive value within an object and allows it to be treated as an object. |
2. A primitive type stores its actual value directly without creating an object. |
|
3. A wrapper class provides various predefined methods for converting, comparing and manipulating data. |
3. A primitive type does not contain methods for converting or manipulating its values. |
|
4. A wrapper class generally requires more memory because it represents data in the form of an object. |
4. A primitive type generally requires less memory because it stores only the basic data value. |
|
5. A wrapper class can hold a null reference to represent the absence of an object. |
5. A primitive type cannot hold a null value because it stores an actual primitive value. |
|
6. Wrapper classes are useful when working with collections and methods that require objects. |
6. Primitive types are useful for performing basic calculations and storing simple data efficiently. |
|
7. Examples: |
7. Examples: |
