Real that variables of primitive types can hold it does not does Indigos or characters not just look 2
at the second variety of variables which can hold or object references 3
district. 4
Create a student object. 5
And we saw this exact statement when introducing classes and objects. 6
Here s is a variable and it's an object reference and not an object that is it holds bits that reference 7
a student object in memory. 8
Let's see how this works. 9
This statement basically has three parts in it. 10
And each of them informs JVM to do something. 11
And let's see what those three parts are. 12
Here's a fusspot a neat dense GBM to look at space and memory for that reference variable. 13
And here is the second part that dolt's GBM took a look at space for a new student object in the memory 14
. 15
OK so space has been a look at it for reference mailable and space has been and look at it for ex-student 16
object in the memory. 17
No we need to send a memory address of the student object to that reference variable. 18
And for that we have the third part that is an assignment operator assigns a memory address of the student 19
object to the variable s. 20
So we just mentioned about objects getting stored in memory but that gets stored in especially the memory 21
that is assigned to JVM. 22
So in JVM starts up it gets a chunk of memory from the underlying operating system in order to run its 23
programs and run it off this memory is referred to us heap and all objects are stored on the heap. 24
OK so all Java objects get stored on the heap. 25
And this diagram shows the heap with all the objects and in our particular example the variable as it 26
references one student object on the heap JVM and a non-starter covers heap concept in detail. 27
But for now just know that we have a heap and that objects are stored on the heap. 28
We looked at big that of all primitives no more object references build dip this GBM specific that is 29
big of an object reference on one JVM maybe smaller or larger than that of an object reference on another 30
JVM holloed on a given JVM. 31
All of the references will have the same Babet regardless of the objects they reference different value 32
for an object reference is null non-employees the object reference is not pointing to anything. 33
So in this statement S.M. be assigned a different null until it is explicitly initialized. 34
Now if you use a dot operator on a null reference that will lead to an exception called null pointer 35
exception exceptions would be covered later in a separate chapter called exceptions. 36
And that's about it. 37
That's the I know for discussion on object references. 38
Thank you