Java GETTER and SETTER tutorial to get and set Field Variables. Object Oriented Java Tutorial #9.2

  Рет қаралды 81,561

Smartherd

Smartherd

Күн бұрын

Пікірлер: 95
@blockbusterlatefees7713
@blockbusterlatefees7713 3 жыл бұрын
Perfectly explained. You actually show what happens to "pug" and where it gets replaced. Excellent! Thanks!
@minoanlight4545
@minoanlight4545 5 жыл бұрын
No one, I repeat NO ONE was able to explain this to me this well. Thank you so much, I do not know if I am dumb or what, but I struggled so much with this. I understand other Java concepts pretty well, but this one was a nightmare to me. I thought about giving up and setting the variables the other way forever, but I knew there would be situations where I would have to make variables hidden like this. Thank you, thank you so much.
@smartherd
@smartherd 5 жыл бұрын
Thanks a lot. keep learning and.... *** Donate to support my FREE work ( If you like my work ) -- Why donate? -- If you think my videos are better than paid courses on Udacity or Udemy, then you must donate. The donation is optional and should be voluntary. Patreon: bit.ly/patreon-donate UPI: smartherd@okaxis Paypal / Payoneer: sriyank123@gmail.com
@qaautomationcult3868
@qaautomationcult3868 4 жыл бұрын
Getters and Setters Getters and Setters are used to effectively protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value. getters and setters are also known as accessors and mutators, respectively. Please subscribe our youtube channel : kzbin.info/door/0xat537YITJbN_9GSMUALA Fb page : facebook.com/learn.automation.testing linkedin page : www.linkedin.com/school/14580724/admin/ website: www.qacult.com for various blogs and Upcoming Events
@qaautomationcult3868
@qaautomationcult3868 4 жыл бұрын
Getters and Setters Getters and Setters are used to effectively protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value. getters and setters are also known as accessors and mutators, respectively. Please subscribe our youtube channel : kzbin.info/door/0xat537YITJbN_9GSMUALA Fb page : facebook.com/learn.automation.testing linkedin page : www.linkedin.com/school/14580724/admin/ website: www.qacult.com for various blogs and Upcoming Events
@rockmusicvideoreviewer896
@rockmusicvideoreviewer896 2 жыл бұрын
@@qaautomationcult3868 Spam
@rockmusicvideoreviewer896
@rockmusicvideoreviewer896 2 жыл бұрын
@@qaautomationcult3868 Spam 2
@deepaknagadi
@deepaknagadi 6 жыл бұрын
I am a beginner and you have not given the basic explanation of "WHY" are we not supposed to access the variables DIRECTLY. That would certainly help in boosting fundamentals of a beginner like me. But overall good one. Thank you.
@smartherd
@smartherd 6 жыл бұрын
Well the are few things which Google can tell you. Rest will be taken care by my videos. :P
@qaautomationcult3868
@qaautomationcult3868 4 жыл бұрын
Getters and Setters Getters and Setters are used to effectively protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value. getters and setters are also known as accessors and mutators, respectively. Please subscribe our youtube channel : kzbin.info/door/0xat537YITJbN_9GSMUALA Fb page : facebook.com/learn.automation.testing linkedin page : www.linkedin.com/school/14580724/admin/ website: www.qacult.com for various blogs and Upcoming Events
@rockmusicvideoreviewer896
@rockmusicvideoreviewer896 2 жыл бұрын
@@qaautomationcult3868 Spam 3
@agosolsgaming4036
@agosolsgaming4036 2 жыл бұрын
The only video that i understood perfectly. subbed.
@smartherd
@smartherd 2 жыл бұрын
Awesome, thank you!
@erangachamini157
@erangachamini157 2 жыл бұрын
Can't we use set and get methods in different functions separately?
@nikhithanikki8413
@nikhithanikki8413 4 жыл бұрын
I have created a pojo class with setters and getters. In class A I have set the values and in class B I wanted to get the values . Kindly help me how to create object and get the values
@divyalakshmithota3444
@divyalakshmithota3444 4 жыл бұрын
Can you please explain how the getter and setter work in case when we enter values dynamically using input fields in run time...I mean how it will set the values? Will it take values directly from fields or from database?
@mervinlee450
@mervinlee450 4 жыл бұрын
Must we always use setter and getters? Can't we just retrieve the information directly from the database? I at times always get a null pointer exception with setter and getter...
@mathiasfantoni2458
@mathiasfantoni2458 4 жыл бұрын
I still don't get why we would use getter and setter way instead of just setting the variables public? What is the computational benefit of mutating them with methods rather than directly?
@KD-xi9wu
@KD-xi9wu 3 жыл бұрын
Sir what's the advantage of setter and getter over directly accessing variables using dot operator ( . )???????
@smartherd
@smartherd 3 жыл бұрын
Abstraction and encapsulation
@maizazuddin6560
@maizazuddin6560 7 жыл бұрын
Awsum Work .. actully i am learning through another persons video tutorial , but when i got stuck in any thing , always found solution in your tutorials , so simple yet so clearing .. Awsum work love from Pakistan .
@kingsley15
@kingsley15 5 жыл бұрын
Your variables should be *private* .
@MK-qz7sg
@MK-qz7sg 5 жыл бұрын
why?
@kamalanb6930
@kamalanb6930 5 жыл бұрын
@@MK-qz7sg getters and setters are mostly used to provide data values to private variable. To access data from public variable and provide it to a private variable we use getter and to set a value we use setter.
@masbro1901
@masbro1901 4 жыл бұрын
@@MK-qz7sg for encapsulation.
@nitish2808
@nitish2808 2 жыл бұрын
How do I access a protected getter setter in another package in Java?
@boominathanarumugam5589
@boominathanarumugam5589 6 жыл бұрын
you explained very well no doubt but you have additionally include what is the use of this method and why we are using these type of methods in java because we have learned these types of concepts but where it will be used in right way we don't know so i hope you will explained in future videos
@muslimquotesofficial
@muslimquotesofficial 6 жыл бұрын
U said it ...he should clearly explain the reasons
@xxxx-kv9ei
@xxxx-kv9ei 5 жыл бұрын
ok these are used ideally in game development but can be used for other purposes to it. most importantly you guys need to go ask yourselves a question and solve it. Thats how you learn programming, it is not learned by just listening. for example if I were to learn SQL, i would need to ask myself, Use adventureWorks2014 and Get me all the sales which has more than 5 products, get customer details, the dates should be UK format. and make a full name. when trying to answer that question, in the process I will learn SQL. so you guys need to go out and make scenarios in your mind and try to solve them.
@ujwalareddy-n7b
@ujwalareddy-n7b Жыл бұрын
Awesome, Explanantion.🙌🏻
@juandavidgomezrestrepo6110
@juandavidgomezrestrepo6110 2 жыл бұрын
Thanks my friend really well explained
@chandrasekhar6362
@chandrasekhar6362 4 жыл бұрын
can we set the values in one request and can we retrieve in other request?
@hardikseth9640
@hardikseth9640 2 жыл бұрын
fantastic explanation and simple and to the point
@emekamgbemere1801
@emekamgbemere1801 4 жыл бұрын
I can't thank you enough. You understand this and it's obvious in your explanation. Thanks.
@amitkadam2354
@amitkadam2354 2 жыл бұрын
is getBreed() contains the value of breed
@tejaslokhande6452
@tejaslokhande6452 6 жыл бұрын
Sir But anyone can access our data if he reads our code even if we have Encapsulated. Then how it works please help?
@rushabhoswal8280
@rushabhoswal8280 7 жыл бұрын
getter and setter are used to access private field using public method right? Then can we access private methods using the same strategy?
@rushabhoswal8280
@rushabhoswal8280 7 жыл бұрын
Great videos!I am learning java through your everyday modules 😃! Can getter and setter be static method?can it be another than public?
@smartherd
@smartherd 7 жыл бұрын
The purpose of Getter and Setter is to be public or sometimes protected. But not private. and you can access private methods by calling a public method from outside the class.
@rushabhoswal8280
@rushabhoswal8280 7 жыл бұрын
Why to access private variables using public method?whereas we can access public field easily?
@smartherd
@smartherd 7 жыл бұрын
Thankyou, You can provide me feedback to make my videos more clear and better. or if you find any better video on youtube then let me know.
@smartherd
@smartherd 7 жыл бұрын
thats for this video was all about. Its always better to access field variables using getter and setter instead of doing it directly. The more in depth reason you will get to know while doing projects.
@mithunchandrasaha403
@mithunchandrasaha403 3 жыл бұрын
Nice Explanation.Sir
@simm5622
@simm5622 3 жыл бұрын
Nicely explained 👍
@masbro1901
@masbro1901 5 жыл бұрын
for what reason we should not access the variable directly ?
@lokeshdohare4872
@lokeshdohare4872 5 жыл бұрын
mas bro it's a instance variable, u cannot access instance varaibles directly inside a method.. U either make object of that class and access it using reference variable or use getter and setter method as explained in video.
@theoriginyt4869
@theoriginyt4869 4 жыл бұрын
Coming from C++ and C#, I see no point in using these at all. Just use the field directly for even a better performance. Or use C# to specify if a variable should be only set privatly or be accessed by public...
@bushratarif6028
@bushratarif6028 3 жыл бұрын
Wow, amazingly explain!
@xxxx-kv9ei
@xxxx-kv9ei 5 жыл бұрын
For those asking "tell us how to use it". ok these are used ideally in game development but can be used for other purposes to o. most importantly you guys need to go ask yourselves a question and solve it. Thats how you learn programming, it is not learned by just listening. for example if I were to learn SQL, i would need to ask myself, Use adventureWorks2014 and Get me all the sales which has more than 5 products, get customer details, the dates should be UK format. and make a full name. when trying to answer that question, in the process I will learn SQL. so you guys need to go out and make scenarios in your mind and try to solve them.
@srilekham8288
@srilekham8288 4 жыл бұрын
its not alternative method for using getter and setter methods.They are used when the variables are private
@milankbudha
@milankbudha 4 жыл бұрын
thank u so much..it was easy to understand
@sarmadnadeem_
@sarmadnadeem_ 6 жыл бұрын
Ma Sha Allah ... Very Helpful indeed :) Thank you !
@smartherd
@smartherd 6 жыл бұрын
Thanks, dont forget to visit our website www.smartherd.com/
@anwar6971
@anwar6971 3 жыл бұрын
Explained so well. Thanks
@sanilasabu5864
@sanilasabu5864 4 жыл бұрын
Well explained
@Student-zc7hb
@Student-zc7hb 3 жыл бұрын
Thnks.... simplicity...
@shahriarmim4696
@shahriarmim4696 6 жыл бұрын
Awesome Explanation. (Y) Very good ! but, isn't should be in code at 2:25 dog1.setBreed("pug");
@smartherd
@smartherd 6 жыл бұрын
Yes. But here as mentioned at 2:29 that here pug is a string variable.
@IdlanRafiqi
@IdlanRafiqi 4 жыл бұрын
Then, what is the correct code? dog1.setBreed("pug"); or dog1.setBreed(pug); ?
@prostudioapp6265
@prostudioapp6265 6 жыл бұрын
Error:(17, 20) error: Cannot find getter for field. sir ihave 3 erore
@cheshvikaraj7769
@cheshvikaraj7769 2 жыл бұрын
nice explanation
@mahirbird9071
@mahirbird9071 5 жыл бұрын
Good explanation. Thanks
@itheblackwolfofmyfamily
@itheblackwolfofmyfamily 6 жыл бұрын
wow it you have an amazing tutorial in java. I have learned a lot. Keep the good work brother!!!
@smartherd
@smartherd 6 жыл бұрын
like and comment for each video. It helps us to grow. thanks alot
@jaibharatmata8921
@jaibharatmata8921 4 жыл бұрын
Wow really nicce
@Iamnabink
@Iamnabink 6 жыл бұрын
awesome video..Thanks for this kinda video..Keep it up.we love you
@himanshuyadav5007
@himanshuyadav5007 3 жыл бұрын
But why this is not the way to it ?
@salwas.alsubhi7013
@salwas.alsubhi7013 6 жыл бұрын
Thank you, it's very Simple and helpfull
@smartherd
@smartherd 6 жыл бұрын
thanks alot.. your comments are my motivation
@abdulraffay1950
@abdulraffay1950 6 жыл бұрын
Man i love you !!! Thank you so much !!!
@feifortisvids3508
@feifortisvids3508 3 жыл бұрын
Thank you
@SaiKiran-xf4hx
@SaiKiran-xf4hx 3 жыл бұрын
But u didn't say why???
@Mr_Unfazed0
@Mr_Unfazed0 6 жыл бұрын
Thanks a bundle sir 🙌 😃
@Persian771
@Persian771 6 жыл бұрын
Very good thanks.
@smartherd
@smartherd 6 жыл бұрын
thanks alot.. your comments are my motivation
@jeevan4337
@jeevan4337 6 жыл бұрын
You or anyone please help me in this case? Will getter setter be useful here or someother approach? stackoverflow.com/questions/52953005/how-to-pass-values-in-java-from-one-class-to-another
@flaasher
@flaasher 6 жыл бұрын
Good job ...
@smartherd
@smartherd 6 жыл бұрын
Thanks
@notatall1944
@notatall1944 5 жыл бұрын
thanks
@praveenkumarelangovan9781
@praveenkumarelangovan9781 6 жыл бұрын
Play the video in 1.25x speed u will not get bored
@smartherd
@smartherd 6 жыл бұрын
I prefer 1.5x
@akashshrestha01
@akashshrestha01 5 жыл бұрын
Cool
@UsmanAli-gb4bn
@UsmanAli-gb4bn 6 жыл бұрын
perfect
@smartherd
@smartherd 6 жыл бұрын
thanks a lot
@vaishnavinalawade9904
@vaishnavinalawade9904 5 жыл бұрын
Liked....
@AttitudeShorts386
@AttitudeShorts386 5 жыл бұрын
Bhai i need your attention
@Josephine-ih8xw
@Josephine-ih8xw 7 жыл бұрын
Thank u
@smartherd
@smartherd 7 жыл бұрын
+josephine maria thank you
@ratmirsusanin5496
@ratmirsusanin5496 5 жыл бұрын
молодец
@BoonkiCoC14
@BoonkiCoC14 2 жыл бұрын
This is why i think java is so dumb. The getter and setter are doing exactly the same thing as the first code.
@rockmusicvideoreviewer896
@rockmusicvideoreviewer896 2 жыл бұрын
This is really a very horrible answer (your reply to some in the comments). If you come straight out and tell us in your video that one way is not a good way and to use a 2nd way instead, you better tell us why. Telling us in a comment to google it is wrong. Humble yourself and explain it in the comment and don't be afraid to admit when you are wrong. Otherwise you come off as someone that only cares about his own ego.
@ajithk2183
@ajithk2183 4 жыл бұрын
Thank you
@kairiannah
@kairiannah 6 жыл бұрын
thanks
@smartherd
@smartherd 6 жыл бұрын
Welcome
Part 5. Roblox trend☠️
00:13
Kan Andrey
Рет қаралды 2,9 МЛН
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
SIDELNIKOVVV
Рет қаралды 4 МЛН
Крутой фокус + секрет! #shorts
00:10
Роман Magic
Рет қаралды 40 МЛН
Getters & Setters | Java | Tutorial 31
17:49
Giraffe Academy
Рет қаралды 110 М.
Java Tutorial for Beginners: METHODS and FUNCTIONS Part-1 #8.1
10:05
JavaScript Getters and Setters Explained
9:11
Colt Steele
Рет қаралды 21 М.
THIS Is How You Should Be Making Getters & Setters In Python
7:32
Dependency Injection, The Best Pattern
13:16
CodeAesthetic
Рет қаралды 850 М.
Encapsulation in Java - Getter and Setter Methods with Code and Examples
17:43
Getters and Setters Java Tutorial #84
14:12
Alex Lee
Рет қаралды 501 М.
Part 5. Roblox trend☠️
00:13
Kan Andrey
Рет қаралды 2,9 МЛН