what happens if I do (sorry for posting in this reply: i just want to get the answer) h = "hello"; where does the pointer go? will "hello" of h be different object from "hello" of g?
Hey@@AkashdeepSingh-qq5fw You're talking about the line of code at 3:58 Strings behave differently in this circumstance than most other objects, so there would NOT be a separate object for the h and g variables. Both pointers would point at the same object in a "String pool." For more information on how this works with the String class, check out this video: ruclips.net/video/Y-Q9m11pFVc/видео.html
@@BillBarnum Oh ok thank you very much! By the way i have one more question on this video you linked: ruclips.net/video/Y-Q9m11pFVc3/видео.html the question is posted there.
Hi I love your videos and Thank you for making them short, simple and visual. Also could you recommend any Java books that teaches you more about "Primitive and Reference Types in Memory" in detail.
There are some good videos on RUclips that talk more about memory in Java. Also, try looking for something on Udemy about Java and memory. You can usually find a coupon for Udemy courses that brings them down to about $15
What if you make a String with the same value for example : String a = "hallo"; String b = "hallo";. Does it point to the same value on the heap or does it make a new one?
Strings are a little weird, so in that case, they would point to the same object. For more information on that, check out my Strings video: ruclips.net/video/Y-Q9m11pFVc/видео.html
So when you set h =g, if you change the value of g to "goodbye", will h change to "goodbye as well? Since they were initially both pointing at "hello", doesn't that mean when you change g to "goodbye", h should also change to "goodbye"?
My question is concerning how the stack works in this design. Since a stack uses FIFO or LIFO does that mean 'd' and 'c' have to be popped(removed) from the stack in order to access 'b'?
Nice job ! explaining reference variables and primative or value types. But I like to add something you might not have covered. Only one memory location is created for primative variables which is on the stack. Primative types have their actual data stored at the same place where the variable is stored. Also primative types have no methods. Also all primatives have a known fixed size. For instance a int variable is 4 bytes. A double is 8 bytes. Reference types do not contain the actual data. They only show where the actual data(object) is stored in memory(heap). Also two memory locations are created when creating objects. One memory location for the object, which is the heap . And one memory location for the object reference variable. Also objects are anonymous, they do not have a name. For instance, the following code: String person ="Lisa"; An String object is created with a text value "Lisa". Also this object has no name. This String object is stored in a special area in the heap called the constant string pool. Objects contain the actual data, in this example it's "Lisa" . Now the reference variable, does have a name , which is " person" . This variable holds the address of the String object with the value of "Lisa". This reference variable is stored in the stack. Reference variabes do not contain the actual data. They only show where to find that data somewhere in memory(heap).
Hi, My question is concerning how the stack works in this design. Since a stack uses FIFO or LIFO does that mean 'd' and 'c' have to be popped(removed) from the stack in order to access 'b'?
QUESTION 1 what happens if i do c = new int[5]; instead of d = new int[5]; ? Will c be overwritten and also affects d? Or: - c will move to a new pointer memory location and write the data value array object there, leaving d unaffected -d will move to a new pointer memory location copying the data value array. Then the data value at location c will be overwritten - something different happens? QUESTION 2 also suppose we just had this code: c = {0,1}; c = new int[2]; will in this case the data value of c be overwritten? Or c will move to a new pointer memory location and then write the data value array object over there, leaving the data value {0,1} non-deleted? Or something different happens?
1. For question 1, you are talking about 2:58 . c will point at a brand new array. d will still point at the unchanged old array. 2. For question 2, you couldn't do c = {0, 1}. You can only hardcode an array in that particular manner if you are also declaring the variable on the same line.
But the arrays store primitive type datas in the heap right?! So the statement „all data for primitive typ variables is stored on the stack“ is not quite right, right? 🤔
So you are saying that primitives as instance variables and primitive as local variables are both stored in the stack? Isnt it important where that primitive defined? Inside a method or as an object field?
The code demonstrated in the video is local variables. If we declared a primitive instance variable, it would appear as part of its object on the heap.
Hey Akashdeep, You're talking about the line of code at 3:58 Strings behave differently in this circumstance than most other objects, so there would NOT be a separate object for the h and g variables. Both pointers would point at the same object in a "String pool." For more information on how this works with the String class, check out this video: ruclips.net/video/Y-Q9m11pFVc/видео.html
@@BillBarnum Oh ok thank you very much! By the way i have one more question on this video you linked: ruclips.net/video/Y-Q9m11pFVc3/видео.html the question is posted there.
In Java, the programmer doesn’t have access to the memory address. The Java Virtual Machine (JVM) will put it where it wants and move it around as it sees fit. Java programmers may know what a pointer is pointing at, but they won’t know where in memory it is pointing.
📌 Subscribe For The Latest Videos: bit.ly/36H70sy 📌
.
💻 All Java Tutorials: bit.ly/JavaTutorialsRUclips 💻
.
🤖 Learn Java In 3 Hours: bit.ly/JavaIn3Hours 🤖
what happens if I do (sorry for posting in this reply: i just want to get the answer)
h = "hello";
where does the pointer go? will "hello" of h be different object from "hello" of g?
Hey@@AkashdeepSingh-qq5fw
You're talking about the line of code at 3:58
Strings behave differently in this circumstance than most other objects, so there would NOT be a separate object for the h and g variables. Both pointers would point at the same object in a "String pool."
For more information on how this works with the String class, check out this video: ruclips.net/video/Y-Q9m11pFVc/видео.html
@@BillBarnum Oh ok thank you very much!
By the way i have one more question on this video you linked: ruclips.net/video/Y-Q9m11pFVc3/видео.html
the question is posted there.
This is unexpected. I have wasted hours on videos on this topic and you explained in just 5 minutes and so easily. I'm very thankful to you.
same here
same lol
When the teacher explains this you're like: Dude wtf are you even talking about!?
And here: Ah... that's not so hard
This is as good as a tutorial gets. Short, to the point, and clearly explained with visuals. Thank you, Bill!
Literally the single most helpful vid on the internet on the topic. Thanks!
Never went through a tutorial so quick , thank you for making it easy and smooth
Thanks for the comment! I'm glad the videos were useful.
this is the best video I have found on primitives and reference types apprehension.
This channel should have at least 500K followers! It is not fair. You are such an amazing teacher and I appreciate it
Our teacher failed to explain this to us in over an hour. Thank you. That was an explanation the way it should be!
Thanks for the feedback, Philipp.
I'm glad you liked the video!
I searched so long to find a good video that could explain reference types and how they're actually used. This video helped me a lot!!!
I'm glad it was helpful, sciencerules!
I'm self studying for the AP CS A Exam this May and your playlist is so helpful! Much easier to follow along than textbooks. Thank you!!
Harpita, I'm glad you find the videos useful. Thanks for sharing.
Clear it with simplicity! The best tutorial ever!
thanks so much for making it visual, i understand it so much better
A Fool Can Also Understand Concept Like This.
If There Is Teacher Like You.
Thank You So Much
Thanks for the feedback, NoFiX!
I'm glad you found the video useful.
Now, my doubts get cleared. Thank you so much for clearing doubts in such a short video.
Thanks for the comment, Pratik!
Thank you bill, you saved me.
The terms sound so complex yet it's so easy to explain with examples.
This is an AWESOME explanation, thank you.
Wow, I have been wrestling with this topic in one form or another for a while and this immediately cleared it up, thank you.
Thanks for the comment, Jacob.
I'm glad you found the video useful.
Hi Bill, I am really thankful to you.
Explained so quickly and to the point! thanks
Great and easy to understand explanation
That was such a well made video, thanks a lot and keep doing the great work.
Thanks for watching and commenting,
Sushant!
Best explanation on the internet !❤
Best video on the matter.
Perfect explanation. Thank you!
Brilliant analogy
Thank you! Starting to understand Java now
perfect explaining. thank you
Thank you for making it super clear to get into my head.
clear explanation thank you
Great tutorial thank you
Hi I love your videos and Thank you for making them short, simple and visual. Also could you recommend any Java books that teaches you more about "Primitive and Reference Types in Memory" in detail.
There are some good videos on RUclips that talk more about memory in Java.
Also, try looking for something on Udemy about Java and memory. You can usually find a coupon for Udemy courses that brings them down to about $15
Thank you Sir! Very well explained and makes perfect sense. Regards
Awesome explaining
This is so helpful! You're a very good teacher, thank you so much!
Thank You very much ,
This cleared all my doubts 🙏
Thanks for the comment and watching the video, Nikhil!
Thank you sir ! You explained it very easily.
I'm glad it was helpful. Thank you for the feedback!
Bravo 👏 Short but very informative
I'm glad you found it useful. Thanks for commenting.
Life saver coz what??!! this made perfect sense I struggled with this.
Excellent bair, short and simple thankyou
Thanks for the feedback Anil. I'm glad you liked the video.
What if you make a String with the same value for example : String a = "hallo"; String b = "hallo";. Does it point to the same value on the heap or does it make a new one?
Strings are a little weird, so in that case, they would point to the same object.
For more information on that, check out my Strings video:
ruclips.net/video/Y-Q9m11pFVc/видео.html
@@BillBarnum damn....just when you think you are getting the hang of it....Thank you
thank u so much for this!
Clear explanation! Thank you man
Thanks a lot sir I've watched a lot of videos and I just understand it on your way there's no enough words to say how much I grateful 🥰
Thanks for the comment!
Hi Bill! Could you please create a playlist to include all your amazing java lessons?
Here you go:
Java For Beginners
ruclips.net/p/PLmpmyPywZ443dRtMleUPoNp2OyiNE45O6
you are good
teacher
very nice explanation
Very well explained.
So when you set h =g, if you change the value of g to "goodbye", will h change to "goodbye as well? Since they were initially both pointing at "hello", doesn't that mean when you change g to "goodbye", h should also change to "goodbye"?
Bill is simply the best
wht editing software do u use
I use the paid version of Screencast-O-Matic
Thank you so much Mr Bill Barnum =)
My question is concerning how the stack works in this design. Since a stack uses FIFO or LIFO does that mean 'd' and 'c' have to be popped(removed) from the stack in order to access 'b'?
thank you so much !
I'm glad you found the video useful, Siddharth.
You're one amazing man
Thanks for the feedback, Sungho!
Just gotta say thanks for your videos
I appreciate that
great job well don!
YES I LIKE THIS
Simple and nice
THIS IS PERCEFT BILL!!!
Nice job ! explaining reference variables and primative or value types.
But I like to add something you might not have covered.
Only one memory location is created for primative variables which is on the stack.
Primative types have their actual data stored at the same place where the variable is stored.
Also primative types have no methods.
Also all primatives have a known fixed size. For instance a int variable is 4 bytes. A double is 8 bytes.
Reference types do not contain the actual data. They only show where the actual data(object) is stored in memory(heap).
Also two memory locations are created when creating objects. One memory location for the object, which is the heap . And one memory location for the object reference variable.
Also objects are anonymous, they do not have a name.
For instance, the following code:
String person ="Lisa";
An String object is created with a text value "Lisa". Also this object has no name. This String object is stored in a special area in the heap called the constant string pool. Objects contain the actual data, in this example it's "Lisa" .
Now the reference variable, does have a name , which is
" person" . This variable holds the address of the
String object with the value of "Lisa".
This reference variable is stored in the stack. Reference variabes do not contain the actual data. They only show where to find that data somewhere in memory(heap).
Hi, My question is concerning how the stack works in this design. Since a stack uses FIFO or LIFO does that mean 'd' and 'c' have to be popped(removed) from the stack in order to access 'b'?
Dude this video helped me
Thanks for the feedback! I'm glad that you found it useful.
THANKS A LOT!
Perfectly
QUESTION 1
what happens if i do
c = new int[5];
instead of
d = new int[5];
?
Will c be overwritten and also affects d? Or:
- c will move to a new pointer memory location and write the data value array object there, leaving d unaffected
-d will move to a new pointer memory location copying the data value array. Then the data value at location c will be overwritten
- something different happens?
QUESTION 2
also suppose we just had this code:
c = {0,1};
c = new int[2];
will in this case the data value of c be overwritten? Or c will move to a new pointer memory location and then write the data value array object over there, leaving the data value {0,1} non-deleted? Or something different happens?
1. For question 1, you are talking about 2:58 . c will point at a brand new array. d will still point at the unchanged old array.
2. For question 2, you couldn't do c = {0, 1}. You can only hardcode an array in that particular manner if you are also declaring the variable on the same line.
But the arrays store primitive type datas in the heap right?! So the statement „all data for primitive typ variables is stored on the stack“ is not quite right, right? 🤔
So you are saying that primitives as instance variables and primitive as local variables are both stored in the stack? Isnt it important where that primitive defined? Inside a method or as an object field?
The code demonstrated in the video is local variables.
If we declared a primitive instance variable, it would appear as part of its object on the heap.
@@BillBarnum yes exactly, i just wanted to emphasize it...
@@serkansunel
Thanks for pointing that out.
Thanks
thanks a lot 👍 👍
Thanks for watching and commenting, Harshil.
Good stuff.
Thanks!
Thank you!
You're welcome!
what happens if I do
h = "hello";
where does the pointer go? will "hello" of h be different object from "hello" of g?
Hey Akashdeep,
You're talking about the line of code at 3:58
Strings behave differently in this circumstance than most other objects, so there would NOT be a separate object for the h and g variables. Both pointers would point at the same object in a "String pool."
For more information on how this works with the String class, check out this video: ruclips.net/video/Y-Q9m11pFVc/видео.html
@@BillBarnum Oh ok thank you very much!
By the way i have one more question on this video you linked: ruclips.net/video/Y-Q9m11pFVc3/видео.html
the question is posted there.
thanks bro
At 4:39 if we make String g point to "goodbye" then what will happen to "hello" ?
Shahriar Mim,
If an object on the heap doesn’t have anything pointing to it, Java’s garbage collection will automatically delete it to save memory.
Thanks a lot for clearing my confusion :)
nice thx
why not saying an address as oppose as a pointer
In Java, the programmer doesn’t have access to the memory address. The Java Virtual Machine (JVM) will put it where it wants and move it around as it sees fit.
Java programmers may know what a pointer is pointing at, but they won’t know where in memory it is pointing.
wow
yours 2 video has 2 concepts,see .array type ..int[ ] c,here and other video
it will be easier to understand if you talk a bit more about stack:)
trop fort mon gars !!!! good job; alles klar
Cool video! I just wonder who are the ones who disliked the video? Your ex..?))
Thanksgiving
life saver 🫂🫂
Thank you so much!
You're welcome!