This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 18538
    
  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)
 
Consider Paul's rocket mass heater.
 
subject: Byte
 
Similar Threads
Integer class : cast problem
Wrapper class
what is the rule here ?
Please Help!!! Convert byte of array (b[ ] ) to InputStream
Doubt regarding Byte Wrapper Constructor