This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
When we assign a value to say a byte variable as below : byte b = 3; Here we see that the right side literal value should be in the range of the byte i.e. ( -128 to 127 ) , so the assignment is valid and code compiles and runs fine. My doubt : 1. For the character variable assigining a int value should be in the range of (0-65535). Does it work the same way as mentioned above? 2. Is it that beyond the range of the variable to which we are assigning it is considered as an int.? ( I am referring specifically to assigning to byte,short,char variables )
Originally posted by Angela Narain: When we assign a value to say a byte variable as below : byte b = 3; Here we see that the right side literal value should be in the range of the byte i.e. ( -128 to 127 ) , so the assignment is valid and code compiles and runs fine. My doubt : 1. For the character variable assigining a int value should be in the range of (0-65535). Does it work the same way as mentioned above? 2. Is it that beyond the range of the variable to which we are assigning it is considered as an int.? ( I am referring specifically to assigning to byte,short,char variables )
Hi all, Integral literals are treated as ints. When they appear in an assignment, for example, in <code>byte b = 3</code> the '3' is an int but Java applies assignment conversion and because '3' is within the range of a byte, the assignment succeeds. The same is true for <code>char c = 655</code>. See JLS §5.2 ------------------ Jane Griscti Sun Certified Programmer for the Java� 2 Platform
It will not recognize values which are not in this range.
Hi Jane Griscti, As we can see from the example above, I am sure that the code will compile and run when we use char c = 655. [Narrowing conversion involving int literals] But when we are trying to print out the value, why is it not printing any value. It is printing a '?' . what does that mean. Can you please clarify on that. thanks Chandrashekar!
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Hi all, I got the info after reading it from Khalid's book. (pg "Not all Unicode Characters can be represented in other encoding schemes. In that case, the ? character is usually used to denote any such character in the resulting output, during translation from Unicode. thanks Chandra! ------------------ Where there is a Will, there is a Way.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.