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

Поделиться
HTML-код
  • Опубликовано: 7 ноя 2024

Комментарии • 18

  • @BillBarnum
    @BillBarnum  4 года назад +1

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

  • @lizetavasilescu3054
    @lizetavasilescu3054 5 лет назад +6

    This is the best explanation I have found on RUclips! Thank you!

  • @AlamBarmaja
    @AlamBarmaja 6 лет назад +3

    Nice explanation thank you

  • @youtubeaccount0x073
    @youtubeaccount0x073 5 лет назад +4

    I hope I get a 5 of AP CS A 🙏

  • @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.

  • @umabharathyts1998
    @umabharathyts1998 5 лет назад +2

    perfect explanation ,Thank u so much!

  • @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."

  • @abrehamish
    @abrehamish 4 года назад

    Excellent explanation

    • @BillBarnum
      @BillBarnum  4 года назад

      Thanks for the feedback!

  • @hemnahmed1160
    @hemnahmed1160 6 лет назад +1

    Great!

  • @illmatic33
    @illmatic33 4 года назад +2

    Watch at 1.25 speed, thank me later

  • @illmatic33
    @illmatic33 4 года назад +1

    link for memory handling ruclips.net/video/LTnp79Ke8FI/видео.html

  • @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.