定义
The fixed values are called as Literal. Literal is a value that is used by the variables.
Integer Literals
A literal of integer type is know as the integer literal.
它可以是八进制、十进制、二进制或十六进制常量。 十进制数字不需要前缀。 后缀也可以与整数文字一起使用,例如 U 或 u 用于无符号数,而 l 或 L 用于长数。 默认情况下,每个文字都是 int 类型。 对于 Integral 数据类型(byte、short、int、long)
07778 // invalid: 8 is not an octal digit
045uu // invalid: suffix (u) is repeated
0b105 // invalid: 5 is not a binary digit
0b101 // valid binary literal
456 // valid decimal literal
02453 // valid octal literal
0x65d // valid hexadecimal literal
12356 // valid int literal
304U // valid unsigned int literal
3078L // valid long literal
965UL // valid unsigned long literal
Floating-point Literals
Double d = 3.14145 // Valid
Double d = 312569E-5 // Valid
Double d = 125E // invalid: Incomplete exponent
Double d = 784f // valid
Double d = .e45 // invalid: missing integer or fraction
Character Literals
char ch = 'a';
char ch = '\u0061';// Here /u0061 represent a.
char ch = '\n';
String Literals
String s1 = "Hello Geeks!";
String s2 = @"Hello Geeks!";
Null Literals
Boolean Literals
bool b = true;
bool c = false;