• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Intger Wrapper class

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,
I am not sure how does the value of Integer which is greater than Byte will get converted into Byte value in this example :
public class Test {

public static void main(String[] args){
Integer i = new Integer(130);
System.out.println(i.byteValue());
}
}
Can anybody explain this ?
Thanks in advance
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Your code
------------------------------

public static void main(String[] args){
Integer i = new Integer(130);
System.out.println(i.byteValue());
}

-------------------------------
Here the value of Integer is greater than a byte than how will it get converted?
Simple yaar it's is just like casting. Here ur data will definately be lost just as in the case of a int to byte conversion and u won't get the result as expected.
Try out this code of urs and u will get it.

Correct me if I am wrong
<marquee> </marquee>
Neeraj thakkar
Java Consultant
<marquee direction=right> </marquee>
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
when u r giving 130 it was giving the byte representation, how this happens is
the range of byte is -128 to 127. remember the positive values started with zero so total positive values is 128 the balance left in 130 is 2, this get subracted in -128, which gives -126. the loop goes like this for any big number.
hope you got.
 
Popeye has his spinach. I have this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic