Added: 2 years ago
From: thenewboston
Views: 102,051
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (170)

Sign In or Sign Up now to post a comment!
  • @thenewboston Dear Bucky,

    What is the point of the Private if you can just use public so you don't have to go back and change it? My guess is because of hackers editing code if you are to publish it, or it just lets java think less, like only inserting what you need instead of the entire 'java.*'. Can you please explain?

  • lol @ " use this one right here" in a soft voice 

  • but why it even takes 1,2,3 for first two lines of output

  • "this" function is not necessary all the times ,just directly typing the method name will also do

  • O crap we're down to less than 100k views... WE'RE THE ONLY ONES LEFT...

  • Comment removed

  • im gonna change the time to 4:5:6

    look out we have a badass over here

  • Comment removed

  • Loled at 0:23: "Now what private means is that these variables are private.". Nice one :D.

  • this is a pointer to object of current class you work on

  • which this

  • Guys!, there is many dislikes because he did it wrong.

    example: (this.hour) does NOT refer to (hour in the method). it refers to the private ones.

    Do some search.

  • @sarab2009 research#

  • @seriouslycantthink Thank you. Sorry for my bad English :P

  • @sarab2009 True.

    docs.oracle.com/javase/tutoria­l/java/javaOO/thiskey.html

  • raise the volume of your speakers and listen at 1:06 a weird bass sound =D

    

  • Damn: I've done this before and I'm still confused. It has been a while though :/

  • Description: How to controll access to memebers...

  • how are there 77 dislikes. 77!

  • lol about a thousand people give up every tutorial

  • @HectorFaelisy Hahaaaa

  • Comment removed

  • damn it, can't find ypaul123's comment...

  • If you are dyslexic and you are learning Java, I feel SO sorry for you.

  • @JamEngulfer221 Capital letters why do they exist!!!! (deslexic and proud)

  • Comment removed

  • Might be a good idea to talk about the concept of scope for this tutorial. Also, is "this" really needed if one is organized and uses different variable names for class level variables and variable in methods in the class?

  • "meme"bers? lol

  • How come this tutorial has 70 dislikes when the others barely even have 10? -_-

  • ahh object oriented lanuages.... FUCK YOU PYTON

  • how do you find useful methods like the "this" method, in java.

  • your explanation on "this" keyword is all wrong. "this" always refers to the class' own variables. In the video you assigned to these variables 1,2,3 and the first time you simply assigned 4,5,6 to the method's local variables that came as parameters, that's why nothing happened to the class variables' values (1,2,3). The second time you assigned 4,5,6 directly to the class variables which were 1,2,3 before and printed them out with their new value.

  • @mzpter the best example of using "this" would've been if you wrote this.hour = hour; this.minute = minute; this.second = second; in the setTime method. So that you assign the values of the parameters to the class variables with exactly same names. (As you can not write hour = hour). Nice tutorials by the way. :)

  • @mzpter no, you got it wrong, "this" always refers to the method variables, the ones that have "this" in front of them, the class variables will replace always the method ones if you dont use "this"

  • I love your videos, but you should really remove this one. It's going to be the cause of a lot of confusion.

  • "In the next tutorials I promise I'll be clearing this. up for you..."

    hehe =3

  • I thought a constructor is a method with the same name as the class, so, setTime is not a constructor (irrelevant of the names of the variables)

  • @Jesteria78  yeah you're right

  • For people that are confused, Bucky explained it backwards. "This." before the variable refers to the global variables (I guess they're called instance variables, but I'm not good with all the programming terminology), without "this." the local variable is used. I remember there was a top rated comment that explained it before, but other comments have taken its place.

  • @ypaul123 Judging from your recently viewed videos, you are a) a very gross human being, and b) have a shit taste in music. Grow up, please.

  • BUCKY ROCKS!!!!

    My Coding Improved!

  • 5:28 LoL he made a pun.

  • I dont know Y or people rush to criticize...

    I bet none of them try or do what u've just done.

    I GOT Something From this! THANKS BUCK..

  • So basically, private overrides public, and this. overrides private?

    Why didn't you just say so in the first place? :P

  • Hey you! click the like button this.second!

  • this is to the class, not the method... if you want the method variables, do not use this. just watch what highlights, which you can see in your video, to see the linkage.

  • @matthewdoucette this is not the class, this is the object . For example (class)String j(object).

    Contstructor(String j){ this.j = j;

    }

    this.j is not the same as String.j .this is a flag referring to an object ,or variable as in int j.

  • "When we use the 'this' keyword, we're reffering to the method's Parameters *Select the 'this.Second'* *The Class' 'Second' Variable lights up to show a match*"

    Bucky are you tired?

  • Apparently nobody really knows what this is.

  • Guys, just play around with the 'this' keyword in Eclipse. You'll eventually understand it better. If not, watch the video response that 'ilikechess1' posted and check the description of that video for a link that explains it!

  • Nice video Bucky, I'm planing on leaving C++ and moving onto Java since it's easier.

    Quick question though mate. You know some phones have Java installed and you can run Java APPs etc...? If I wrote a simple Hello World program in Java and then put the .jar (or is it .java?) file onto my phone would it run? Or would I have to do stuff to it in the IDE (check options etc...) and rearrange the code?

    I'm not interested at this moment in GUI stuff for phones, just screwing around with messages.

  • I'm a beginner, because of the comments I was not able to watch the video. But then again I'll finish all your tutorial. Your tutorials amaze me, so one mistake will not affect the whole tutorials.

  • lets dislike for good. :(

    hopefly he'll respond

    im a beginner. bucky is way more expert than iam.

  • bucky u need 2 replace this video, as people pointed out.. your explaination is wrong. got lots of respect to you and your videos.

  • Well at the very least bucky should reply with a comment and let us know what all the confusion is about...

  • Oh we should dislike this video se he will notice.. just saying he doesnt want to have video with LOTS of dislikes..

  • Delete it please!!! and keep going. good luck. we will support you as long as there is sign of improving

  • bucky fix this bro

  • Bucky....please delete/redo this video to prevent confusion for beginners in Object Oriented Programming.

  • delete this video dude...and redo it

  • Agree. This (right this!) you got wrong.

  • i am getting answer as local variables after using this also...:(...

  • brow for this keyword you can find it...mistake can be happen

    *****youtube.com/watch?v=VQkGd­J_fm0Y*******

  • brow for this keyword you can find it...mistake can be happen

  • in addition to revising your explanation, try this example: public void setTime(int hour,int minute,int second){ hour = 3; minute = 4; second = 5; this.hour = hour; this.minute = minute; this.second = second; }

  • Lol, I thought i had a decent idea of what 'this' is about and this video completely confused me. I agree with the others and maybe redo this tutorial...

  • buckey said that local variable r preferred than method local variable when variable name is same

    but reverse is happening with me

  • plz help i am in big confusion just tell me if i have : class c1{ int x=2; c1(int x){ System.out.println("the value of x is = " + x); } now if i call this method in main class by passing argument int a=10; this1 obj1= new this1(a); i expect the output to be as per explained by buckey the value of x=2 but the output is coming the value of x=10 plz explain anyone!!
  • This was another great tuturial.

    Pun intended.

  • air

  • nice video

  • nice video

  • Voice crack at 4:37 :D

  • so, this means that this.hour changes the value of the class variable hour and that setTime method is still using the class variable and not its own because it does not exist?

  • like everybody said, when you call a variable in a method, it first checks wheter if it is a parameter, a local variable or a instance variable, when you use the keyword THIS, it checks if its a instance variable, a parameter or a local variable. In other words, THIS points to the instance variable(class variables).

  • Yes, what everybody else said regarding the use of THIS.

  • daawww

    i don't get it

  • When we say:

    this.hour = it means the hour variable of THIS class and not the hour variable in the parameter list.

    You've said the opposite in the video.

    But hey, we all make mistakes and we all appreciate your effort :)

  • bucky.. your explanation is wrong in this video.. hope you correct this and upload it again..

  • private means they are private?

    noooo

    (sarcasm)

  • man you are explaining it all wrong and your explanation is really bad

  • Your sense of humor tickles me -- makes the videos!

  • Don't show this video to your employer. He'll fire you.

  • Thank you for explaing this!!!!! Wish my instructor would have told me why we use "this"... lol

  • exactly what specimon said

    love you bucky keep em coming please

  • "this" refers to current object which in this case is the tuna class.

    You can see Eclipse highlighting the fields of the current object.

  • Lmao. I'm sure that was his tone, "Use THIS one, right HERE!" haha :)

  • "Public, private and this". Sounds like a sitcom to me.

  • Thank you

    

  • if i enter sec or minutes mor ethan 60 it does not replace em with 0 and prints em instead???

  • Check out the link below, it explains what exactly a THIS is in Java. bit.ly / ckalCx

  • Here's how i look at it..

    the 'this' keyword finds the object that

    called the method,'settime()', and displays

    the instance variables assigned to said object.

  • Everyone I think he gets the idea about what this is !!! idiots.

  • this.second refers to this class field

  • this.second refers to 'second' field from 'this' class.

    good job anyway !

  • this.second refers to 'second' field from 'this' class.

    good job anyway !

  • :))) u make me laugh every time i watch u'r tutorials , your sense of humor it's awesome :d

  • i had one more doubt that how could bucky initializes(i.e assign values) for the class variable while defining . Is that valid ???????

    If yes then what is the use of an simple constructor

  • " this" either refers to an instance variable or it refers to the appropriate constructor in the class based on the number of args passed in. it doesn't refer to the method variables or "local" variables.

  • Hmm when you have setting of:

    setTime(int h,int m,int s)

    {hour=4;minute=5;second=6} and the private methods above the same, it results to 04:05:06 and not 01:02:03

  • but... wait a minute.... the code

    private int hour = 1;

    private int minute = 2;

    private int second = 3;

    isn't in a method, so why is it even executed at all????

  • " but hum" in the end ^^

  • What Bucky meant is : "this" changes value of instance var with value of method var...

  • bucky i understand all in this video, except for THIS.

    ..i dont quite get it...anyways good tutorials man

  • I agree with specimon and hmk##

    The only java I know is thanks to you, but after toying around it seems to be the opposite. Whenever you use this., it will refer to the instance variables and not the method variables (correct me if I'm using the vars names wrong)

  • just great how you make us understand this, 5 books couldn´t tell me as good as you.

    regards.

  • THE BEST WAS to introduce one into the usage of "THIS" keyword! VERY NICE BUCKY! ;)

  • bucky u r a gr8 person i have ever seen....... ur tutorials give me lot of sense about java and u explain so much better than my university teachers..... and 0121ryanh117 @ypaul123 is a mother fuck dont listen him...... and bucky i love you

  • Declaring a field public is bad programming btw, don't do it, if you do want to change the values make a set method and call that method in the class you want to use it from.

  • @Nunjabes encapsulation :P

  • @ypaul123 You are a complete asshole, you should be banned from the internet.

  • hes better than u in every way, and i dont see you making any tuts that ppl wanna see, so obviously u dont no wut ur doing or talking about. they really should start banning kids 9 and under from the internet,,,

  • lol ur allowed to use short text as long as youre not writing something important, and im actually very smart, probably smarter than you...by a lot...

  • @Guildwars55

    Just because you assert to be "smat" doesn make you one, in fact you probably announced it in order to compensate the fact that you are not.

    I bid you goo day.

  • @ypaul123 IDIOT!

  • @ypaul123 Meh, go back living under a frikking rock, douchebag.

  • @ypaul123 this guy has made thousands of tutorials that are watched every single day and treasured by people who want to learn how to program. he gives out this knowledge for free and he delivers it in a fun and informative way. you, fool, are the pathetic douche and I sincerely hope your computer blows up in your face and you never have access to one ever again in your entire life so no one else has to put up with your crap.

  • @ypaul123 you suck your the biggest douche on the whole internet.You probably comment on every video you see.

    Asshole

  • not this that one

  • Comment removed

  • Buckky soory .. let me explain when ever a varible is called in a method it first check whether is it 1.Parameter 2.local variable 3.instance variable as when you call second bla, bla in a method it consider it parameter and change it but what happen when we use this key word then system check in following order 1.instance var 2.parameter 3.local var hopefully all understand now plz make new vedio and clear your concept comment me if i was wrong skype/google/googletalk=hmk250­61984
  • @hmk25061984 Hi there ! I guess you got it all wrong and Bucky's right, look at the Java Tutorial Fourth Edition (2006), by Sharon Zakhour (given as a reference in The Java EE 6 tutorial (2010) from Oracle (Thee Bible ov Java)) : "Within an instance method or a constructor, this is a reference to the current object - the object whose method or constructor is being invoked. You can refer to any member of the current object from within an instance method or a constructor by using this."

  • The usage of 'this' in the method:

    public void setTime(int hour,int minute,int second){

    this.hour=hour;

    this.minute=minute;

    this.second=second;

    }

    Initialize the values in the 'main'

  • lol..."this is like a little joke"...great, can't wait for this to be cleared up in the next tutorial......now...

  • this refer to Instance of the same class.

    Buky remove this video.

  • rajeev, you are right. This tutorial was so far so good. But because of THIS.....

  • Bucky, if you think these thises are confusing you should have heard this from my teacher here at school. You have made clear in under 6 mins what he couldn't make me understand in 3 months. THANK YOU for these tutorials, you have taught me much more than the stoopid jargon-filled textbook or my teacher. Again, THANKS!

  • Great respect to you Bucky.

    But sorry, you explained it the wrong way round. The keyword "this" is used to point towards instance variables (the class variables) and not the method vars. So its exactly opposite as you showed. As you can see in Eclipse: When hovering over the variables name with "this" enabled the instance vars are orange also. And vice versa the method vars when taking this away. (visible during this video)

  • Yes, specimon is correct. You are brilliant, but it seems you have made a mistake (don't worry, we're all human!!) :). Specimon explains why.

  • I agree as well with specimon "this" refers to the the instance variables.

    In my class they taught that it will actually do exactly the opposite of what you said it would in the video. It will consider the variables local to the method first then only the instance variables inside the method if you specify with this.second ect.

    Love your videos. They help me to review topics and get extra practice but this appears to be incorrect.

  • @specimon Thanks, that confused the hell outta me for a second. "What? 'this' referrers to the local scope?"

  • @specimon Hi there ! I guess you got it all wrong and Bucky's right, as it is written in the Java Tutorial Fourth Edition (2006), by Sharon Zakhour (given as a reference in The Java EE 6 tutorial (2010) from Oracle (Thee Bible ov Java)) : "Within an instance method or a constructor, this is a reference to the current object - the object whose method or constructor is being invoked. You can refer to any member of the current object from within an instance method or a constructor by using this."

  • @JamesBecht :

    Thats actually what I said. "This" refers to the object and therefore the object variables. Not the method or constructor variables...

  • @specimon "the keyword "this" is used to point towards instance variables (the class variables)"... definitely NOT "the class variables"... anyway :-)

  • @JamesBecht your comment is confusing.

    "THIS" for ---> class variables and object variables = same thing.

    Except when you talk about global variables (static etc. what is not important in this case)

    "THIS" not for --> Other variables that are also defined in the constructor and methods.

    Please just read my original comment one more time.

    Thanks....

  • @specimon OK I think I understand what you mean (english is not my native language...)... but what's getting me confused here is that the keyword "this" allows the Tuna class variables to be overriden by the setTime method variables... right ? as it's said in Sharon Zkhour's book.

  • @specimon well well well... now I think what got me confused... I thought the class variables were overriden by some method variables having the same name (as I said in my previous post), while instead it's just that "this" is giving new values to the local class variables... ? am I right this time ? and btw sorry for the confusion...

  • Comment removed

  • @specimon u r wrong instance methods are NOT class methods

  • @specimon If you know Java, why are you watching?

  • @specimon I guess Bucky explained it correctly. I think you don't even know what's the difference of instance variables and class variables, cause you typed like "instance variables(the class variables)". Didn't he pointed out in this video that "this" is used to point towards instance variables? Instance variables are those variables inside the method's parameter.Watch the video again. If you couldn't understand, then I guess that you must be an I***t. and this 93 who thumbed up are j** a**.

  • @javaken09 - sorry but you are incorrect - please check again

    instance vars are called "instance" regarding the class instance - the other type are local vars

    just read it up on the java doc or ask on the oracle developer forum

    thanks

  • @javaken09  Mighty strong words for someone who clearly has no idea what they're talking about. Specimon is correct, as are the 96 people making sure the correction is visible for people trying to learn.

  • @specimon Yup.

    Before you slam specimon, look up Oracle's Java tutorials regarding this. Do a search for "Using the this Keyword Java."

  • @coderTrevor - thanks mate :)

  • 3999 views :P

    Great tutorials!!!

  • @812Insane, you're my hero!!!! 4000th view

  • I Agree with gaurav here as methods are using class's attributes which are modified using 'this' operator.

  • I understood the concept that you were putting across awesome once again cheers : )

  • this makes sense.

    I like this.

    I understand this.

    this is cool!

    LOL! this is a joke.

  • now i understand what 'this keyword does...

    i really appreciate your tutorials..^^

    '

  • yeah the this keywords explanation is not ok.

    still, nice tutorials

  • You are so retarded. when using this.hour, you're using the private int hour that you declared previously, and setting that to 4, NOT the int hour set in the void setTime().

    Also, if a field is static, so private static int hour; you wouldn't use this.hour, you would use tuna.hour. tuna being the actual classname, not an instance of the class.

  • Comment removed

  • if he is supposedly so retarded y would you even take your take time watch his video?

  • Hmm... I like your tutorials a lot, but as others have stated, you really need to redo this video. Pretty much everything you explain about the 'this' statement is backwards.

  • i like all ur vids man! I downloaded everyone of them...1 to 45..pls move on to intermediate..and GUI's...tnx alot

  • you have done a mistake by mistake. please correct it. when we use "this" it will use private variable of tuna class rather local variable of settime function.

  • u ROCK bucky

  • thxns for these java videos. they are the best!

  • This will definitely can help me later on. when i started to study again^_^ more tutorials

  • As far as I can see, your setTime() method arguments are not used at all. "This" is not referring to method arguments, but to class variables (those that are set to private in your program).

    That's the reason why your program changes time to 4:5:6, because "this" is referring to class variables, and not to method arguments!

    Also notice that Eclipse is coloring the same variables in whole program when you click on one of them. That should help in distinction between local and class variables.

  • I was thinking the exact same thing...

  • In fact, I've did one mistake in terminology. Above mentioned private variables are in fact instance variables (and not class variables, as I sad before).

    Nevertheless, the point is the same, this lesson has really huge error that should be corrected.