No video

Primitive and Reference (Object) Types in Memory (Java Tutorial)

  Рет қаралды 59,793

Bill Barnum

Bill Barnum

Күн бұрын

This Java tutorial for beginners compares memory handling of primitive vs object (reference) type variables. This also shows data types in stack and heap memory.
Aligned to AP Computer Science A.
🔥 Subscribe To Get More Tutorials: bit.ly/36H70sy 🔥
#Java #JavaTutorial #JavaTutorials

Пікірлер: 124
@BillBarnum
@BillBarnum 4 жыл бұрын
📌 Subscribe For The Latest Videos: bit.ly/36H70sy 📌 . 💻 All Java Tutorials: bit.ly/JavaTutorialsKZbin 💻 . 🤖 Learn Java In 3 Hours: bit.ly/JavaIn3Hours 🤖
@AkashdeepSingh-qq5fw
@AkashdeepSingh-qq5fw 3 жыл бұрын
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?
@BillBarnum
@BillBarnum 3 жыл бұрын
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: kzbin.info/www/bejne/j160aqBnZtV5jMU
@AkashdeepSingh-qq5fw
@AkashdeepSingh-qq5fw 3 жыл бұрын
@@BillBarnum Oh ok thank you very much! By the way i have one more question on this video you linked: kzbin.info/www/bejne/j160aqBnZtV5jMVn the question is posted there.
@abkn9977
@abkn9977 4 жыл бұрын
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.
@kartikeysingh6971
@kartikeysingh6971 2 жыл бұрын
same here
@shadowvortex6653
@shadowvortex6653 10 ай бұрын
same lol
@Linkario86
@Linkario86 5 жыл бұрын
When the teacher explains this you're like: Dude wtf are you even talking about!? And here: Ah... that's not so hard
@Ali-mi9up
@Ali-mi9up 5 жыл бұрын
Literally the single most helpful vid on the internet on the topic. Thanks!
@afifkhaja
@afifkhaja 4 жыл бұрын
This is as good as a tutorial gets. Short, to the point, and clearly explained with visuals. Thank you, Bill!
@SuperSandman1995
@SuperSandman1995 4 жыл бұрын
this is the best video I have found on primitives and reference types apprehension.
@thestarinthesky_
@thestarinthesky_ 5 жыл бұрын
This channel should have at least 500K followers! It is not fair. You are such an amazing teacher and I appreciate it
@nipnaps4138
@nipnaps4138 Жыл бұрын
Never went through a tutorial so quick , thank you for making it easy and smooth
@BillBarnum
@BillBarnum Жыл бұрын
Thanks for the comment! I'm glad the videos were useful.
@leadgamer7908
@leadgamer7908 3 жыл бұрын
A Fool Can Also Understand Concept Like This. If There Is Teacher Like You. Thank You So Much
@BillBarnum
@BillBarnum 3 жыл бұрын
Thanks for the feedback, NoFiX! I'm glad you found the video useful.
@d0c.0v3rd0s3
@d0c.0v3rd0s3 2 жыл бұрын
Our teacher failed to explain this to us in over an hour. Thank you. That was an explanation the way it should be!
@BillBarnum
@BillBarnum 2 жыл бұрын
Thanks for the feedback, Philipp. I'm glad you liked the video!
@jamindebu7134
@jamindebu7134 5 жыл бұрын
thanks so much for making it visual, i understand it so much better
@supernovic99
@supernovic99 Жыл бұрын
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!!!
@BillBarnum
@BillBarnum Жыл бұрын
I'm glad it was helpful, sciencerules!
@harpitapandian2598
@harpitapandian2598 Жыл бұрын
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!!
@BillBarnum
@BillBarnum Жыл бұрын
Harpita, I'm glad you find the videos useful. Thanks for sharing.
@kedikebba6441
@kedikebba6441 4 жыл бұрын
Thank you bill, you saved me.
@ruinex7718
@ruinex7718 4 жыл бұрын
This is an AWESOME explanation, thank you.
@sushantsyt
@sushantsyt 2 жыл бұрын
That was such a well made video, thanks a lot and keep doing the great work.
@BillBarnum
@BillBarnum 2 жыл бұрын
Thanks for watching and commenting, Sushant!
@christo-j5507
@christo-j5507 4 жыл бұрын
Clear it with simplicity! The best tutorial ever!
@omniversal4739
@omniversal4739 4 жыл бұрын
The terms sound so complex yet it's so easy to explain with examples.
@9111adil
@9111adil 4 жыл бұрын
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?
@BillBarnum
@BillBarnum 4 жыл бұрын
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: kzbin.info/www/bejne/j160aqBnZtV5jMU
@christopherhayward3078
@christopherhayward3078 4 жыл бұрын
@@BillBarnum damn....just when you think you are getting the hang of it....Thank you
@abhishekgaikwad4828
@abhishekgaikwad4828 Жыл бұрын
Explained so quickly and to the point! thanks
@someone4860
@someone4860 3 жыл бұрын
Hi Bill, I am really thankful to you.
@fireflies15
@fireflies15 5 жыл бұрын
perfect explaining. thank you
@donutsandunicorns
@donutsandunicorns 4 жыл бұрын
thank u so much for this!
@pratikkumarsingh8114
@pratikkumarsingh8114 2 жыл бұрын
Now, my doubts get cleared. Thank you so much for clearing doubts in such a short video.
@BillBarnum
@BillBarnum 2 жыл бұрын
Thanks for the comment, Pratik!
@pamameh1841
@pamameh1841 6 жыл бұрын
Great tutorial thank you
@21Bullet
@21Bullet 4 жыл бұрын
Perfect explanation. Thank you!
@kinolockhart4228
@kinolockhart4228 5 жыл бұрын
Brilliant analogy
@hkahlon9542
@hkahlon9542 4 жыл бұрын
Thank you Sir! Very well explained and makes perfect sense. Regards
@JThompson_VI
@JThompson_VI 2 жыл бұрын
Wow, I have been wrestling with this topic in one form or another for a while and this immediately cleared it up, thank you.
@BillBarnum
@BillBarnum 2 жыл бұрын
Thanks for the comment, Jacob. I'm glad you found the video useful.
@birkhansonkan4236
@birkhansonkan4236 6 жыл бұрын
clear explanation thank you
@nemeris7
@nemeris7 Жыл бұрын
Best explanation on the internet !❤
@Ravi-qz5of
@Ravi-qz5of 3 жыл бұрын
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.
@BillBarnum
@BillBarnum 3 жыл бұрын
There are some good videos on KZbin 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
@sumitrajpal29
@sumitrajpal29 3 жыл бұрын
Thank you sir ! You explained it very easily.
@BillBarnum
@BillBarnum 3 жыл бұрын
I'm glad it was helpful. Thank you for the feedback!
@projectsnik305
@projectsnik305 2 жыл бұрын
Thank You very much , This cleared all my doubts 🙏
@BillBarnum
@BillBarnum 2 жыл бұрын
Thanks for the comment and watching the video, Nikhil!
@anilmaurya55
@anilmaurya55 3 жыл бұрын
Excellent bair, short and simple thankyou
@BillBarnum
@BillBarnum 3 жыл бұрын
Thanks for the feedback Anil. I'm glad you liked the video.
@19891214ful
@19891214ful 2 жыл бұрын
Bravo 👏 Short but very informative
@BillBarnum
@BillBarnum 2 жыл бұрын
I'm glad you found it useful. Thanks for commenting.
@AzzaBruce
@AzzaBruce 4 жыл бұрын
Thank you! Starting to understand Java now
@Suraj-pf6ic
@Suraj-pf6ic 4 жыл бұрын
Thank you for making it super clear to get into my head.
@goldenotis9703
@goldenotis9703 9 ай бұрын
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'?
@meysamjavadzadeh
@meysamjavadzadeh 4 жыл бұрын
Awesome explaining
@MissMidspring
@MissMidspring 4 жыл бұрын
This is so helpful! You're a very good teacher, thank you so much!
@chetantai
@chetantai 7 ай бұрын
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"?
@enfieldli9296
@enfieldli9296 2 жыл бұрын
Clear explanation! Thank you man
@andybirenzi
@andybirenzi 4 жыл бұрын
Great and easy to understand explanation
@rickzalman4136
@rickzalman4136 11 ай бұрын
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).
@goldenotis9703
@goldenotis9703 9 ай бұрын
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'?
@mz-wk4kb
@mz-wk4kb 2 жыл бұрын
Hi Bill! Could you please create a playlist to include all your amazing java lessons?
@BillBarnum
@BillBarnum 2 жыл бұрын
Here you go: Java For Beginners kzbin.info/aero/PLmpmyPywZ443dRtMleUPoNp2OyiNE45O6
@MrBumbo90
@MrBumbo90 4 жыл бұрын
Best video on the matter.
@bosco4896
@bosco4896 5 жыл бұрын
YES I LIKE THIS
@AkashdeepSingh-qq5fw
@AkashdeepSingh-qq5fw 3 жыл бұрын
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?
@BillBarnum
@BillBarnum 3 жыл бұрын
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.
@h.rehaief3567
@h.rehaief3567 5 жыл бұрын
great job well don!
@user-kb6ho8qu9e
@user-kb6ho8qu9e 7 ай бұрын
you are good teacher
@romariosihombing7820
@romariosihombing7820 4 жыл бұрын
THIS IS PERCEFT BILL!!!
@brehgankage6242
@brehgankage6242 5 ай бұрын
Very well explained.
@user-lf3yj5zb2r
@user-lf3yj5zb2r Жыл бұрын
Thank you so much Mr Bill Barnum =)
@hajarmouqadem7671
@hajarmouqadem7671 4 жыл бұрын
THANKS A LOT!
@Tony.Nguyen137
@Tony.Nguyen137 3 жыл бұрын
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? 🤔
@kimsungho4114
@kimsungho4114 3 жыл бұрын
You're one amazing man
@BillBarnum
@BillBarnum 3 жыл бұрын
Thanks for the feedback, Sungho!
@serkansunel
@serkansunel 3 жыл бұрын
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?
@BillBarnum
@BillBarnum 3 жыл бұрын
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.
@serkansunel
@serkansunel 3 жыл бұрын
@@BillBarnum yes exactly, i just wanted to emphasize it...
@BillBarnum
@BillBarnum 3 жыл бұрын
@@serkansunel Thanks for pointing that out.
@user-zw9mk3lz5f
@user-zw9mk3lz5f 2 жыл бұрын
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 🥰
@BillBarnum
@BillBarnum 2 жыл бұрын
Thanks for the comment!
@rockedwow7217
@rockedwow7217 3 жыл бұрын
Dude this video helped me
@BillBarnum
@BillBarnum 3 жыл бұрын
Thanks for the feedback! I'm glad that you found it useful.
@Hinchey613
@Hinchey613 8 ай бұрын
Just gotta say thanks for your videos
@BillBarnum
@BillBarnum 8 ай бұрын
I appreciate that
@ihorbehen8563
@ihorbehen8563 5 жыл бұрын
Perfectly
@AkashdeepSingh-qq5fw
@AkashdeepSingh-qq5fw 3 жыл бұрын
what happens if I do h = "hello"; where does the pointer go? will "hello" of h be different object from "hello" of g?
@BillBarnum
@BillBarnum 3 жыл бұрын
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: kzbin.info/www/bejne/j160aqBnZtV5jMU
@AkashdeepSingh-qq5fw
@AkashdeepSingh-qq5fw 3 жыл бұрын
@@BillBarnum Oh ok thank you very much! By the way i have one more question on this video you linked: kzbin.info/www/bejne/j160aqBnZtV5jMVn the question is posted there.
@shahriarmim4696
@shahriarmim4696 6 жыл бұрын
At 4:39 if we make String g point to "goodbye" then what will happen to "hello" ?
@BillBarnum
@BillBarnum 6 жыл бұрын
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.
@shahriarmim4696
@shahriarmim4696 6 жыл бұрын
Thanks a lot for clearing my confusion :)
@iskandermakhmudov
@iskandermakhmudov Жыл бұрын
Thank you!
@BillBarnum
@BillBarnum Жыл бұрын
You're welcome!
@sudarshanh.s.521
@sudarshanh.s.521 4 жыл бұрын
Simple and nice
@harshilplays1170
@harshilplays1170 Жыл бұрын
thanks a lot 👍 👍
@BillBarnum
@BillBarnum Жыл бұрын
Thanks for watching and commenting, Harshil.
@subhangijena4381
@subhangijena4381 5 жыл бұрын
very nice explanation
@siddharthmundra1895
@siddharthmundra1895 Жыл бұрын
thank you so much !
@BillBarnum
@BillBarnum Жыл бұрын
I'm glad you found the video useful, Siddharth.
@illmatic33
@illmatic33 4 жыл бұрын
Good stuff.
@BillBarnum
@BillBarnum 4 жыл бұрын
Thanks!
@NMNaufaldo
@NMNaufaldo 6 жыл бұрын
Thanks
@siAppDesign
@siAppDesign 5 жыл бұрын
why not saying an address as oppose as a pointer
@BillBarnum
@BillBarnum 5 жыл бұрын
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.
@sujaybanerjee3511
@sujaybanerjee3511 3 жыл бұрын
wht editing software do u use
@BillBarnum
@BillBarnum 3 жыл бұрын
I use the paid version of Screencast-O-Matic
@leolv7872
@leolv7872 6 жыл бұрын
nice thx
@NguyenPhuc-pt8bh
@NguyenPhuc-pt8bh Жыл бұрын
thanks bro
@yogeshwarpatel7540
@yogeshwarpatel7540 4 жыл бұрын
wow
@sanjeevkumar-ty8dx
@sanjeevkumar-ty8dx 4 жыл бұрын
yours 2 video has 2 concepts,see .array type ..int[ ] c,here and other video
@anonymouskevin6558
@anonymouskevin6558 6 жыл бұрын
it will be easier to understand if you talk a bit more about stack:)
@ewoyann4266
@ewoyann4266 4 жыл бұрын
trop fort mon gars !!!! good job; alles klar
@arunsanga6433
@arunsanga6433 4 жыл бұрын
Thanksgiving
@pavelvorontsov7020
@pavelvorontsov7020 5 жыл бұрын
Cool video! I just wonder who are the ones who disliked the video? Your ex..?))
@coderatul
@coderatul 6 ай бұрын
life saver 🫂🫂
@itsblu4735
@itsblu4735 8 ай бұрын
Thank you so much!
@BillBarnum
@BillBarnum 8 ай бұрын
You're welcome!
Checking Equality in Java ( == vs equals method )
12:32
Bill Barnum
Рет қаралды 8 М.
Java Stack + Heap with Reference & Instance Variables
23:58
Job Ready Programmer
Рет қаралды 224 М.
The CUTEST flower girl on YouTube (2019-2024)
00:10
Hungry FAM
Рет қаралды 39 МЛН
SCHOOLBOY. Последняя часть🤓
00:15
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 16 МЛН
Blue Food VS Red Food Emoji Mukbang
00:33
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 33 МЛН
Pointers and dynamic memory - stack vs heap
17:26
mycodeschool
Рет қаралды 1,4 МЛН
Variables in Java ✘【12 minutes】
12:32
Bro Code
Рет қаралды 197 М.
Pass By Value and Pass By Reference In Java | Java Tutorials
26:02
Java Memory Model in 10 minutes
10:55
Defog Tech
Рет қаралды 259 М.
Primitives Data Types In Java - All the Primitives And What They Do
10:24
What is null and a null pointer exception? (Java Tutorial)
6:14
Bill Barnum
Рет қаралды 19 М.
Memory Fundamentals - part 1 of Java Memory Management
18:31
Virtual Pair Programmers
Рет қаралды 143 М.
Stack vs Heap Memory - Simple Explanation
5:28
Alex Hyett
Рет қаралды 224 М.
Casting an Object (Upcasting and Downcasting) - Java Tutorial
5:53
JavaScript - Reference vs Primitive Values/ Types
20:56
Academind
Рет қаралды 153 М.
The CUTEST flower girl on YouTube (2019-2024)
00:10
Hungry FAM
Рет қаралды 39 МЛН