Java 7: Binary literal type

From Java 7 Binary type also joins the category of literal with byte, short, int and long. Which means a binary value can be assigned  by using 0b or 0B  prefix to a  primitive type.

What is a Literal :  A literal is source code representation of source code. Which can be directly assigned to any primitive type.

Try following in your code with JDK1.7+

Why Binary Literals:

  • No need to translate binary value to integer to use them.
  • Benefit to programs where bit per bit operation is required.

Other literal type are following

One more feature introduced related to primitive type.

Underscore in integer type: To improve readability of code in integer delimiters.


Leave a Reply

Your email address will not be published. Required fields are marked *