Results 1 to 7 of 7

Thread: double object's method comparison

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Resolved double object's method comparison

    Hello

    can you guys tell me if there is a difference between these two sections of code

    Code:
    x = Double.parseDouble( xChars );
    Code:
    x   = ( Double.valueOf( xChars ) ).doubleValue();
    Last edited by vb_student; Jun 24th, 2006 at 10:33 AM.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: double object's method comparison

    About "Double.valueOf":

    Returns a Double object holding the double value represented by the argument string s.

    If s is null, then a NullPointerException is thrown.

    Leading and trailing whitespace characters in s are ignored. The rest of s should constitute a FloatValue as described by the lexical rule:

    FloatValue:
    Signopt NaN
    Signopt Infinity
    Signopt FloatingPointLiteral

    where Sign and FloatingPointLiteral are as defined in §3.10.2 of the Java Language Specification. If s does not have the form of a FloatValue, then a NumberFormatException is thrown. Otherwise, s is regarded as representing an exact decimal value in the usual "computerized scientific notation"; this exact decimal value is then conceptually converted to an "infinitely precise" binary value that is then rounded to type double by the usual round-to-nearest rule of IEEE 754 floating-point arithmetic, which includes preserving the sign of a zero value. Finally, a Double object representing this double value is returned.

    To interpret localized string representations of a floating-point value, use subclasses of NumberFormat.



    While "Double.parseDouble":

    Returns a new double initialized to the value represented by the specified String, as performed by the valueOf method of class Double
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: double object's method comparison

    thanks for the reply

    i geuss the two sections of code are equivalent?
    i guess this is not possible

    Code:
    double xChars
    xChars.doubleValue()
    i guess xChars is not an object, but a value in this code?

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: double object's method comparison

    Correct, in java there is a difference between primitive data types (int, char, boolean, short...) and class objects (Integer, Character, Boolean, Short...) Not like in Visual Languages
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: double object's method comparison

    & double is a primitie data type.

    would Integer be an object holiding an integer value?

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: double object's method comparison

    Yes, exactly, it holds int value with some methods to use
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: double object's method comparison

    thanks

Posting Permissions

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



Click Here to Expand Forum to Full Width