This Keyword in Java Full Tutorial - How to Use "this"

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 ม.ค. 2025

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

  • @lfcbpro
    @lfcbpro ปีที่แล้ว +66

    I've gotta say John, I am doing Java in Uni, and I have their book, and a few others, but your videos wipe the floor with them when it comes to clarity and explanations.
    Seriously, if you aren't a teacher, you should be one.
    I was disheartened when I was reading the course materials for my class, but just watching your videos has really helped with everything.
    Thank you very much indeed.

  • @Clean_Slate
    @Clean_Slate 2 ปีที่แล้ว +37

    You make things look so much easier. I feel like I have watched perhaps an entire lecture after most (if not all) of your videos.
    And I mean that in the best possible way. Keep being great, you certainly have a gift in teaching!

  • @ne_univayte_pazani
    @ne_univayte_pazani 6 วันที่ผ่านมา

    Probably nobody gonna see my comment, but im having a java exam in 2 days and figuring out something that was a pain in ass the whole semester in 7 minutes is truly a save. Thank you, John!

  • @luomle-f6z
    @luomle-f6z 11 หลายเดือนก่อน +2

    Your channel single handedly allowed me to pass my intro to java course. Went from failing to a 3.0.
    Thank you!

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

    this keyword was so confusing to me as a beginner- more than most other concepts!!-video really nails it down, and helps reinforce my understanding

  • @JusQuelle
    @JusQuelle 3 ปีที่แล้ว +61

    This was a great explanation of the "this" keyword, thank you so much!

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

    grabe ka na johnny, you really know a lot of work, legend

  • @ayenoodles9068
    @ayenoodles9068 2 ปีที่แล้ว +12

    Thank you John! I’m a sophomore Software Engineer, and you explain things much clearer than my professor ✨

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

      @@jamesdrinkard687 what do you think assignments are in school? also, you think john never went to school? you sound like you're coping a bit.

  • @bhaweshpandey4306
    @bhaweshpandey4306 3 ปีที่แล้ว +20

    I am a beginner, so I guess it will take sometime to thoroughly grasp all at once.
    Thanks for the explanation man!!

    • @vipulpatel1849
      @vipulpatel1849 6 วันที่ผ่านมา

      Hey bro how it's going you have learned java right now,,,??

  • @IluSsIoNnN
    @IluSsIoNnN 3 ปีที่แล้ว +11

    I am just learning Java (from mechanical engineering, career switch) and your videos are great.
    Keep it up and Thank you !

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +8

      Awesome, good luck on the career switch!

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

    I've watched a bunch of your videos today just in two hours and I'm amazed of how you make things look so clear in just seven minutes or so per topic :D Great job!

  • @wallywild5088
    @wallywild5088 3 ปีที่แล้ว +2

    Plz keep doing this in just a couple months you’ve provided so much value

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว

      Been going for about a year now! But the first bunch of videos were much rougher for sure, so you're probably not wrong that the last couple months had some of the best stuff so far. 🙂

  • @danial_amini
    @danial_amini 4 หลายเดือนก่อน

    Why is this guy so helpful, so much clarity & speed in teaching 😭😭😭😭

  • @user-0987-a
    @user-0987-a 2 ปีที่แล้ว

    You explain it better than anyone, bc you inform us what we need to know NOT what you know.

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

    I think that using "this" in class methods, like constructor or getters and setters, is not for avoid confusing between the function parameter and the filed name.
    The uses of "this" is for referencing the specific object in memory beacause we can have many other objects of the same class.

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

    The explanation is insanely clear! Saved me from another course tbh

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

    holy crap *this* actually makes sense now! I was trying to do something for a project in my comp sci class and couldn't figure out what I was doing wrong.(also apparently we were supposed to use "this." but it wasn't introduced until the next lesson which was stupid)

  • @NovaEngineer
    @NovaEngineer 8 หลายเดือนก่อน +1

    Best explaination on "this" keyword i have ever seen so far on Yt!!! Thanks a lot man🙏🙏🙏🙏🙏🙏

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

    Omg been fighting with Intellij to understand getters, setters and constructors and watching This was an instant 4 piece! Thank you!!!

  • @dekumutant
    @dekumutant 3 ปีที่แล้ว +2

    Your channel is fantastic. Please don't stop

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

    Your explanation of the "this" keyword is crystal clear. After being stuck at this point for such a long time, it finally makes sense to me. I am really grateful for your help! I am in my second year of college and right now, struggling in a java class highlighting algorithms and data structures. I have also checked some of your other videos and will certainly watch more! Thanks!

    • @darrenfrancis8126
      @darrenfrancis8126 ปีที่แล้ว

      im in the same boat but i am building a calculator app and in the tutorial he used "this keyword in a different context.
      functionButtons[i].addActionListener(this);

    • @gamingzonezone1
      @gamingzonezone1 หลายเดือนก่อน

      Hi jingyi can we be friends

  • @sportingdirector1
    @sportingdirector1 3 หลายเดือนก่อน

    Thank you! I'm so appreciative of this that I'll watch the ad in its entirety so you can get some of the money!

  • @cshishir4582
    @cshishir4582 ปีที่แล้ว

    The tenth grade board exams are comming up and i think that this was a pretty informative video.
    I really like the efforts put by Sir John who is also teaching us for free unlike most of the cases (tutions example) where they charge tons of money for basic concepts.
    The plus point is that he is a really great teacher too.
    Sir i hope that you will continue to do this.

  • @atazky613
    @atazky613 3 ปีที่แล้ว +1

    Youre a f*cking magician John, i literally thought about refreshing my java constructor knowledge when you uploaded this video

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +2

      Thanks! 🧙‍♂️
      You may have seen it already, but I have another recent video with even more constructor info here: th-cam.com/video/pgBk8HC7jbU/w-d-xo.html

  • @gabrielfono844
    @gabrielfono844 ปีที่แล้ว

    This is whole different level.
    I am working hard to get to this point where explaining concept is as easy as coidng with john currently explains
    thanks for your hard work
    we all really appreciate.

  • @jvsnyc
    @jvsnyc 3 ปีที่แล้ว +4

    Dang near perfect, and no, I don't have any complaint at all, except that in other languages some good developers felt that "this" was redundant in instance methods and should generally be avoided as noise (their approach was non-ideal when the natural name for a method parameter was the same as a data member, of course -- they would wind up having to munge those). On the theme of "I love how you do brief intros that don't overwhelm the learner with minor details without lying or teaching anything they will have to learn later" a very good book I am reading does just that. In a quest to prepare the reader for cert exams, they don't merely ignore stuff that isn't on the exam in that area, but actively make some misstatements that won't affect one's performance on the exam, but if you go beyond later, you will actively have to unlearn some "convenient lies" that they could have just ignored instead. It is a fine line, but you normally always land on the right side of it. There are extremely few "untrue statements" or "non-facts" found in your videos in service of making a good introduction. That is not easy to pull off, and I really appreciate it.

  • @instayville-is2no
    @instayville-is2no ปีที่แล้ว

    Your explanations have helped me fully wrap my head around these concepts that I have never been able to understand for years in my self-study. Thank you so much! I've subscribed since I'm going all-in on learning Java at this point and I really want to hone in on the basic concepts.

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

    You're saving my Java studies. I am really grateful for your classes !

    • @hikaru_e
      @hikaru_e ปีที่แล้ว

      ong, he is crystal clear with what he explains and many times he answers questions I've been wondering about for quite some time

    • @gamingzonezone1
      @gamingzonezone1 หลายเดือนก่อน

      Hi atmaria can we be friends

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

    probably the best "this" keyword tutorial I've come across... and I've watched a ton. Thanks!

  • @kevincarter3753
    @kevincarter3753 ปีที่แล้ว

    Great tutorials! Right length, right content and great attitude!

  • @Gandhi_Physique
    @Gandhi_Physique 3 ปีที่แล้ว

    Wow, I wasn't expecting to learn anything but now I understand it much better. I didn't even know you could call a constructor in that way.

  • @Hassan-lv9di
    @Hassan-lv9di ปีที่แล้ว

    The best explanation i've ever seen !!! thank you alot John! keep up the hard work

  • @matheuscastroks
    @matheuscastroks ปีที่แล้ว

    your the best teacher ive ever had, thank you

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

    Far better than the course i've paid good money for :) - Thanks very much!

  • @prasanthivasu
    @prasanthivasu ปีที่แล้ว

    thank you john. I got my concept clear. was confused in class.

  • @hammer9185
    @hammer9185 ปีที่แล้ว

    I'm just impressed by the way you explain Everything! Excellent job!

  • @tamingpaola
    @tamingpaola ปีที่แล้ว

    this definitely helped me, im 11 weeks in my java cs class and needed to understand what the hell was going on with these constructors XD

  • @rubinconineski526
    @rubinconineski526 ปีที่แล้ว

    It is very good. You speak very good. I understand almost everything 95 %.
    Thank you.

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

    I see what you did there with the dog named Kramer and the Kramer poster in the back. BTW your explanations are super easy to understand compared to other videos. Amazing work.

  • @mckenziepictures
    @mckenziepictures ปีที่แล้ว

    1. This video was AWESOME!
    2. Even more awesome, John listens to Rush! (R.I.P. Neil Ellwood Peart)

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

    His videos are so cracked. It's so beginner friendly.

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

    I am learning java and this helps me a lot , thank you so much John

  • @s.a.806
    @s.a.806 10 หลายเดือนก่อน +1

    Very clear, thanks a lot!

  • @seifashraf2046
    @seifashraf2046 ปีที่แล้ว

    I don't know how you make things this simple, suddenly I just understand it and idk how lol

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

    I work in C#, and I swear Java is basically the same language with a different API.
    I feel like I'll be referring to your videos a lot while working on my CS Java course, though, since Java is different enough to cause some confusion.

  • @SwarcMaster
    @SwarcMaster 3 ปีที่แล้ว

    Keep doing great job, John. Thanks to you i can progress Helsinky MooC course like walk in a park.

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

    Excellent video, very clearly explained, also cool vibe. 10 out of 10. Thank you very much!

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

    This is wonderful, I finally understand how this works!

  • @Roberto-lb5or
    @Roberto-lb5or ปีที่แล้ว

    Magnificent explanation as always. I got your bootcamp course at your web page

  • @Alstash
    @Alstash ปีที่แล้ว

    Clear, pleasant, and understandable. Thank you!

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

    Thank you so much for teaching this

  • @gunslinger7779
    @gunslinger7779 3 ปีที่แล้ว +2

    Thank you so much for THIS video.

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว +2

      I almost added a counter to the video to show every time I said the word "this", I thought it would be hilarious. But then I thought it might have been too distracting. So you all can turn it into a drinking game instead.

  • @zehrairkicatal2156
    @zehrairkicatal2156 3 ปีที่แล้ว

    Perfectly it was explained Looking forward to next your video reference type and primitive type CASTING

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

    Great video, the subject is so clearly explained. Amazing explanation, Thanks!!!

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

    you give answer for every why I ask myself. Thanks

  • @24K-r2l
    @24K-r2l ปีที่แล้ว

    Really clear explanation, thank you so much!

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

    Very well explained, thank you!

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

    Great explanation. Addicted to your channel. Thanks for such a simple explanation

  • @viniciuslima1185
    @viniciuslima1185 3 ปีที่แล้ว

    your videos are really helpful... much love from brasil!

  • @gulshanmustafayeva1707
    @gulshanmustafayeva1707 ปีที่แล้ว

    You are thee greatest explainer ever 🙂 thank uu

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

    Thank you so much! This video completely made sense out of it.

  • @mitmordag
    @mitmordag 3 ปีที่แล้ว

    Great explanation! Thank you. I am looking forward to next videos

  • @tellefsolberg5698
    @tellefsolberg5698 3 ปีที่แล้ว

    Absolutely terrific videos!

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

    Finally understood this, thank u so much

  • @jer5206
    @jer5206 3 ปีที่แล้ว

    These vids are gold ty!

  • @iliasettaoussi4680
    @iliasettaoussi4680 3 ปีที่แล้ว

    you are an amazing instructor

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

    THank you soooo much! Please continue creating your videos!!

  • @derrickli497
    @derrickli497 ปีที่แล้ว

    no cap you teach better than my triple PHD professor from a top 30 university in the world

  • @isackcosta5660
    @isackcosta5660 ปีที่แล้ว

    Good video! Helped me a lot.

  • @abdesamad6616
    @abdesamad6616 ปีที่แล้ว

    This was a great explanation of the "this" keyword

  • @paulgrossman8830
    @paulgrossman8830 ปีที่แล้ว

    John, are you a drummer? Just looking at your kit in the background. Thanks as always for the great videos.

  • @cetinarslan262
    @cetinarslan262 3 ปีที่แล้ว

    Thank you. It was really clear. Good luck...

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

    this should be the first line in the constructor is the new thing i have learnt.

  • @micleh
    @micleh 3 ปีที่แล้ว

    I'm so annoyed by the fact that here in Germany the government makes pupils use parameters prefixed with a 'p', which is why they'll never get in contact with the 'this' keyword, since there is never a conflict with the field names - I'll tell them, though, anyway. Your Dog constructor would therefore look like 'this': public Dog(String pName, int pAge).
    I think this is a relict from the time that the default language in higher education was Delphi and senior developers in the government didn't want to give up this parameter naming convention when they had to learn Java.
    Thanks again for the awesome content. I'll definitely recommend your videos to my students.

  • @amiraliazimi6355
    @amiraliazimi6355 3 ปีที่แล้ว

    Great! ❤️
    I always watch your videos

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว

      Thanks for watching, glad you enjoy them!

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

    Thank you so much, it really helped

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

    Thanks a lot for your videos, they have been a godsend!

  • @meetbohra5415
    @meetbohra5415 3 ปีที่แล้ว

    Thank-you John!

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

    Really great videos, thanks!

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

    I feel like this is a dumb question, but why not just change the names of the method parameters? Wouldn't that remove the need for the 'this' keyword?

  • @thegopodude7000
    @thegopodude7000 5 หลายเดือนก่อน

    Doug Demuro loves this keyword

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

    I love all your videos! never stop making them!

    • @gamingzonezone1
      @gamingzonezone1 หลายเดือนก่อน

      Hi Julia can we be friends

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

    thank you so much, i was struggling with this "this" hahahahaha

  • @ousmanetall1286
    @ousmanetall1286 ปีที่แล้ว

    My hope is you explain in details the differences between method and constructor, and the purposes

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

    Hi John.
    How come we don’t just use a different parameter name instead of “name”. Wouldn’t that also avoid there being two “names” to be referred to? For example:
    public void setName(String nameSet) {
    name = nameSet;
    }

    • @CodingWithJohn
      @CodingWithJohn  3 ปีที่แล้ว

      You're absolutely right, that would do the trick too! I suppose programmers are kind of a stubborn bunch and we don't want to use another name for something if we don't have to. I don't have much of a better explanation unfortunately, but the convention you'll see used is still to use the same names with "this".

    • @zaptodeathx
      @zaptodeathx 3 ปีที่แล้ว

      @@CodingWithJohn alright! Thank you for explaining that.

    • @ЮрийОлейник-ы6н
      @ЮрийОлейник-ы6н 2 ปีที่แล้ว +1

      "this" is a reference to a current object. I'm suprised that author can't show a simple example when usage of "this" is necessary. One of the examples could be a method for class Node like:
      void add(Node aNode){
      aNode.next=next;
      next.prev=aNode;
      next=aNode;
      aNode.prev=this;
      }
      Here Node is a node of double linked list. This method adds aNode right after current(or "this") Node in list. And it can't be done without "this".

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

    ur a god!!! help me soooo much thank you so much

  • @vedantjha2327
    @vedantjha2327 ปีที่แล้ว

    Point to note
    This keyword can also be used to call other parameterized constructor
    Which will be the first statment

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

    You are amazing! Thanksss

  • @floridarolf100
    @floridarolf100 3 ปีที่แล้ว

    There's a new Java Sheriff in town!

  • @la1m1e
    @la1m1e 7 หลายเดือนก่อน +2

    For me it's usually like this: it doesn't work -> add this. -> it works

  • @carlosjohnson4421
    @carlosjohnson4421 ปีที่แล้ว

    i need you as my personal teacher

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

    great video thank you so much

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

    Thanks for this, except @4.38 - "point of a static method is that they CAN NOT be used"

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

    Thank you so much!

  • @tomkutscher942
    @tomkutscher942 10 หลายเดือนก่อน

    Currently Iam in the first year of systems engineering and we have to learn java but with bluej, but bluej sometimes sucks, there are many features like markings in eclipse and other editors that bluej doesnt have.

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

    5:15 Why not just create a constructor that is parameterized, or create a default constructor WITH the default values included? Why the need for a no-args constructor in your example? It seems like (and I know it just seems) you're doing unnecessary work; one parameterized constructor (and the addition of a default constructor) solves the need for the this keyword, does it not?

  • @PedrovoriskAB
    @PedrovoriskAB 3 ปีที่แล้ว

    Make a video about creating a server and client with java pls !!!!!!!!! THANK U FOR ALL UR VIDEOS

  • @Robert-jt9yg
    @Robert-jt9yg ปีที่แล้ว

    Great stuff

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

    Thank you again :)

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

    1:40 I'm pretty sure you don't need 'this'. Java will just figure it out for you. Also you missed the opportunity to show passing 'this' as an argument.