Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default problem in wrapper class

    HI all,

    Plz assist me to clear some doubt in wrapper class.

    Actually wrapper class is used to convert primitive data types to object type.
    For Eg:
    Integer a=new Integer(10);
    Now 'a' would be Integer object.
    As far as my knowledge, object cannot go through any arithmetic operation directly .But when i gone through these steps in eclipse ide a++ worked perfectly.How it would be possible.Hope some one will clariffy this doubts,

    All comments regarding this tipic is highly appreciated.

  2. #2
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    There is only one class that can undergo arithmetic operation, and that is the String class. It can only add two Strings together, which is called concatenation , when you add them together. The Inter class just allows for certain operations that PRIMITIVES cannot do:

    Integer a, b;
    assuming they have been assigned values:
    a + b will NOT work

    On the other hand

    int a, b;
    a + b WILL work because int is a primitive

    I suggest that you use the Integer, Double, Float, and so on classes, only when you need some of the methods they provide.

  3. #3
    gulapala is offline Member
    Join Date
    Dec 2007
    Posts
    11
    Rep Power
    0

    Wink

    Hi binoympappachen,

    First let me know which version of Java you are using. Because in jdk1.4 you can;t do arithmetic operation over Integer objects. But from Java 5, because of the concepts of boxing and unboxing, Integer,Double Objects can also do arithemetic operations, as the JVM internally

    1. converts the objects to primitive values
    2. Does the arithmetic operation
    3. Converts the result to an Object datatype.
    Thanks & Regards, G.Rajasekhar

  4. #4
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Eh, i was completely wrong in my previous post... i guess there are downsides to switching over the 5 very late :\.

    Anyways, sorry for a misleading post, dont listen to me :)

  5. #5
    gulapala is offline Member
    Join Date
    Dec 2007
    Posts
    11
    Rep Power
    0

    Default

    I don't think there are any downsides in switching to 5.0. By switching you can also use new feature that are been introduced in Java 5.0
    Thanks & Regards, G.Rajasekhar

Similar Threads

  1. Java Service Wrapper 3.3.0
    By Java Tip in forum Java Software
    Replies: 0
    Last Post: 03-29-2008, 01:04 PM
  2. wrapper classes
    By sireesha in forum New To Java
    Replies: 5
    Last Post: 12-11-2007, 09:45 PM
  3. Replies: 1
    Last Post: 08-07-2007, 03:47 PM
  4. 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
  •