What is null and a null pointer exception? (Java Tutorial)

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 ธ.ค. 2024

ความคิดเห็น • 18

  • @BillBarnum
    @BillBarnum  5 ปีที่แล้ว +1

    📌 Subscribe For The Latest Videos: bit.ly/36H70sy 📌
    .
    💻 All Java Tutorials: bit.ly/JavaTutorialsTH-cam 💻
    .
    🤖 Learn Java In 3 Hours: bit.ly/JavaIn3Hours 🤖

  • @lizetavasilescu3054
    @lizetavasilescu3054 5 ปีที่แล้ว +6

    This is the best explanation I have found on TH-cam! Thank you!

  • @umabharathyts1998
    @umabharathyts1998 5 ปีที่แล้ว +2

    perfect explanation ,Thank u so much!

  • @AlamBarmaja
    @AlamBarmaja 6 ปีที่แล้ว +3

    Nice explanation thank you

  • @youtubeaccount0x073
    @youtubeaccount0x073 5 ปีที่แล้ว +4

    I hope I get a 5 of AP CS A 🙏

  • @abrehamish
    @abrehamish 4 ปีที่แล้ว

    Excellent explanation

    • @BillBarnum
      @BillBarnum  4 ปีที่แล้ว

      Thanks for the feedback!

  • @youtubeaccount0x073
    @youtubeaccount0x073 5 ปีที่แล้ว +1

    Let’s say we create an object Cat anonymous = new Cat(); what does anything have to do with the Cat in the beginning it’s the type of the object yeah but like what does that mean. So anonymous is the memory reference so is the anonymous pointing to Cat or something??

    • @BillBarnum
      @BillBarnum  5 ปีที่แล้ว +4

      Think of it like this:
      Imagine that you created a name for a real life cat. In this case, the name is "anonymous." Just because you have a cat name, doesn't mean you have an actual cat. If you say "hey anonymous, go clean your fur," nothing will happen because there is no actual cat attached to that name.
      If you want a cat to actually do anything, you need to create a physical cat and then have the name anonymous point at the actual cat.
      Now that you have the anonymous name pointing at a physical cat, you can say things like "Hey anonymous, go catch a mouse."

  • @hemnahmed1160
    @hemnahmed1160 6 ปีที่แล้ว +1

    Great!

  • @shahriarmim4696
    @shahriarmim4696 6 ปีที่แล้ว

    Dear Bill, I have a question ! All we know is that, objects including instance variables are created in heap and all methods and local variables, and reference variables are created on the stack. Suppose I have,
    class Animal {
    int size;
    public void methodA(){
    // a line of code
    }
    }
    now If I create an Animal object and I refer to it to a reference variable called dog i.e. Animal dog = new Animal(); Then I invoke the methodA() in my main() method like this dog.methodA(). Now My Question Is: How's going to object use that method cause object is in Heap and Method is in Stack!? And as far as I know from your video there's only a pointer from stack which is reference variable pointing at object which is in Heap.

    • @BillBarnum
      @BillBarnum  6 ปีที่แล้ว +2

      The reference variable dog would be on the stack, but dog would be pointing to an object of type Animal on the heap.
      When you called dog.methodA(), it would call the method from the object on the heap that the dog variable was pointing to.
      Bear in mind this analogy is not a perfect representation of what Java does in the background.

  • @illmatic33
    @illmatic33 4 ปีที่แล้ว +1

    link for memory handling th-cam.com/video/LTnp79Ke8FI/w-d-xo.html

  • @illmatic33
    @illmatic33 4 ปีที่แล้ว +2

    Watch at 1.25 speed, thank me later

  • @guptadagger896
    @guptadagger896 2 ปีที่แล้ว +1

    What is happening on the stack and heap when we call catzilla.fall() and clawdia.fall()?

    • @BillBarnum
      @BillBarnum  2 ปีที่แล้ว

      fall() is a static method which means it belongs to the class. Since the method resides in the class, an instance of the class (object) doesn't need to exist to access it.