Results 1 to 7 of 7

Thread: Wrapper Class

  1. #1
    haiforhussain is offline Member
    Join Date
    Jun 2008
    Posts
    11
    Rep Power
    0

    Default Wrapper Class

    hi all
    As we have primitive data types,Then what is the need of Wrapper class....
    Kindly clarrify it ...

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Wrapper classes are to wrap primitives in Objects which can be hold in different ways(may be as a Vector) for another use of.

    As an example get an Integer from String.

    Java Code:
    Integer iVal = Integer.valueOf("123");

  3. #3
    haiforhussain is offline Member
    Join Date
    Jun 2008
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by Eranga View Post
    Wrapper classes are to wrap primitives in Objects which can be hold in different ways(may be as a Vector) for another use of.

    As an example get an Integer from String.

    Java Code:
    Integer iVal = Integer.valueOf("123");
    Hi
    Thanks for ur explanation .... What is the use of this over by using normal primitive data types ...

    Eg : int iVal=123;

  4. #4
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    Hello Hussain,

    Consider a situation where u have table and one of its column is of string type but can store int too suppose for password like 1st value in column would be say "sweety" where as the other user would have kept (i.e., 2nd value of same column) say "123".

    And for some reasons u need that integer value. when u get from DB as resultset it will return u as a string but to convert to integer we can use Wrapper class like

    Integer iVal = Integer.valueOf("123");

    in which case u cant use
    int iVal=123;

    So wrapper classes r not used everywhere it is used in some situation only where it is required.
    To finish sooner, take your own time....
    Nivedithaaaa

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Hussain, you got a nice explanation here. As Niveditha says, there is some specific cases we can use wrapper classes. Refer some details more and you can clarify it yourself.

  6. #6
    haiforhussain is offline Member
    Join Date
    Jun 2008
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by Niveditha View Post
    Hello Hussain,

    Consider a situation where u have table and one of its column is of string type but can store int too suppose for password like 1st value in column would be say "sweety" where as the other user would have kept (i.e., 2nd value of same column) say "123".

    And for some reasons u need that integer value. when u get from DB as resultset it will return u as a string but to convert to integer we can use Wrapper class like

    Integer iVal = Integer.valueOf("123");

    in which case u cant use
    int iVal=123;

    So wrapper classes r not used everywhere it is used in some situation only where it is required.

    Hi Niveditha
    Thanx for ur explanation....

  7. #7
    Niveditha's Avatar
    Niveditha is offline Senior Member
    Join Date
    May 2008
    Posts
    307
    Rep Power
    7

    Default

    :) Not a problem..
    We are here to help u out and make ur understanding better and make sure evn we dont forget them.

    You will get many more such examples that u will have to hunt, this was just one among them.
    To finish sooner, take your own time....
    Nivedithaaaa

Similar Threads

  1. Secure FTP Wrapper 3.0.2
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 04-29-2008, 06:05 PM
  2. problem in wrapper class
    By binoympappachen in forum New To Java
    Replies: 4
    Last Post: 12-13-2007, 12:31 PM
  3. wrapper classes
    By sireesha in forum New To Java
    Replies: 5
    Last Post: 12-11-2007, 09:45 PM
  4. Replies: 1
    Last Post: 08-07-2007, 03:47 PM
  5. Exception Failed to Generate Wrapper Class on WebLogic
    By christina in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 02:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •