Encapsulation in Java Tutorial #83

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024

Комментарии • 292

  • @alexlorenlee
    @alexlorenlee  Год назад +2

    If you’re new to programming but want a career in tech, I HIGHLY RECOMMEND applying to one of Springboard’s online coding bootcamps (use code ALEXLEE for $1,000 off): bit.ly/3HX970h

  • @latedeveloper7836
    @latedeveloper7836 3 года назад +92

    Yet another excellent explanation. Timestamps below for anyone who needs them:
    1:00 Definition of encapsulation
    3:03 How to use encapsulation with getters and setters
    3:17 What static means
    5:19 The point of encapsulation - extracting variables from the user
    9:22 Summary of what encapsulation is

  • @alexanderderictapalla58
    @alexanderderictapalla58 4 года назад +243

    You're a magician. You made every topics in Java understandable. Like wow. Just wow. Thank you very much!

    • @comcfi
      @comcfi 4 года назад +2

      For sure

  • @java_tech_guru
    @java_tech_guru Год назад +4

    When we create a class with private members. What we are actually trying to do is create a user defined data structure. It helps us to store the data privately. It prevents direct access.

  • @mrblobby1841
    @mrblobby1841 3 года назад +30

    Useful to note: most setter methods would include validation logic and checks. For example, check that age is greater than X for a student.

  • @Nanis-World
    @Nanis-World 2 года назад +12

    Alex, you've helped me get through all of the Java courses for my computer science degree. Thank you so much for the time you've put into making these videos and for helping me understand what my "teachers" are getting paid to do but failed miserably at!! 😊

  • @joethompson8147
    @joethompson8147 3 года назад +11

    In IntelliJ you can right click in the Student.java class, choose "Generate", choose "getter" or "Setter" and IJ will write the methods for you.

  • @ndyer6005
    @ndyer6005 4 года назад +4

    You explained so clearly and precisely what my instructor took 2 hours explaining. I also enjoying copy-coding with you and then modifying my methods and variables for practice.

  • @mrpickles1
    @mrpickles1 3 года назад +32

    I'll eat my shirt if there's anyone out there who can explain java better than alex
    My college lectures are incomprehensible and i fall asleep 9/10 times.

    • @adamdreier
      @adamdreier 3 года назад +3

      That’s why I didn’t go to college hahaha, some dude on RUclips explaining it better than a University lmao 🤣

  • @benanikin4388
    @benanikin4388 4 года назад +1

    Bro you're a life saver! 10 mins of your content worth more than 2 hours with my professor

  • @mariaolsson1458
    @mariaolsson1458 3 года назад +1

    This really made a difference to me. Now I know what I did have so much trouble to understand about Java, it was Encapsulation. And now Alex explained how it works. Thank you!

  • @mariyaqureshi6800
    @mariyaqureshi6800 4 года назад +6

    I wish I found this channel when I was in my java class. You explain it so clearly!

  • @megabubbles9478
    @megabubbles9478 2 года назад

    You teach in a very calm and peaceful manner it’s kinda relaxing to watch you teach

  • @lahirudamianperera6255
    @lahirudamianperera6255 4 года назад

    Thanks man ♥️java is in ur blood...I thought of giving up java....but ur way of teaching changed mee...thanks dude

  • @tanjimashraf803
    @tanjimashraf803 4 года назад +1

    You make the complicated topics so easy to understand. Thank you so much.

  • @delzyfire7209
    @delzyfire7209 4 года назад +19

    please keep do what you are doing.I'm learning soo much thanks to you

  • @sunkistzerosugar
    @sunkistzerosugar 4 года назад

    Currently in 2150 programming and my professors have been pretty iffy at explaining the terminology and what is actually going on but damn man you make this as clear as day.

  • @troubledtom5250
    @troubledtom5250 2 года назад +1

    thanks i was trying to understand from that one programming book my teacher recommended to me but couldn't understand much except for the different classes bit ,so really glad i clicked on your video thanks alot man your a life saver.

  • @WittySpirits
    @WittySpirits 3 года назад +1

    The best short definition of encapsulation and fantastic explanation. Great video Alex.

  • @maxd7228
    @maxd7228 4 года назад +1

    Also setters can be used for validating the data type. If you send a int to a String your program crashes but using the setters you can catch that and throw an exception or perform additional actions on the passed value to reformat before storing the value.
    Great vid as always.

    • @welltypedwitch
      @welltypedwitch 4 года назад

      That's not how java works, but for sonethibg like JS or Python, thos may be quite useful. Java is statically typed, so your compiler will conplain, if you try to pass an int to a function that expects a string

  • @duongvuong8514
    @duongvuong8514 2 года назад

    OMG, what you said, I deeply felt it. I went through a whole semester without knowing what OOP is, got 50% on final but still ended up with a B. I swear, in that online class I did everything I could, look for all explaination both from online and from her but I still didn't get anything. Now it just came to me after 5 mins watching you lol. Thank you, thank you, thankyou!

  • @Fiwsh
    @Fiwsh 2 года назад +1

    Very helpful for my final exams, apprecitaed sir.

  • @darrenjosiah9246
    @darrenjosiah9246 2 года назад +1

    3 weeks ago OOP was a foreign concept and I dreaded it. Now I'm mastering it and ready for an interview!

  • @samael5653
    @samael5653 3 года назад

    thanks of what you are doing i will maybe have the 99% more chanche to pass my exam... thank you Alex ! you're amazing!!!

  • @supernovic99
    @supernovic99 Год назад

    I'm currently preparing for the AP CSA on my own and your videos are literally the reason I'm confident for the exam. Thanks a lot!!!

  • @An_American_Boy
    @An_American_Boy 2 года назад

    Arigato.
    You've done the work so easily that it had made difficult for others to do.

  • @luiso3482
    @luiso3482 4 года назад +4

    Alex, you rock! You have the gift of teaching. Keep it up and thank you for spreading your knowledge.

  • @bozhidarkn
    @bozhidarkn Год назад

    My man! These are some of the best explanations I have found regarding programing. Not just Java but Programing in general.
    Please share a PayPal or Patreon or other page where I can support you directly. I will not be purchasing the linked products or the full course (which I am completely sure is wort every penny and I will most definitely recommend to any folks looking to learn Java) but I still want to buy you a drink the least!

  • @koushikpaul5957
    @koushikpaul5957 4 года назад +1

    I had a lot of difficulty with this at first, you made this a lot simpler than I thought it was. Thanks!

  • @MrAc3528
    @MrAc3528 4 года назад +27

    Hey Alex could you possibly make a video on the merge sort algorithm?
    You’re the best java teacher on RUclips and if you explained it I know for sure I would comprehend it. Thanks man.

    • @Monster33336
      @Monster33336 4 года назад

      Java is so hard you might need an expert for specifics.

    • @scholli99
      @scholli99 4 года назад

      @@Monster33336 youre making fun about java? Dude did you ever developed software professionelly ? Java is pretty complex language.

    • @Monster33336
      @Monster33336 4 года назад

      @@scholli99
      just that Java is a nightmare when working with real objects not just system.out.println

    • @shashankshetty5879
      @shashankshetty5879 4 года назад +8

      You both are making it hard for starters like me to learn the language . No problem if it is hard or complex I will learn 👀

  • @acelyaerdogan2222
    @acelyaerdogan2222 4 года назад +4

    Wow you make it seem so simple and understandable - super grateful to have found you; your videos would literally be how I will pass my end of year Java exam. Thank you! Looking out for your videos - keep striving!

  • @amasaadi382
    @amasaadi382 Год назад

    you're a life saver man, wish you all the best😊😊

  • @dee23gaming
    @dee23gaming 4 года назад +3

    Google can't explain this as well as you do. I just end up scrolling through complex "examples". I also like how you explain why you type the keywords in the methods. Keep up the nice work, really do appreciate it

  • @williamparker382
    @williamparker382 4 года назад +5

    This is awesome and so simply explained!

    • @mormsophen3238
      @mormsophen3238 4 года назад

      Yeah. It is too simple or maybe i already familiar with set and get

  • @AoDShotZz
    @AoDShotZz 2 года назад +1

    You’re such a huge motivator! You make things possible to understand. Thank you

  • @novalandinc.1345
    @novalandinc.1345 4 года назад

    Thank you Alex. You Made learning Encapsulation easier

  • @batoolali3529
    @batoolali3529 Год назад

    i am so thankful that your channel exist thank you for sharing your time and effort
    love the way you present the ideas

  • @joethompson8147
    @joethompson8147 3 года назад +20

    5:30 "The point of encapsulation is to abstract the variables from the user to make it easier to use the object."

  • @java_tech_guru
    @java_tech_guru Год назад

    When it comes to encapsulation. Mostly people talk about creating private instance variables and adding public getters, setters methods.
    That is true.at the same time we need to understand one thing.
    That is creating the data structure with required fields to store the data privately.

  • @darrenbisin5974
    @darrenbisin5974 3 года назад

    Please Continue Making Java Tutorials In RUclips, You're Amazing In your tutorials 👍💖

  • @harshasuresh4062
    @harshasuresh4062 2 года назад

    When I say you are a lifesaver, I mean it!!! Thank you Alex ❤

  • @naweedmohammadi7909
    @naweedmohammadi7909 3 года назад +1

    Your explanation was amazing Alex, the most understandable explanation ever keep it app bro

  • @digby2263
    @digby2263 2 года назад

    Thankyou so much I was falling behind on our lessons this past few weeks and having a hard time on understanding how to use encapsulation, since I was ill of covid❤️

  • @anthonyakamook
    @anthonyakamook 3 года назад +1

    Thank you, this made perfect sense for me!

  • @farahbalbaa1266
    @farahbalbaa1266 Год назад

    Hey Alex , first of all thank you for your easy and simple explanation in addition to your calmness.
    Second thing is , Can you tell me how to write (System.out.print();) without writing it all as you did in the video please?

  • @wiktorsobczyk6547
    @wiktorsobczyk6547 4 года назад

    best teacher ever

  • @drsgonborn
    @drsgonborn Год назад +1

    setters and getters are the simplest funcionts in OO, but for someone who has never seen codding it sooooo damn hard to *click* in the brain, but when it does oooooh if fells good

  • @mp7596
    @mp7596 2 года назад

    Alex, this was a great explanation. I am studying for an assessment for an entry-level job, so thank you

  • @Glennyates1025
    @Glennyates1025 2 года назад

    You have a gift. Very clear and enjoyable. Well done!

  • @asimenibhavya6423
    @asimenibhavya6423 4 года назад +1

    You just made my life very easy in learning and understanding java concepts! THANK YOU! (Y)

  • @hamsal_khaldi7851
    @hamsal_khaldi7851 3 года назад

    amazing teacher, I am I the only one who doesn't understand from the uni lecture or there are others having the same problem? because this is so simple why in the lecture seems so hard like its a chemistry! Thank you for the logic easy example

  • @danujagreru
    @danujagreru 4 года назад

    keep going, dude. it's very simple to understand

  • @albarsalan4173
    @albarsalan4173 3 года назад +1

    Thank you man for your great efforts. I believe you are one of the best on RUclips keep up the good work.

  • @tanveerahmad8455
    @tanveerahmad8455 3 года назад

    after many lecture watched finally u satisfy me ->🥰Thanks Alex

  • @AlexOlivares471
    @AlexOlivares471 4 года назад +5

    Damn dude, great explanation. Now I might pass my Java exam tomorrow, thanks!

  • @bhanupriyatham668
    @bhanupriyatham668 3 года назад

    simply awesome man .......... love from india

  • @zed-shasw
    @zed-shasw 3 года назад

    You are a genius teacher.

  • @info-prog
    @info-prog 2 года назад

    Alex Lee, you are a real Bruce lee of Java. Thaks a lot for this n all ur videos.

  • @mohamedawnallah2957
    @mohamedawnallah2957 4 года назад

    It is very Better To put Constructor instead Setters as Constructors get called once we create object so that will be easy for user.Your Explanation is wonderful Continue....

  • @le_travie7724
    @le_travie7724 3 года назад

    Annnnd subbed! You're way better at explaining this than my profs. Cheers m8

  • @Nas_Vinspired
    @Nas_Vinspired 4 года назад +1

    Thank you for the very helpful and easy to understand video content, man!

  • @rittenbrake1613
    @rittenbrake1613 4 года назад +1

    very clear Thanks Alex

  • @tjake7864
    @tjake7864 4 года назад

    Nice work Alex!

  • @daisymangue9130
    @daisymangue9130 3 года назад

    everything is easy with Alex....i have hope in java bcz of u

  • @Blackronin357
    @Blackronin357 4 года назад +3

    Really great tutorial, can't wait to see what else you have to teach. I was following along well enough and ran into a snag w/ the encapsulation between the two classes. I'm thinking its because I'm using a different IDE (intelliJ) that doesn't have the same robust options when it comes to creating a new class. Going to try with the IDE your using an see how it goes from there. Nonetheless, I still was able to understand what went where and why.

    • @Blackronin357
      @Blackronin357 4 года назад +1

      Ran the test code in Eclipse IDE and it went through as it should. Wondering what difference the IDE settings make? Only thing I can think of is that there was a confirmation request to run both classes in Eclipse where as it seems intelliJ only wants to run one. Wondering what it should be set as to allow both?

  • @matthewmarchman8885
    @matthewmarchman8885 Год назад

    Love how you explain these concepts 💯

  • @Iloveanimalssmh
    @Iloveanimalssmh 2 года назад +1

    thank you god bless u this is really helpful

  • @TomJamesM
    @TomJamesM 4 года назад +2

    Hey Alex, Thanks so much for your videos. They're really helpful!

  • @jimbosliceOG
    @jimbosliceOG 3 года назад

    You’re an excellent teacher

  • @mempi9514
    @mempi9514 3 года назад

    Hi, you are really good explaining java material. I am grateful to have found you

  • @aintdistinct
    @aintdistinct 7 месяцев назад

    precise and easy way to explain it, ty💯

  • @ersinkarakulak3225
    @ersinkarakulak3225 4 года назад +3

    Hi, you're amazing. Im learning Java with you :) Firstly I tried with turkish channel but i didn't. We are waiting Pyhton, C++... THANKS

  • @achraferraji3403
    @achraferraji3403 4 года назад +6

    I think those who make Dislike are the teachers you've talked about

  • @ramvenkatvuddanti8233
    @ramvenkatvuddanti8233 2 года назад +1

    Hello Alex i'm studying in udemy just watched your videos for reference, but now i think i should use the udemy for reference.LOL

  • @sanan495
    @sanan495 2 года назад +1

    Alex return back. We need java tutoring classes. If u read this just confirm it

  • @viniciusbrisotti9848
    @viniciusbrisotti9848 4 года назад

    Great explanation bro! You presented the concept in a very simple language

  • @moniashelli9502
    @moniashelli9502 4 года назад +1

    thank you for explaining this, i actually thought it was complicated

  • @saintz2k7
    @saintz2k7 4 года назад

    Hey Alex I love you and you videos, you truly are a hero among men...would you please think about making a video explaining the JRE, JVM, SDK, IDE, Java Library etc. These are very confusing topics but are necessary foundations for people using JAVA. I would really appreciate that. Also do you have a patreon account? I think you deserve to be rewarded by us for the tireless and amazing work you do

    • @yxcv22
      @yxcv22 4 года назад

      That would be really nice

  • @ahmedelsleet8542
    @ahmedelsleet8542 2 года назад

    carrying me in my java course! thank you

  • @spicebowl6325
    @spicebowl6325 4 года назад +6

    Thank you so much. Keep going.... 🙏

  • @tonynork7931
    @tonynork7931 2 года назад

    Great and simple explaining👍

  • @anvarbekziyodov
    @anvarbekziyodov 4 года назад

    bunch of thanks Alex, you made my day

  • @Pandaputih2000
    @Pandaputih2000 Год назад

    I'm glad found this video. Learnt alot.. Thx

  • @mikebrown5142
    @mikebrown5142 Год назад

    Awesome vid, your explanations are spot on. God bless!

  • @rehpotsirhc21
    @rehpotsirhc21 2 года назад +1

    the thing im struggling to understand is what the actual purpose is of the private variables if you are just going to expose a method which can change the value. ill have to dig around more and see what I can find. The only thing ive found so far is not expose to a user but not sure what that means lol

  • @brandonbelcher1002
    @brandonbelcher1002 2 года назад

    Very concise and useful. Thanks so much!

  • @shenfdo8779
    @shenfdo8779 3 года назад

    Nice explanation Alex, and Thanks 😊

  • @mehdimah2760
    @mehdimah2760 4 года назад +1

    Thank you Alex.

  • @pablofalco
    @pablofalco 4 года назад

    Finally I get this...Thank you!

  • @johnpaulbarrios5359
    @johnpaulbarrios5359 3 года назад

    Thankyou so much dude you really help me for my exam From: Philippines

  • @SSracer192
    @SSracer192 3 года назад

    Thanks Alex for creating these videos, keep it up!!

  • @adamameen5
    @adamameen5 2 года назад

    He nailed it 🔥

  • @tlo0542
    @tlo0542 3 года назад

    excellent explanation. Helped me alot. thank you.

  • @futgaming17
    @futgaming17 3 года назад

    your content is amazing bro

  • @javlontursunov6527
    @javlontursunov6527 2 года назад +1

    Bro thank you so much

  • @MaurianeBanza
    @MaurianeBanza Год назад

    Thank so much my favorite teacher

  • @darkhead612
    @darkhead612 3 года назад

    Thx for that shortcut!!

  • @starmehari2071
    @starmehari2071 3 года назад

    Thanks a lot Alex it is really helpful.

  • @evanpoole7829
    @evanpoole7829 Год назад

    Amazing video even for non java developers. Gone are the days of watching people write generic pseudo code about cars, thanks for actually explaining it in context yet still going into the theory for computer science students.

  • @AMANSINGH-yv4vv
    @AMANSINGH-yv4vv 3 года назад

    Nicely explained as usual - u r great man