aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Byte 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 "Byte" Watch "Byte" New topic
Author

Byte

Sireesha Mullapudi
Ranch Hand

Joined: Jun 26, 2006
Posts: 74
Hi,


why the line Byte b=new Byte("10L"); throwing NumberFormatException.

It is possible to cast long to byte.

then why Byte b=new Byte("10"); is not throwing Exception

Thanks,
SCJP1.4
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18843
    
  40

Originally posted by lakshmi amulya:
Hi,

why the line Byte b=new Byte("10L"); throwing NumberFormatException.

It is possible to cast long to byte.

then why Byte b=new Byte("10"); is not throwing Exception

Thanks,
SCJP1.4


You are not casting a long to a byte -- nor casting a int to a byte. You are passing a string to the Byte class to parse to a byte. The "L" character is not supported by the parser called by the Byte class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Byte