Last Updated:

Underline in numeric literals. Java Chip 7

 

Let's look at the underscores in numeric literals on the example of a simple Java program:

The result of the above program printing variables of various data types using underlining in numeric literals.

 

Tips for using underlines in numeric literals

  • Underlines can only be used between numbers.
  • You cannot put an underline next to a comma, L/F suffix, or prefix. For example, using 3._14 110_L 0x_123 will cause a compilation error.
  • It is allowed to use several underlines between numbers. For example, record 12___3 is valid.
  • You can't put underlines at the end of a literal. So, the entry 123_ will cause a compilation error.
  • If you write an underscore at the beginning of a numeric literal, it is treated as an identifier, not a numeric literal. Here's what it looks like: