This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Wrapper Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Wrapper Classes" Watch "Wrapper Classes" New topic

Wrapper Classes

Brett Delia

Joined: Feb 22, 2001
Posts: 20
Some colleages and I were debating why the wrapper class that correspond with the primitive datatypes are immutable. I was hoping to get some feedback from this group as to why they are.

Thank in advance.
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

The reason why I think they are immutable is because of the purpose of these classes. If what I had read was correct, the purpose of these wrapper classes is so that you can store primitive values in Vectors and such. Since they all take Objects, but not primitives, there needed to be a way to put the primitives in them. SO they made the Wrapper classes. I also think they are used for statci methods for converting primitive types around.
I know I use them specifically for these two purposes. I always have to convert between pimitive and String and back and forth all the time.
For EJB's I 100% recommend always using the Wrapper Classes to map to database fields, rather than primitives. It just makes things easier.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
sanjays samadder

Joined: Mar 30, 2001
Posts: 24
if you have done any bit of awt class you will notice that textcomponets take in dta in string format .the question is how will you convert them to primitive so as to perform calculations on them .in order to make them as primitive data type wrapper classes are used.that is one practical use i have found.
I agree. Here's the link:
subject: Wrapper Classes
jQuery in Action, 3rd edition