Results 1 to 4 of 4

Thread: Wrapper class

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Answers
    20

    Wrapper class

    What is mean by Wrapper class?
    What is it use...?


  2. #2
    Junior Member
    Join Date
    Nov 2006
    Answers
    25

    Re: Wrapper class

    Hi,

    The built-in object type for the java primitive type is called as the wrapper class.

    It will be used when the primitive type is needed as a object type for some purpose.
    eg:
    int count=9;
    if the count variable is needed as an object type then u can use the built in object type for int ie. Integer

    Integer count = new Integer(9);

    Hope this is useful.

    Regards,
    Elango


  3. #3
    Contributing Member
    Join Date
    Sep 2006
    Answers
    42

    Re: Wrapper class

    For all the primitive data types we have their corresponding objects - Eg: for int we have Integer and so on. These are known as wrapper classes.

    Prior to Java 5, there were methods that accepted only objects as their arguments, I think these wrapper classes would be used there.
    The only other use I have found is in the reflection API, which relies completely on objects. I dunno if there is any other place where they can be used and not the primitives.

    Regards,
    Sahil


    --Smile, It makes people wonder what you are thinking!!!


  4. #4
    Junior Member
    Join Date
    Sep 2007
    Answers
    7

    Thumbs up Re: Wrapper class

    Hi,
    First of all you should know that Java's primitive datatypes are not Objects.
    But in actual practice there will be situations where you will have to pass this primitive values to some functions that accepts only Objects. So there should be some mechanism to represent the primitive values as Objects.

    Here comes the need of wrapper classes. These are builtin classes provided by java, to allow you to represent a premitives as objects. Java provides wrapper classes for all primitive datatypes.

    int ----> Integer
    char ----> Character
    float ----> Float
    double ---->Double, etc.

    eg
    int a = 10
    Integer i = new Integer(a);
    now you can pass this to any functions accepting objects. And also you can use many builtin fuctions provided by java.

    Wrapper classes provide so many good and useful functions like parseXxx(),
    xxxValue() etc. where xxx stands for corresponding primitive datatypes. These functions will help you to convert from String to primitive and from object to primitive.
    ptmidhun@gmail.com
    But, Now these things are more easy, From J2SE5.0 onwards java also supports autoboxing and autounboxing. A feature copied from C#.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact