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?
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?
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"
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.
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.
"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*"
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.
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...
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!!
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).
" 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.
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)
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.
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...
@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.
Everybody commits a mistake.. c'mon... just a little misconception right... ^^, the keyword "this" usually access the class members/variables or properties within a class... :) Great Vids Bucky...
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=hmk25061984
@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."
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!
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)
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 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."
@specimon "the keyword "this" is used to point towards instance variables (the class variables)"... definitely NOT "the class variables"... anyway :-)
@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...
@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 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.
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.
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.
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.
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.
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.
@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?
TheMopia 2 days ago
lol @ " use this one right here" in a soft voice
AlexandrePicotte1 1 week ago
but why it even takes 1,2,3 for first two lines of output
COD5252 1 week ago
"this" function is not necessary all the times ,just directly typing the method name will also do
COD5252 2 weeks ago
O crap we're down to less than 100k views... WE'RE THE ONLY ONES LEFT...
TheViolinCalamity 2 weeks ago in playlist Java (Beginner) Programming Tutorials 4
Comment removed
CollectivePreference 2 weeks ago
im gonna change the time to 4:5:6
look out we have a badass over here
Frostbiyt 2 weeks ago in playlist Java (Beginner) Programming Tutorials
Comment removed
gnanameena 1 month ago
Loled at 0:23: "Now what private means is that these variables are private.". Nice one :D.
MrYouMath 1 month ago 3
this is a pointer to object of current class you work on
devilazpl 1 month ago in playlist Java Programming Tutorials
which this
MacMusicMinecraft 1 month ago
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 1 month ago in playlist More videos from thenewboston
@sarab2009 research#
seriouslycantthink 1 month ago
@seriouslycantthink Thank you. Sorry for my bad English :P
sarab2009 1 month ago
@sarab2009 True.
docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html
cpuwiz14 1 month ago
raise the volume of your speakers and listen at 1:06 a weird bass sound =D
DevilOnHog 1 month ago
Damn: I've done this before and I'm still confused. It has been a while though :/
amydfu 1 month ago
Description: How to controll access to memebers...
MrEmil20 1 month ago
how are there 77 dislikes. 77!
agcummings11 2 months ago
lol about a thousand people give up every tutorial
HectorFaelisy 2 months ago in playlist Java Programming Tutorials
@HectorFaelisy Hahaaaa
Phenomof713557 1 month ago in playlist Java Programming Tutorials
Comment removed
Tiular 2 months ago in playlist Bucky's Java Beginner Tutorial :D
damn it, can't find ypaul123's comment...
lNUMPUN 2 months ago
If you are dyslexic and you are learning Java, I feel SO sorry for you.
JamEngulfer221 2 months ago in playlist Java Programming Tutorials 4
@JamEngulfer221 Capital letters why do they exist!!!! (deslexic and proud)
SnazzyShenanigans 2 months ago in playlist Java Programming Tutorials
This has been flagged as spam show
user MrEmil20;
if (likes > 10){ MrEmil20 = happy;
}
else{
user MrEmil20 != happy;
}
MrEmil20 3 months ago
Comment removed
MrEmil20 3 months ago
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?
ooojunkdnaooo 3 months ago
"meme"bers? lol
devvilboyy676767 4 months ago
How come this tutorial has 70 dislikes when the others barely even have 10? -_-
tehnoobguy1 4 months ago in playlist TheNewBoston - Java Programming
ahh object oriented lanuages.... FUCK YOU PYTON
hairybratwurst 4 months ago
how do you find useful methods like the "this" method, in java.
90cdowns 4 months ago
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 4 months ago in playlist TheNewBoston Java Playlist 9
@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 4 months ago in playlist TheNewBoston Java Playlist
@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"
m3talkid 3 months ago in playlist More videos from thenewboston
I love your videos, but you should really remove this one. It's going to be the cause of a lot of confusion.
walkerneo 4 months ago
"In the next tutorials I promise I'll be clearing this. up for you..."
hehe =3
VaginosaurusRex 5 months ago 2
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 5 months ago
@Jesteria78 yeah you're right
gr1mtoy6100 5 months ago
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.
DeanDip 5 months ago
@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.
RazorSRaider 5 months ago
BUCKY ROCKS!!!!
My Coding Improved!
ikemefunaikemefuna 6 months ago in playlist Bucky's Java Tutorial
5:28 LoL he made a pun.
UnearthlyXbox 6 months ago
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..
k022002 6 months ago
So basically, private overrides public, and this. overrides private?
Why didn't you just say so in the first place? :P
zerohourkevin 7 months ago
Hey you! click the like button this.second!
ro33han 7 months ago 130
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 7 months ago 44
@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.
sesshoumaru3st 1 month ago in playlist Java Programming Tutorials
"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?
TheMasterMind555 7 months ago 3
Apparently nobody really knows what this is.
seed419 8 months ago in playlist Bucky's Java Tutorial 2
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!
LyriiczBoii 8 months ago
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.
LOUIS11233333 8 months ago in playlist Java Programming Tutorials
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.
Gelicania 9 months ago
lets dislike for good. :(
hopefly he'll respond
im a beginner. bucky is way more expert than iam.
andradewa19 9 months ago
bucky u need 2 replace this video, as people pointed out.. your explaination is wrong. got lots of respect to you and your videos.
abdo15 9 months ago
Well at the very least bucky should reply with a comment and let us know what all the confusion is about...
seed419 9 months ago
Oh we should dislike this video se he will notice.. just saying he doesnt want to have video with LOTS of dislikes..
zedo28 10 months ago 2
Delete it please!!! and keep going. good luck. we will support you as long as there is sign of improving
tedtdu 10 months ago
bucky fix this bro
Mrjameslat 10 months ago
Bucky....please delete/redo this video to prevent confusion for beginners in Object Oriented Programming.
vinodsra 10 months ago
delete this video dude...and redo it
lalitmali 10 months ago
Agree. This (right this!) you got wrong.
daGrevis 10 months ago
i am getting answer as local variables after using this also...:(...
TheNaman1989 11 months ago
brow for this keyword you can find it...mistake can be happen
*****youtube.com/watch?v=VQkGdJ_fm0Y*******
diyathU 11 months ago
brow for this keyword you can find it...mistake can be happen
diyathU 11 months ago
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; }
d2smwar 11 months ago
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...
WAKEUPshift111 1 year ago
buckey said that local variable r preferred than method local variable when variable name is same
but reverse is happening with me
786avin 1 year ago
786avin 1 year ago
This was another great tuturial.
Pun intended.
Drizien 1 year ago
air
kld0093 1 year ago
nice video
gudboai 1 year ago
nice video
gudboai 1 year ago
Voice crack at 4:37 :D
xXChaosHavokXx 1 year ago
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?
90nizam 1 year ago
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).
digaum8754 1 year ago
Yes, what everybody else said regarding the use of THIS.
annasophia78 1 year ago
daawww
i don't get it
oliball123 1 year ago
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 :)
ErichLancaster 1 year ago
bucky.. your explanation is wrong in this video.. hope you correct this and upload it again..
karthikpandiyan 1 year ago
private means they are private?
noooo
(sarcasm)
joaoris 1 year ago
man you are explaining it all wrong and your explanation is really bad
skootergofast123 1 year ago
Your sense of humor tickles me -- makes the videos!
stephenlentz 1 year ago
Don't show this video to your employer. He'll fire you.
ybelyal 1 year ago 2
Thank you for explaing this!!!!! Wish my instructor would have told me why we use "this"... lol
mail4asim 1 year ago
exactly what specimon said
love you bucky keep em coming please
MohaSharpeyes 1 year ago
"this" refers to current object which in this case is the tuna class.
You can see Eclipse highlighting the fields of the current object.
jdubeau007 1 year ago
Lmao. I'm sure that was his tone, "Use THIS one, right HERE!" haha :)
SamaLovesGuess 1 year ago
"Public, private and this". Sounds like a sitcom to me.
megaelliott 1 year ago 4
Thank you
amberg1000 1 year ago
if i enter sec or minutes mor ethan 60 it does not replace em with 0 and prints em instead???
hammadkhalid 1 year ago
Check out the link below, it explains what exactly a THIS is in Java. bit.ly / ckalCx
Chankeypathak 1 year ago
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.
thecoast47 1 year ago
Everyone I think he gets the idea about what this is !!! idiots.
NomNomPlz 1 year ago
this.second refers to this class field
banebajonet 1 year ago
This has been flagged as spam show
this.second refers to 'second' field from 'this' class.
banebajonet 1 year ago
This has been flagged as spam show
this.second refers to 'second' field from 'this' class.
banebajonet 1 year ago
this.second refers to 'second' field from 'this' class.
good job anyway !
banebajonet 1 year ago
this.second refers to 'second' field from 'this' class.
good job anyway !
banebajonet 1 year ago
:))) u make me laugh every time i watch u'r tutorials , your sense of humor it's awesome :d
cirynelu 1 year ago
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
kumaramitme 1 year ago
" 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.
KE61090 1 year ago
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
after731 1 year ago
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????
thatsmamaluigitoyou1 1 year ago
" but hum" in the end ^^
Tsunaze0 1 year ago
What Bucky meant is : "this" changes value of instance var with value of method var...
TheSnakeleg 1 year ago
bucky i understand all in this video, except for THIS.
..i dont quite get it...anyways good tutorials man
NnamdiOrafu 1 year ago
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)
kripiyon 1 year ago
just great how you make us understand this, 5 books couldn´t tell me as good as you.
regards.
xrtze 1 year ago
THE BEST WAS to introduce one into the usage of "THIS" keyword! VERY NICE BUCKY! ;)
kibaszottkurvajutub 1 year ago
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
sim0332 1 year ago
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 1 year ago
@Nunjabes encapsulation :P
abovestand 1 year ago
This has been flagged as spam show
you stupid fucking spic
you just made 9000+ viewers more confused you incomptent fuck.
local variables are whats inside a method.
Scope variables are valid throughout the entire scope of a class
god you are a pathetic douche..and a shitty programmer.
ypaul123 2 years ago
@ypaul123 You are a complete asshole, you should be banned from the internet.
0121ryanh117 2 years ago 14
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,,,
Guildwars55 2 years ago 4
This comment has received too many negative votes show
you dumb kid
please apply basic english rules and accurate word spelling when you address one of my talkbacks
you inferior paki hindu
ypaul123 2 years ago
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 2 years ago
@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 2 years ago
@ypaul123 IDIOT!
RAZ4396 6 months ago
@ypaul123 Meh, go back living under a frikking rock, douchebag.
DaBananaboat 5 months ago
@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.
AccendoCerebrum 6 months ago 2
@ypaul123 you suck your the biggest douche on the whole internet.You probably comment on every video you see.
Asshole
supermonkeybot3000 6 months ago
not this that one
metal4life68 2 years ago
This has been flagged as spam show
Everybody commits a mistake.. c'mon... just a little misconception right... ^^, the keyword "this" usually access the class members/variables or properties within a class... :) Great Vids Bucky...
lugajohnpaul 2 years ago
Comment removed
lugajohnpaul 2 years ago 2
hmk25061984 2 years ago 32
@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."
JamesBecht 1 year ago
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'
arvindr21 2 years ago 3
lol..."this is like a little joke"...great, can't wait for this to be cleared up in the next tutorial......now...
LawenceCodye 2 years ago 2
this refer to Instance of the same class.
Buky remove this video.
rajeev16704 2 years ago
rajeev, you are right. This tutorial was so far so good. But because of THIS.....
kenjiokagmail 2 years ago
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!
zxz555 2 years ago
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)
specimon 2 years ago 104
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.
Zombiedevice 2 years ago 6
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.
cwieand 2 years ago 3
@specimon Thanks, that confused the hell outta me for a second. "What? 'this' referrers to the local scope?"
hectixx 1 year ago
@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 1 year ago
@JamesBecht :
Thats actually what I said. "This" refers to the object and therefore the object variables. Not the method or constructor variables...
specimon 1 year ago
@specimon "the keyword "this" is used to point towards instance variables (the class variables)"... definitely NOT "the class variables"... anyway :-)
JamesBecht 1 year ago
@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 1 year ago
@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.
JamesBecht 1 year ago
@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...
JamesBecht 1 year ago
Comment removed
David92N 1 year ago
@specimon u r wrong instance methods are NOT class methods
pinkpeppypepper 11 months ago
@specimon If you know Java, why are you watching?
TerranLol 8 months ago
@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 8 months ago
@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
specimon 8 months ago
@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.
N728BS 7 months ago
@specimon Yup.
Before you slam specimon, look up Oracle's Java tutorials regarding this. Do a search for "Using the this Keyword Java."
coderTrevor 7 months ago
@coderTrevor - thanks mate :)
specimon 7 months ago
3999 views :P
Great tutorials!!!
812Insane 2 years ago 4
@812Insane, you're my hero!!!! 4000th view
7777phoenix 2 years ago 2
I Agree with gaurav here as methods are using class's attributes which are modified using 'this' operator.
soninish 2 years ago
I understood the concept that you were putting across awesome once again cheers : )
zaneizane 2 years ago
this makes sense.
I like this.
I understand this.
this is cool!
LOL! this is a joke.
ytgodzilla 2 years ago
now i understand what 'this keyword does...
i really appreciate your tutorials..^^
'
bmarkrussel 2 years ago
yeah the this keywords explanation is not ok.
still, nice tutorials
TheMrSarasa 2 years ago
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.
hardstylepie 2 years ago
Comment removed
SoXaS13 2 years ago
if he is supposedly so retarded y would you even take your take time watch his video?
ilikechess1 2 years ago
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.
mikemcculley 2 years ago 2
i like all ur vids man! I downloaded everyone of them...1 to 45..pls move on to intermediate..and GUI's...tnx alot
delsuim 2 years ago
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.
gauravsinha200 2 years ago
u ROCK bucky
nai237 2 years ago 2
thxns for these java videos. they are the best!
dmitryx01 2 years ago 2
This will definitely can help me later on. when i started to study again^_^ more tutorials
janeuarymmiv 2 years ago
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.
fortissimoX 2 years ago 6
I was thinking the exact same thing...
SanityJsp 2 years ago
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.
fortissimoX 2 years ago 2