public class Main {
public static void main(String[] args) {
// NOT STATIC
//xxxValue()
Byte aByte = 125;
byte b = aByte.byteValue();
short s = aByte.shortValue();
int i = aByte.intValue();
long l = aByte.longValue();
float f = aByte.floatValue();
double d = aByte.doubleValue();
Integer aInteger = 6753;
i = aInteger.intValue();
l = aInteger.longValue();
f = aInteger.floatValue();
d = aInteger.doubleValue();
Boolean aBoolean = true;
boolean bo = aBoolean.booleanValue();
// Static
// parseXxx
b = Byte.parseByte("127"); // Exception in thread "main" java.lang.NumberFormatException: Value out of range. Value:"256" Radix:10
// 8 bits signed -128..127 !!!
i = Integer.parseInt("123456");
bo = Boolean.parseBoolean("TRUE");
//static
// valueOf()
Byte anotherByte = Byte.valueOf("-128");
anotherByte = Byte.valueOf(b); // NO BYTE LITTERALS !!!
Integer anotherInteger = Integer.valueOf("123456");
anotherInteger = Integer.valueOf(123456);
}
}
Hello. First of all thanks for your notes.
ReplyDeleteb = Byte.parseByte("127"); // Exception in thread "main" java.lang.NumberFormatException: Value out of range. Value:"256" Radix:10
127 is acceptable. But based on Exception it should be Byte.parseByte("256") in code.