This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why Wrapper Classes Are Needed in Java  RSS feed

 
sirisha makkapati
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Wrapper classes Are Used To Acess Primitive Types as Objects,But Why We Would like to AcessPrimitive types to be accessed as Objects,Any one Can Tell me The Reason
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One reason is that you can't store primitive types in any of the Collection classes.
 
Crace Selvage
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wrapper classes are a way of manipulating the values stored in a primitive data type, and then treating those values as if they were an object. All of the Wrapper classes have methods that interact with each particular primitive data type.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sirisha makkapati:
Hi,
Wrapper classes Are Used To Acess Primitive Types as Objects,But Why We Would like to AcessPrimitive types to be accessed as Objects,Any one Can Tell me The Reason

I think, correctly, your question is better addressed by looking at earlier work in computer science, but the answer to your question is difficult to put into words while staying entirely within the Java nomenclature.

Originally, a value stored in memory would have to be read into a working area of the processor. Then, as compiler science kept up with more powerfull machines, it became simpler to use a record of where the value was stored rather than the value it's self. Then, something called the structure - which is remakably close to a class in Java - became used to keep several values in one ... object ... get it ?

A structure was used so often to keep all data in one place that it was boosted in capabilities and renamed the class, because all data could be classified into ojects which lend themselves to thinking.

They way compilers were written and the complexity of keeping up with everything just lead to keeping everyting in objects to make matters simple.
[ January 07, 2007: Message edited by: Nicholas Jordan ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!