Skip to content

Commit 38e7c41

Browse files
author
Ram swaroop
committed
added content
1 parent ba4351b commit 38e7c41

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,19 @@ into code like:
234234
System.out.println("Bill" + " Joy");
235235
{% endhighlight %}
236236

237-
### Literal values for Non-primitives
237+
### Literal values for Non-Primitives
238238

239239
Variables are just bit holders, with a designated type. You can have an `int` holder, a `double` holder, a `long` holder,
240240
and even a `String[]` holder. This holder is assigned a bunch of bits representing the value. For primitives, the bits
241241
represent __a numeric value__ but for non-primitives, these bits represent __a way to get to the object__.
242242

243+
For example, a `byte` with a value of `6` means that the bit pattern in the variable (the `byte` holder) is `00000110`,
244+
representing the 8 bits. But what happens in case of non-primitives, for example, `Button b = new Button();`, what's
245+
inside the `Button` holder `b`? Is it the Button object? No! A variable referring to an object is just a reference
246+
variable. A __reference variable__ bit holder contains __bits representing a way to get to the object__. We don't know
247+
what the format is. The way in which object references are stored is virtual-machine specific (it's a pointer to
248+
something, we just don't know what that something really is). All we can say for sure is that the variable's value is
249+
not the object, but rather a value representing a specific object on the heap. Or `null`. When it is `null`, i.e,
250+
`Button b = null;` you can say that the reference variable `b` is not referring to any object.
251+
243252

0 commit comments

Comments
 (0)