In Java SE 7, new binary notation is added, and you can use decimal notation to represent values in binary form as easily as possible.
For example:
A 8-bit byte value:
byte abyte = 0b100001;
A 16-bit short value: short
ashort = 0b1010010100101;
A 32-bit int value:
int anInt1 = 0b101000010100010110100101000101;
A 64-bit Long value (note suffix "l" at the end)
long along = 0b101000010l;
Binary literals begin with 0b or 0 B, case-insensitive
int anInt2 = 0b101;
In Java SE 7, the following underscore is also supported as a numeric representation of a delimiter join:
decimal form
int anInt1 = 123_45_6;
Binary, 16 and other forms also support
int anInt2 = 0b10_0110_100;
int anInt3 = 0xff_ec_de_5e;
The decimal form also supports
float pi = 3.14_15f;
Double adouble = 3.14_15;
Multiple underline connected
int chain = 5______2____0;
However, the following forms of writing are incorrect:
Underline cannot be placed at the last
int x = 52_; Error
/underline cannot be near decimal point (not near decimal point)
float pi1 = 3_.1415f; Error
Float pi2 = 3._1415f; Error
//underline cannot be placed tightly in front of suffix "l" or "f"
float pi3 = 3.1415_f; Error
Long aLong1 = 999_99_9999_l;//error
//underscore cannot be placed between the prefix characters representing the system
int x5 = 0_x52; Error
Also, note the following, which puts the underscore on the front:
int _52 = 120; In Java, a variable name cannot begin with a number, but it can begin with an underscore
int x = _52; So, the _52 here is not a literal form of a number, but rather a variable identifier (variable name)