Click here to Skip to main content
15,915,324 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why are there Wrapper Classes if we already have Primitive datatypes??
Eg: we can create an integer variable as
int x = 10;
then why would we use Wrapper class as
Integer x = new Integer(10);
Posted

1 solution

Primitive data types are not classes in Java. Therefore they do not come with instance variables and methods. This is good for efficiency, but seems to force us in a non-object oriented direction. To accommodate this, there are wrapper classes.
 
Share this answer
 
Comments
Tamanna9931 23-Jan-13 5:34am    
means primitive datatypes make Java not an object-oriented language??? if yes, then primitive datatypes should not be exist in Java,, then why there are primitive datatypes exist in Java??
techgeek from-india 23-Jan-13 5:43am    
Java is a OOP language and it is not a pure Object Based Programming Language. Many languages are Object Oriented. There are seven qualities to be satisfied for a programming language to be pure Object Oriented. They are:

•Encapsulation/Data Hiding
•Inheritance
•Polymorphism
•Abstraction
•All predefined types are objects
•All operations are performed by sending messages to objects
•All user defined types are objects.
Java is not because it supports Primitive datatype such as int, byte, long... etc, to be used, which are not objects. Contrast with a pure OOP language like Smalltalk, where there are no primitive types, and boolean, int and methods are all objects.

CPallini 23-Jan-13 8:00am    
Performance?
http://stackoverflow.com/questions/4624933/comparing-performance-of-int-and-integer

Side note: OOP is not a panacea.
Tamanna9931 23-Jan-13 5:53am    
Thanx....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900