# Literals

Literal is a value of any type given explicitly. So in expression x+10, x is variable and 10 numeric literal.
Sign + or - can be consider as part of the numeric literal or as expression with unary + and -.

exampledescription
23
+23
-23
20L
Decimal integer literal is defined as sequence of digits without a leading 0 (zero).
Integer types represents by
• byte - value must be in range [-128; 127]
• short - value must be in range [-32,768; 32,767]
• int - value must be in the range [-231; 231-1]. This is default type.
• long - value must be in the range [-231; 231-1] and must have suffix L or l. L is preferred because it is easier to distinguish from 1.
Since Java SE 8 you can use unsigned integers.
023
0o23
-023
An octal integer literal is defined as sequence of 0-7 digits with leading 0 or prefix 0o.
0x23
0x23AAbb
-0xabcde
A hexadecimal integer literal is defined as sequence of 0-9 digits and letters a-f or A-F with prefix 0x or 0X.
Case of letters is meaningless, so 0xa = 0xA = 10 and 0xf = 0xF = 15
0b11
-0b0001
A binary integer literal is defined as sequence of 0 and 1 with prefix 0b or 0B.
1.234e2
-.1415926
123.4f
123.4d

There are two types for represent floating-point numbers: double and float. A floating-point literal is of type float if it ends with the letter F or f; otherwise its type is double and it can optionally end with the letter D or d.
Java supports a scientific notation, i.e. literals can use E or e.

true
false
true and false are boolean literals.
{1,2,3}
{ "a", "c", strvar}
A array literal is defined as sequence of values in curly braces.
'A' A character literal is a character in single quotes. May contain any Unicode (UTF-16) character. If your editor and file system allow it, you can use such characters directly in your code. If not, you can use a "Unicode escape": \uxxxx.
"str\u00F1"
"line1\n\rline2"
A string literal is a sequence of characters in double quotes. May contain any Unicode (UTF-16) characters. If your editor and file system allow it, you can use such characters directly in your code. If not, you can use a "Unicode escape": \uxxxx.

## underscore in numerical literals

Any number of underscore _ characters can appear anywhere between digits in a numerical literal.

``````long creditCardNumber = 1234_5678_9012_3456L;
int hexBytes = 0xFF_EC_DE_5E;
float pi =  3.14_15F;``````