aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes well a doubt ! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "well a doubt !" Watch "well a doubt !" New topic
Author

well a doubt !

vivek sivakumar
Ranch Hand

Joined: Aug 09, 2001
Posts: 187
well a simple question .
byt b = 200; // this does not compile ofcourse the limit for byte is only till 127 ,
but this works int x = 1234567890; how does this work (except that they say the precision is lost)


SCJP, SCWD <br />A farmer learns more from a bad harvest than a good one.
Alfred Kemety
Ranch Hand

Joined: Aug 14, 2002
Posts: 279
check the output

HTH


Alfred Raouf - Egypt - SCJP 1.4<br />Kemety.equals(Egyptian) // returns true
david eberhardt
Ranch Hand

Joined: Jul 02, 2002
Posts: 158
Originally posted by vivek sivakumar:
well a simple question .
byt b = 200; // this does not compile ofcourse the limit for byte is only till 127 ,
but this works int x = 1234567890; how does this work (except that they say the precision is lost)

1) Alfred is correct.
2) no precision is lost
3) if you were to assign int x = 10234567890;
then compiler error will show up as:
C:\BIN>javac Test.java
Test.java:3: integer number too large: 10234567890
int x = 10234567890;
^
1 error

----------------------------------------------
if you try to assign to a byte b = 200; (which exceeds the max value of 127) you get an error worded slightly different:
C:\BIN>javac Test.java
Test.java:5: integer number too large: 10234567890
int x = 10234567890;
^
Test.java:4: possible loss of precision
found : int
required: byte
byte b = 200;
^
2 errors

both are compiler errors and you will not have made a working class file that is runnable.
In the case of the error of the byte assignment, you are trying to assign "200" which is an literal number which is an int by default!
The compiler is really telling you 2 things with the message "loss of precision" error - first, the number needs an explicit cast to a byte, and second - if you make the cast you will lose precision.
byte b = (byte)200;
System.out.println("byte b = " + b);
output is : byte b = -56
vivek sivakumar
Ranch Hand

Joined: Aug 09, 2001
Posts: 187
Thankx alfred and david for clearing.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: well a doubt !
 
Similar Threads
Multiple Linguistic
classname of inner class
problem in hibernate
religion on the train?
to find the home directory in java