File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes A SIMPLE DOUBT REG WRAPPER CLASSES! Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "A SIMPLE DOUBT REG WRAPPER CLASSES!" Watch "A SIMPLE DOUBT REG WRAPPER CLASSES!" New topic
Author

A SIMPLE DOUBT REG WRAPPER CLASSES!

mara thamizhan
Ranch Hand

Joined: Jul 05, 2006
Posts: 74
HAI ALL,
WHAT IS THE USE OF MAKING A PRIMITIVE DATATYPE VALUE TO BE STORED IN A OBJECT AS WE STORE USING WRAPPER CLASSES!

I READ THAT IT WILL ADD FUNCTIONALITY!

CAN U EXPLAIN HOW IT WILL ADD FUNCTIONALITY & IS THERE ANY DRAWBACKS DUE TO THIS?

BYE FOR NOW!

CHEERS,
SAYEE
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24051
    
  13

HI,

WELCOME TO JAVARANCH!

HERE, LET ME HELP YOU WITH THAT "CAPS LOCK" KEY. SOMETIMES IF YOU BANG IT WITH YOUR FIST, LIKE THis, it comes unstuck. There! That's better!

I'm not quite sure what you're asking. In Java, the primitive types like "int", "char", "double", "boolean" aren't kinds of objects; as a result, you can't treat them like objects. This is unfortunate, because all of the nice collection classes (the Lists, Sets, Maps, etc) only work with objects.

That's where those "wrapper" classes come in. If you wrap up an "int" inside an "Integer" wrapper object, then you can treat the result as any other object. You can store it in a Collection, or do any of the many other things that only work with Objects. When you need to get the primitive back, there are methods like intValue() to get it out again.

Java 5 -- the newest version of Java -- will often do this kind of wrapping and unwrapping for you automatically. It's called "autoboxing".


[Jess in Action][AskingGoodQuestions]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Discussion continued at http://www.coderanch.com/t/404102/java/java/WRAPPER-CLASSES-ADD-FUNCTIONALITY


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: A SIMPLE DOUBT REG WRAPPER CLASSES!
 
Similar Threads
String immutability
centralized/reusable servlet inside portlet
primary key type can't be primitive type. True?
Wrapper Classes
HOW WRAPPER CLASSES ADD FUNCTIONALITY