The value 123 is a literal. Since it’s a normal base-10 value, we might say it is a decimal literal.
We use binary literals with different type of datatypes like byte, short and int to illustrate its use. We also use addition operation to add two binary literals.
Here is the source code of the Java Program to Illustrate Use of Binary Literals. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Binary_Literal
public static void main(String args)
byte aB = 0b00100001;
short aS = 0b10100010100;
int a1 = 0b10110;
int a2 = 0b101;
int a3 = 0b1011;
$ javac Binary_Literal.java $ java Binary_Literal Byte value:33 Short value:1300 Integer value:22 Result:16
Sanfoundry Global Education & Learning Series – 1000 Java Programs.