// Exemples catagorie lexical "integer literal" Java7 ou plus public class JavaConst { public static void main(String[] args) { long carteBleu = 1234_5678_9012_3456L; // decimal long long numSecu = 1_62_09_63_075_523L; // decimal long long hexaBytes = 0x0F_EC_DE_5E; // hexadecimal long hexaWords = 0xCAFE_BABE; // hexadecimal (valid JVM files identification) long hexaWord2 = 0xB16_B00B5; // hexadecimal porno! long hexaWord3 = 0xC0DE_BAB1BEL; // hexadecimal long (5 octet) byte byteBinary = 0B0010_0101; // binaire long longBinary = 0b11010010_01101001_10010100_10010010; // binaire long long maxlong = 0X7fff_ffff_ffff_ffffL; // hexadecimal long long maxlong2 = 07_77777_77777_77777_77777L; // octal long long moins1 = 0xffff_ffff_ffff_ffffL; // hexadecimal long negatif =-1 int moins1bis = 03_77777_77777; // octal 4 octets =-1 int moinsDix = -10; // "10" constante decimal, "-" operateur au niveau syntaxique int plusdix = +10; // "10" constante decimal, "+" operateur au niveau syntaxique int zero = 0; // 0 decimal long zerobis = 0l; // 0 decimal long ! int zeroter = 00; // 0 octal int zerooooo = 0__________0; // 0 octal (un peu long) int dix = 1__________0; // 10 decimal int add = 12_3 + 5_4_3; // add= 666 short[] HAPPY_FACE = { // bitmap binaire (short)0b0000011111100000, (short)0b0000100000010000, (short)0b0001000000001000, (short)0b0010000000000100, (short)0b0100000000000010, (short)0b1000011001100001, (short)0b1000011001100001, (short)0b1000000000000001, (short)0b1000000000000001, (short)0b1001000000001001, (short)0b1000100000010001, (short)0b0100011111100010, (short)0b0010000000000100, (short)0b0001000000001000, (short)0b0000100000010000, (short)0b0000011111100000 }; /* Contre Exemples (verifiés avec compilo javac) int x1 = _52; // It is an identifier, not a numeric literal int x2 = 5_2; // OK (decimal literal) int x3 = 52_; // Invalid; cannot put underscores at the end of a literal int x4 = 5_____2; // OK (decimal literal) int x5 = 0_x52; // Invalid; cannot put underscores in the 0x radix prefix int x6 = 0x_52; // Invalid; cannot put underscores at the beginning of a number int x7 = 0x5_2; // OK (hexadecimal literal) int x8 = 0x52_; // Invalid; cannot put underscores at the end of a number int x9 = 0_52; // OK (octal literal). for octal 0 is the beginning of number !! int x10 = 05_2; // OK (octal literal) int x11 = 052_; // Invalid; cannot put underscores at the end of a number int x12 = 08; // Invalid : not decimal, not octal int x13 = 07; // OK octal long x14 = 0x0B16_B00B_BABE_L; // Invalid :cannot put underscores at the end of a number */ } }