#42 This keyword in Java
Vložit
- čas přidán 29. 08. 2024
- Check out our courses:
Enterprise Java Spring Microservices: go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-sp...
Coupon: TELUSKO20 (20% Discount)
Udemy Courses:
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
Java For Programmers:- bit.ly/javaPro...
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusk...
In this lecture we will see:
- Instance variable and Local variable
- Can we declare two or more variables with the same name?
- This keyword and its uses in Java
#1
Instance variable:- These variables are declared within a class but outside a method.
- These variables are created when we create an object and are destroyed when the object is destroyed.
Local variable:- These variables are declared within a method but do not get any default value.
- They are created when we enter a method or constructor and get destroyed when the call returns from the method.
#2
In Java, it is not allowed to declare two or more variables having the same name inside a scope either in class scope or method scope.
- The preference is always given to the local variable.
- Creating an object is not a good idea to solve the issue of conflicting names of instance and local variables.
- We can differentiate between local and instance variables by passing an object itself.
- Instead of writing and passing an object, we can simply use this keyword.
#3
This keyword:-
This keyword represents the current object.
- Current object is an object which is calling the method.
- This keyword is used to invoke the current class constructor.
- Using the 'this' keyword, we can return the current class instance.
- This keyword can be used as an argument in the constructor call.
Github repo : github.com/nav...
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com
bro used entire 9 minutes just to define a single keyword , this shows he wants us to learn deeply 🙇🔥
while learning java i had realised that java is easier than java script bcoz in java script to explain the this keyword it will take easily an hour.
I was learning java for project requirement and this video saved my life to understand this in java it is weird but understood :) No one can escape this three languages in their life java, python and js
00:02 Understanding the 'this' keyword in Java
01:14 In Java, the stack memory and heap memory are used for different purposes.
02:27 Local and instance variables with the same name in Java
03:43 Assigning a variable to itself in Java can lead to unexpected behavior.
04:55 In Java, 'this' refers to the current object instance.
06:04 Creating a new object may cause issues with assigning values.
07:19 Passing object references and differentiating between instance and local variables in Java
08:36 The 'this' keyword represents the current object in Java
Excellent way of teaching.
Pushes us to wrong path only to make us understand the right path. Thank you.
Iam here from JS and i know the function of this keyword but when i was a beginner it was a huge headache for me. But after this video I can clearly state that Navin reddy sir aka telusko is one of the best teacher ever. Genius, the way he explained about this keyword..
Amazing Explanation sir. Trying out different possibilities and explaining really nice
Like me a person love details and how things works. I watched alot of tutorials about java and difficult topics like consturtor and this keyword,implicitly I understand it but I can't move without understanding initial way for things work. Your explaining with more fantastic details and different way, you are amazing . Thank you alot my teacher
Best explanation ever!
I can't thank you enough for these amazing tutorials sir.
The best Java teacher I have ever seen. Explanations, Examples are perfect
I watched many videos to understand how this keyword works, but none of them helped me. This video cleared all my doubts and questions. Thank you, sir, for this lecture!
THIS is the only time I have ever understood the THIS keyword. Thank you so much!! So does that mean that the This keyword is only used in NON-STATIC methods?
Your way of explaining things is fantastic. Thank you.
I literally clapped when this was used at last
Thankyou sir ❤ keep teaching us like this. More respect to you sir.
you are excellent at java concepts
This video shows your passion towards teaching, great work sir, I'm impressed 👏🏼
Take simple example
bro why do you look so humble ❤️ thanks for the videos anna..!!
Can we say that constructor return this that is why we can use to access instance variable
Like
Human obj = new Human();
//Human(); It is constructor call
Hey Navin sir! Your fan from Nepal!
best explanation
quality content fr🙂
Thanks a ton sir, now the confusion got cleared for me for THIS keyword…. Your explanation is irreplaceable…🥰🥰🥰🥰🥰
Great way of explanation
Wow great concept Thanks you so much❤
hi Navin , pls make a video on passing this keyword into methd arguements and passing this keyword as arguments in parameterised constructors
Perfectly explained. Thank you.
brilliant explanation
Grateful for this Playlist ...thank you!
Thanks for the explaination Sir.
Happy teacher's day sir🎉🎉🎉
I really helped me in understanding this, thanks ❤
Excellent explanation ,thanks😊
Java means Telusko ❤
Can anyone one help me to understand ?
I didn't understand at this "when we call age function we are passing the value ?👀 But why the heck we did we get zero, what's happening if we mention local and instance variable as same name ?
Thanks Naveen 🔥 Big fan 💥
Super sir
one doubt, if we are not using this key word and just using two different variable names..will it work?
yeah it will work
What do you mean by the current object !?
I think you are asking it for this keyword am I correct? if that is your question, Then whenever you create an object it cannot use the variable directly so we need to use methods to access it, when you create an object to modify those values using methods those object are the current object for the "this" keyword (this is not a correct answer this is what i understand so far)
No, I sometimes didn't get what he meant, :D I understood about this keyword, I know It refer to the current class object, we use in many ways, for builder pattern and for constructor to set the values so we define it and distigawise between local and global var, I don't care much much he don't explain the internal thing, so for refresh it is fine but not for the real knowledge. @@karots77
great teacher love you
Lil bit confusion sir.
varayyo vammo...entha baga cheppav babai.
line 30
obj.setAge(age: 30); // how did he type this inside the bracket--> age:
Inlay hints added by vs code (not a part of the code)
Not written by me.
@@Telusko oh, I'm learning java using Eclipse which is why I was unaware..thanks bro..
we cant call local variable outside of its local context
That's a lot of THIS😂
🙏❣
sir khud he kyu padh rahe ho