aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes problem with constructors of Long and Float Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "problem with constructors of Long and Float" Watch "problem with constructors of Long and Float" New topic
Author

problem with constructors of Long and Float

kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87

why doesnt line 1 one causes a runtime exception while line 2 does?
thanks
Muhammad Ijaz Ahmed
Greenhorn

Joined: Feb 01, 2010
Posts: 3
the reason is your are using "L" upper case, it should be lower case so try this
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 446
    
    1

Ijaj
this is not the case
for long and float numbers
L or l and F or f do not matter

SCJP 6 [86%], OCPWCD [84%], OCEJPAD [83%]
If you find any post useful, click the "plus one" sign on the right
Muhammad Ijaz Ahmed
Greenhorn

Joined: Feb 01, 2010
Posts: 3
@Prasad:
Thanks for correction. So does that mean we can't pass string either suffix is l or L. we have to pass numeric string?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18981
    
  40

kevinn lee wrote:
why doesnt line 1 one causes a runtime exception while line 2 does?


The answer to "why" is probably lost in the bowels of history -- ie. I doubt if anyone knows. These are merely two different implementations. The Float implementation seems more robust, can deal with extra whitespaces, and follows the same definition of floating point as the JLS. However, the Long implementation seems to be less robust, and can only take digits -- no white space, no leading zero for octal, no hexidecimal syntax, etc.

Maybe they were done at different times. Maybe they were done by two different developers. Etc. Your guess would probably be as good as mine.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
kevinn lee
Ranch Hand

Joined: Feb 15, 2010
Posts: 87
Henry Wong wrote:
kevinn lee wrote:
why doesnt line 1 one causes a runtime exception while line 2 does?


The answer to "why" is probably lost in the bowels of history -- ie. I doubt if anyone knows. These are merely two different implementations. The Float implementation seems more robust, can deal with extra whitespaces, and follows the same definition of floating point as the JLS. However, the Long implementation seems to be less robust, and can only take digits -- no white space, no leading zero for octal, no hexidecimal syntax, etc.

Maybe they were done at different times. Maybe they were done by two different developers. Etc. Your guess would probably be as good as mine.

Henry

thank you henry

I came across this in a certain mock exam.Are we supposed to know things like this for the exam?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with constructors of Long and Float