Skip to content

Commit 52040c2

Browse files
author
Ram swaroop
committed
added content
1 parent 8046bcf commit 52040c2

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

_posts/2015-05-14-variables-and-literals.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ figure below:
4343

4444
### Literal Values for All Primitive Types
4545

46-
A __primitive literal__ is merely a source code representation of the primitive data types, in other words, an integer,
47-
floating-point number, boolean, or character etc. that you type in while writing code. The following are examples of
48-
primitive literals:
46+
__Literals__ are nothing but values that a particular data type can hold. A __primitive literal__ is merely a source
47+
code representation of the primitive data types, in other words, an integer, floating-point number, boolean, or
48+
character etc. that you type in while writing code. The following are examples of primitive literals:
4949

5050
{% highlight java %}
5151
127 // byte literal
@@ -58,7 +58,7 @@ primitive literals:
5858
false // boolean literal
5959
{% endhighlight %}
6060

61-
####Integer Literals
61+
#### Integer Literals
6262

6363
There are four ways to represent integer numbers in the Java language: decimal (base 10), octal (base 8),
6464
hexadecimal (base 16), and from Java 7, binary (base 2).
@@ -84,6 +84,19 @@ doubles and floats, you CANNOT add an underscore character directly next to the
8484

8585

8686

87+
**Binary Literals**
88+
89+
From Java 7, you can initialize variables holding binary literals. But they must start with either 0B or 0b, as shown
90+
below:
91+
92+
{% highlight java %}
93+
int b1 = 0B101010; // set b1 to binary 101010 (decimal 42)
94+
int b2 = 0b00011; // set b2 to binary 11 (decimal 3)
95+
{% endhighlight %}
96+
97+
98+
99+
87100

88101

89102

0 commit comments

Comments
 (0)