Scrivio Interview library
CodingFoundations6 min read · updated 12 November 2026

What do these literals mean and which are compile errors? 1_000_000, 0x1F, 0b1010, 017, 08, 10L, 1e3, 3.0f, 1_000_, '\u0041'

1_000_000 is one million, 0x1F is hexadecimal 31, 0b1010 is binary 10, and 017 is octal 15 because a leading zero means octal. 10L is a long, 1e3 is the double 1000.0, 3.0f is a float and '\u0041' is the char 'A'. Two of them do not compile: 08, because 8 is not an octal digit, and 1_000_, because an underscore may only appear between digits.

Why this question is asked

Literals look too simple to be worth an interview question, but they hide a few rules that cause real bugs: a leading zero that silently changes a number's base, a missing L that makes a value an int, and underscores that only work in some positions. Interviewers ask this to see whether we read code precisely, character by character, the way the compiler does. In this answer, we will recap what a literal is and how Java decides its type, go through the integer literals in each base, then the suffixes and floating-point forms, the char escape, and finally the two lines that do not compile and why.

1A Quick Recap of Literals and Their Types

A literal is a value written directly in the source code, such as 42, 3.5 or 'x'. The compiler reads it and decides both its value and its type. The type rules are short: a whole number with no suffix is an int, a whole number ending in L (or l, which is best avoided because it looks like 1) is a long, a number with a decimal point or an exponent is a double, and adding f or F makes it a float. A character in single quotes is a char.

For whole numbers, the first characters decide the base, the number system used to read the digits. 0x or 0X means hexadecimal (base 16), 0b or 0B means binary (base 2), and a plain leading 0 means octal (base 8). Anything else is decimal. That last rule about the plain zero is the one that surprises people.

Each literal from the question
LiteralTypeValueWhy
1_000_000int1000000underscores between digits are ignored
0x1Fint31hex: 1 x 16 + 15
0b1010int10binary: 8 + 2
017int15leading 0 means octal: 1 x 8 + 7
08-compile error8 is not an octal digit
10Llong10L suffix
1e3double1000.0exponent makes it floating point
3.0ffloat3.0f suffix
1_000_-compile errorunderscore cannot end a literal
'\u0041'char'A'Unicode escape for code point 65
Two of the ten do not compile.

2Integer Literals in Four Bases

Let us print the valid integer literals to see their values. Java always prints an int in decimal, whatever base we used to write it.

Java
System.out.println(1_000_000); // 1000000
System.out.println(0x1F); // 31 (1 x 16 + 15)
System.out.println(0b1010); // 10 (8 + 0 + 2 + 0)
System.out.println(017); // 15 (1 x 8 + 7)

Notice that the base only changes how we write the number. In memory, 0x1F, 31 and 037 are the same int. Hex is common for bit masks and colours, and binary literals, added in Java 7, make flag constants readable, for example 0b0000_0100 for the third bit.

The octal line deserves attention. 017 looks like seventeen with a harmless padding zero, but Java reads it as base 8, so its value is 15. Nothing warns us. This rule comes from C, and most modern code never uses octal on purpose, so in practice a leading zero is almost always a mistake.

3Suffixes, Exponents and the Char Escape

The next literals are about type rather than base.

Java
long a = 10L; // 10, a long
double b = 1e3; // 1000.0, a double: 1 x 10 to the power 3
float c = 3.0f; // 3.0, a float
float d = 3.0; // compile error: possible lossy conversion from double to float
char e = '\u0041'; // A
System.out.println(1e3); // 1000.0
System.out.println(e); // A
System.out.println((int) e); // 65

The L suffix matters most when the value or a calculation does not fit in an int. 3_000_000_000 without L does not compile (integer number too large), and an expression made only of int literals is computed in int even if we assign it to a long, which is a classic overflow bug.

1e3 is scientific notation: the e means times ten to the power of. Any literal with an exponent or a decimal point is a double unless we add f. That is why float d = 3.0 fails: 3.0 is a double, and Java will not narrow it to float silently.

'\u0041' is a Unicode escape for code point 0x41, which is 65 in decimal, the letter A. But there is a catch: Java processes Unicode escapes before it even splits the source into tokens. So a \u000a escape inside a comment really becomes a line break, which can end the comment early. It is a famous puzzle, and a reason to keep such escapes out of comments.

4Why 08 and 1_000_ Do Not Compile

Now the two broken literals. For 08, the leading zero says octal, and octal digits only go from 0 to 7. So 08 is not a valid number. For 1_000_, the rule for underscores is that they may only appear between two digits. They cannot start a number, end it, or sit next to the decimal point, a suffix or a prefix like 0x.

Java
int o = 08; // compile error (javac 21 reports "';' expected"; the message depends on the compiler)
int u = 1_000_; // compile error: illegal underscore
int v = _1000; // compiles only if a variable named _1000 exists: it is an identifier, not a number
int w = 0x_1F; // compile error: illegal underscore
long x = 10_L; // compile error: illegal underscore
double y = 1_.5; // compile error: illegal underscore
double z = 08.5; // 8.5: leading zeros are allowed in floating-point literals

Notice the last line. A leading zero only means octal for integer literals, so 08.5 is a perfectly good double. And _1000 is not a literal at all: a leading underscore makes it a name, so the compiler looks for a variable with that name.

Underscores exist purely for readability. 1_000_000 and 1000000 produce identical bytecode. They are useful for long constants such as 10_000_000_000L or card-like groupings in tests, and they are worth using whenever a number has more than four or five digits.

5Follow-up questions

Why can a leading zero in a literal cause a production bug in configuration code?

Because the zero silently changes the value instead of failing. If someone writes int retryDelay = 010 or a port like 0800, the code compiles in the first case and means 8, not 10. The same trap appears when parsing configuration text: Integer.decode("010") returns 8, while Integer.parseInt("010") returns 10, so two parts of the system can read the same value differently. Some YAML 1.1 parsers also read unquoted 010 as octal, so check your parser. The fix is to avoid zero padding in numeric configuration, quote values that are really identifiers such as zip codes, and parse with an explicit radix.

Does 1_000_000 cost anything at runtime?

No. The compiler removes the underscores and stores the plain value 1000000 in the class file. They are purely for people reading the source.

What type is 'A' + 1, and what is printed?

Arithmetic on a char promotes it to int, so 'A' + 1 is the int 66 and println shows 66. To get the next letter we need a cast: (char) ('A' + 1) is 'B'.

6Conclusion

In this answer, we saw that a literal's prefix decides its base and its suffix decides its type. 1_000_000 is one million, 0x1F is 31, 0b1010 is 10 and 017 is 15 because a plain leading zero means octal. 10L is a long, 1e3 the double 1000.0, 3.0f a float and '\u0041' the char A. 08 fails because 8 is not an octal digit, and 1_000_ fails because underscores may only sit between digits. The leading zero rule is the one to remember, because it silently changes values in real code.

What to say in the interviewAbout 80 seconds aloud

Open with

1_000_000 is just one million; the underscores are only for readability and are allowed between digits. 0x1F is hexadecimal, so 16 plus 15, which is 31. 0b1010 is binary, which is 10. 017 is the tricky one: a leading zero in an integer literal means octal, so it is 8 plus 7, which is 15, not seventeen.

Then, if they want more

That is also why 08 does not compile, since 8 is not an octal digit. 10L is a long because of the L suffix, 1e3 is scientific notation and gives the double 1000.0, 3.0f is a float, and backslash u 0041 is a Unicode escape for code point 65, so it is the char A.

Finally, 1_000_ does not compile because an underscore cannot end a literal; it also cannot start one, or sit next to the decimal point, the L suffix or the 0x prefix.

Two things I would add: a leading zero only means octal for integers, so 08.5 is a valid double, and the octal rule is a real source of bugs, because a padded value like 010 compiles and silently means 8. So in configuration or constants I avoid zero padding and use underscores for long numbers instead.

About this answer

Last updated
12 November 2026
Versions it names
Java 7
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What do these literals mean and which are compile errors? 1_000_000, 0x1F, 0b1010, 017...": https://scrivio-interview-library.netlify.app/java/types-and-values/d0dd1f0e84/