Java encapsulation 💊

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 201

  • @garrickreynolds2015
    @garrickreynolds2015 3 роки тому +67

    I’ve been watching your videos to help in my programming 3 course and I feel like you simplify everything so well, I’ve really had a breakthrough in my understanding of certain concepts after watching your explanations. Thank you for your work!!

  • @BroCodez
    @BroCodez  4 роки тому +87

    //*************************************************
    public class Main {
    public static void main(String[] args) {

    // Encapsulation = attributes of a class will be hidden or private,
    // Can be accessed only through methods (getters & setters)
    // You should make attributes private if you don't have a reason to make them public/protected

    Car car = new Car("Chevrolet","Camaro",2021);

    car.setYear(2022);

    System.out.println(car.getMake());
    System.out.println(car.getModel());
    System.out.println(car.getYear());

    }
    }
    //*************************************************
    public class Car {

    private String make;
    private String model;
    private int year;

    Car(String make,String model,int year){
    this.setMake(make);
    this.setModel(model);
    this.setYear(year);
    }

    public String getMake() {
    return this.make;
    }

    public String getModel() {
    return this.model;
    }

    public int getYear() {
    return this.year;
    }

    public void setMake(String make) {
    this.make = make;
    }

    public void setModel(String model) {
    this.model = model;
    }

    public void setYear(int year) {
    this.year = year;
    }

    }
    //*************************************************

    • @farhangotham1898
      @farhangotham1898 2 роки тому +4

      U are a legend

    • @michaeljagdharry
      @michaeljagdharry 2 роки тому +3

      Don't forget to pin this comment!! Thank you so much for all your help! Your videos are amazing and crystal clear!

    • @shadmankhan1969
      @shadmankhan1969 2 роки тому +3

      just letting you know you forgot to bin this comment boss. thanks for everything

  • @frankjuuh
    @frankjuuh 3 роки тому +11

    I've never felt more driven to like and comment on every video by any creator. Love your videos.

  • @RMJJ91
    @RMJJ91 Рік тому +2

    You are a legend. You make learning to code so much easier!!

  • @youvegotmail9385
    @youvegotmail9385 2 роки тому +9

    I've probably watched a million hours of coding videos already and just stumbled upon this guy today and the way he simplifies and explain things is next level. Even better than WebDev Simplified, Coding with John or dCode.

    • @PitbullSubedi
      @PitbullSubedi Рік тому

      humm who are they? im looking to get something from them too hahaha. lil bit of knowlwdge

    • @bananinator2502
      @bananinator2502 Рік тому +7

      1000000 hours = 114,155251 years. I wanted to say that this is not possible, but the oldest known living person is Maria Branyas of Spain, he aged 116 years, 189 days. The oldest known living man is Juan Vicente Pérez of Venezuela, aged 114 years, 105 days, so you must be Juan Vicente Pérez. This is unrealistic because he isnt alive anymore, The oldest living man is Edie Ceccarelli with 155 years and 216 days, your wrote the comment about 11 months ago, so it must be you Edie. Im really happy you still try to learn new things to this age. I do not only have too much time, but i wrote this comment also for the algorhytm to support Bro Code,

  • @anindo101
    @anindo101 2 місяці тому

    I found this great tutorial on Java Encapsulation. It really helped clear up my doubts.

  • @jenniT613
    @jenniT613 2 роки тому +2

    Your explanation of setters and getters was amazing! Thank you so much

  • @javlontursunov6527
    @javlontursunov6527 2 роки тому +2

    Man I really appreciate what you are doing. Keep going.

  • @surfacepro8208
    @surfacepro8208 2 роки тому

    By far, the best You-Tube tutorial channel!

  • @邵明黎
    @邵明黎 3 роки тому +11

    my teacher recommend you, very helpful

    • @BroCodez
      @BroCodez  3 роки тому +9

      awesome! I'm thankful for the recommendation

  • @pavelkvasnicka6856
    @pavelkvasnicka6856 Рік тому

    This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro

  • @EMont-qe8qf
    @EMont-qe8qf 3 роки тому +2

    Thanks, Bro. You're the best!
    Shoutouts from Brasil.

  • @santoshojha757
    @santoshojha757 Рік тому

    I got know new technique of placing setter methods inside constructor. Thanks.

  • @santhoshs.0209
    @santhoshs.0209 2 місяці тому +1

    nice video for get and set method

  • @lzh00
    @lzh00 3 роки тому +1

    Nice rhyme at the end, when you say ""hey you, yeah I'm talking to you...

  • @SM_Carino
    @SM_Carino 2 місяці тому

    I never thought I would reach to the 40th tutorial video.....thanks a lot Bro😂😂🎉🎉🎉It has taken my dedication and your dedication to make me understand Java

  • @itdasturlashdunyosi5631
    @itdasturlashdunyosi5631 3 роки тому +2

    I loved the way you explain! Thanks a lot

  • @dianamilenaarchilacordoba4632
    @dianamilenaarchilacordoba4632 2 місяці тому

    great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much

  • @fadinimer4574
    @fadinimer4574 16 днів тому

    excellent demonstration, thank you so much

  • @cuca3243
    @cuca3243 Рік тому

    Great explanation, unlike other videos I have seen. I am understanding now the meaning of encapsulation. Thank you.

  • @samymmohibby3508
    @samymmohibby3508 7 місяців тому

    You are an uncrowned king

  • @danny.3036
    @danny.3036 3 роки тому +3

    Thanks, Bro! ☕ You're awesome!

  • @まさきおう
    @まさきおう 2 роки тому

    THis really helps me a lot! I am such lucky to find this video.

  • @JoePelusoMedia
    @JoePelusoMedia 5 місяців тому

    Thank you for reminding me to relax :) Actually sat back and relax for the first time in a while.. Dx

  • @ladalll1303
    @ladalll1303 2 роки тому +2

    Great explanation! It is super well structured and clear. I have to watch your videos while taking other Java course because you explain it so well! Thank you again!

  • @magl1003
    @magl1003 3 роки тому +6

    Your videos are amazing! Thank you so much for teaching me Java. I was struggling hard with everything and OOP was not making any sense to me. You deserve so many more views! Keep up the good work!

  • @marbles5590
    @marbles5590 Рік тому

    thank you so much! I was quite confused with setters for a while, I thought they'd be useless if we already have constructors for initializing values but then you can just invoke the setters inside a constructor

  • @christianvillanueva723
    @christianvillanueva723 4 роки тому +16

    Happy teachers day/month bro
    I consider you as my teacher because I learn a lot
    Thanks

    • @BroCodez
      @BroCodez  4 роки тому +6

      thank you Christian, I'm happy to help

  • @jabber1407
    @jabber1407 Рік тому +15

    what's the idea of making something private if you're just going to make setters and getters?

    • @Alex-up9fh
      @Alex-up9fh 7 місяців тому +4

      i think this too. Lol

    • @Zico_277
      @Zico_277 7 місяців тому +15

      Cause when we're talking about encapsulation, the whole idea is protect our code from other devs (ourself included). For example if i write an Account balance Atribute public in my program It's like i'm saying: "Anyone is free to change the value in here" but through the getters and setters. We limit the other at changing the atributes only in the object and only with the Getters and Setters. (Sorry if It's hard to understand i'm just learning OOP too) If someome see something wrong with my explaining feel free to correct me.

    • @yanluisnunezlara319
      @yanluisnunezlara319 5 місяців тому +6

      So the variables or class fields can't be modified directly, other reason is the setter methods allow us validate data before being assigned to variables and so on.

    • @AnujaShirke
      @AnujaShirke 4 місяці тому

      Because if suppose we create variable for rollnumber and make it private, by using setters we can set variable values depending on certain conditions and get value using getter but if we do not make that variable private we are giving access to other devs to enter any random value , not those values which are correct as per our condition so this is the use of setters if we create instance variables private and use setters to set value according to our condition then it will set.

    • @adityasailada4218
      @adityasailada4218 4 місяці тому

      Simple reason someone else can modify our variables...hence we declare it as private but if we give access to methods they will not be able to modify anything and hence our code is safe

  • @theBATfamiliar
    @theBATfamiliar 6 місяців тому

    Grat explanation, I salute you sir

  • @jagsingh1571
    @jagsingh1571 2 роки тому

    Bro you are the fookinggggg best, you just helped me out for my assignment and seriously the best explaining everrrrr!!!!! thank you so much!!!❤

  • @TheZae31
    @TheZae31 2 роки тому

    Bro you just saved me like you won't believe thanks.

  • @mabelle105
    @mabelle105 3 роки тому

    Thank you so much! It took me actually quite long to understand this, but finally I understood this method!

  • @unalysuf
    @unalysuf Рік тому

    I've just started to learn java and j discovered your channel and you are pretty good. So I wanted to support your channel with my comments. Thank you so much again for your amazing effort.

  • @MrCEO-jw1vm
    @MrCEO-jw1vm 8 місяців тому

    Oh boy, I finally understood encapsulation. phew!! Thanks Bro!

  • @Ctrl-Z-Renders
    @Ctrl-Z-Renders 22 дні тому

    You may have 2.2 million subs, you are underrated anyways.

  • @uwan009
    @uwan009 2 місяці тому

    Simple and clear!

  • @shinkansen1907
    @shinkansen1907 5 днів тому

    YOU ARE A LEGEND

  • @oumelkheirkhayrieaa5424
    @oumelkheirkhayrieaa5424 2 роки тому

    Thank you so much for this! We really appreciate it bro!

  • @imsabbar
    @imsabbar 3 роки тому +1

    Well Explanation, Thanks teacher for these Videos 🙏 you really helped me a lot ♥️

  • @camerald8257
    @camerald8257 3 роки тому

    As a 2nd year and currently learning Java, I am so happy because I did not understand these concepts during the lecture but you simplified them. What a steal!

    • @lroadzl1288
      @lroadzl1288 2 роки тому

      For it being your seconds year, What things about programming do you know so far?

  • @IceBeam93
    @IceBeam93 3 роки тому +1

    Thank you for enlightening me with this knowledge :)

  • @mohamadnazirissumalgy3699
    @mohamadnazirissumalgy3699 2 роки тому

    Bro,you're the best!

  • @lalainaichane319
    @lalainaichane319 Рік тому

    Clear and concise ! Thank you bro 🤜

  • @azizarfaoui7038
    @azizarfaoui7038 10 місяців тому

    this video is very helpfull

  • @nambyrajao1736
    @nambyrajao1736 Рік тому

    Yeah, another super video THAAAAAAANKS !

  • @0ZANGETSUFLASH0
    @0ZANGETSUFLASH0 Рік тому

    ur God at explaining!

  • @Ducky_shades
    @Ducky_shades 2 роки тому

    Thanks, it is very inspiring and informative.

  • @mddulalmiah8012
    @mddulalmiah8012 4 місяці тому

    Legend bro..

  • @Joseph-gh5ib
    @Joseph-gh5ib 2 роки тому

    great tutorials. thank you so much!!!

  • @userkanchank
    @userkanchank Рік тому

    Best video

  • @Simis999
    @Simis999 2 роки тому

    Bro had a party yesterday :D fistbump

  • @subid.majumdar
    @subid.majumdar 2 роки тому +1

    all we're really doing is making the
    attributes of our class
    private so that they cannot be directly
    accessed from elsewhere within our
    program
    if you need to retrieve one of these
    values you can use a
    getter method if you need to change or
    set one of these values
    you can use a setter method so that you
    can indirectly either
    get or set these values and other
    classes do not have direct access

  • @shaheenreid9939
    @shaheenreid9939 4 роки тому +13

    Hi! Your videos are helping me excel in my Java class. Thank you so much! I have a question about setters. If I am using encapsulation but also using inheritance, how do I get around the fact that setting a variable in the parent class to private prevents a subclass from accessing/setting values for that private variable?

    • @shaheenreid9939
      @shaheenreid9939 4 роки тому

      I guess I am just trying to understand the need for having constructors and setters to set values in the event I need to use both encapsulation and inheritance.

    • @BroCodez
      @BroCodez  4 роки тому +9

      use the super constructor! 🦸
      ua-cam.com/video/oKZnHNM9Ew4/v-deo.html

    • @shaheenreid9939
      @shaheenreid9939 4 роки тому +7

      @@BroCodez Ahhh okay got it. Thanks Bro!

  • @zkillzixx6692
    @zkillzixx6692 2 роки тому

    I appreciate your effort Bro 💪💪💪

  • @dr.smoothlove
    @dr.smoothlove 2 роки тому +1

    Comment for the algorithm, bro.

  • @johanjaimes10
    @johanjaimes10 2 роки тому +1

    I have been thinking what is the point with encapsulation if you are returning the variable value anyway but watching your video I've realised that encapsulation is useful if you want to hide a variable value but you need that variable to calculated something. For example, you want to hide the percentage of revenue but you need it to calculate the final price of a product. You don't want that the percentageRevenue to be public.

  • @abdirizackmuhamud9203
    @abdirizackmuhamud9203 Рік тому

    Legend.

  • @yigitsoyhanozu
    @yigitsoyhanozu Рік тому +1

    4:03 "Can we pretty please get" hhashadhashahahha

  • @EdgeLordOmen
    @EdgeLordOmen 7 місяців тому

    Thank you!

  • @MrRiverman64
    @MrRiverman64 9 місяців тому

    Thanks, bro! For real!

  • @MY-bn4px
    @MY-bn4px 4 роки тому +2

    amazing

    • @BroCodez
      @BroCodez  4 роки тому

      Thanks for watching!

  • @blendajeti6167
    @blendajeti6167 6 місяців тому

    King

  • @arjundas7078
    @arjundas7078 3 місяці тому

    nice

  • @santialawiahputrisekar7237
    @santialawiahputrisekar7237 2 роки тому +3

    In the constructor,
    What is different between using "this.setmake(make) " and not using "this."?

  • @basil9633
    @basil9633 Рік тому

    W for helping with comp sci final

  • @dolevdo
    @dolevdo 2 роки тому

    Amazing

  • @bekzattursynbay5675
    @bekzattursynbay5675 Рік тому

    great

  • @proalexv
    @proalexv Рік тому

    Also, great video!

  • @actionbeam001
    @actionbeam001 6 днів тому

    @Bro Code hello bro what if we used a public class to string method to display everything?? its so simple right?

  • @曾毓哲-b1t
    @曾毓哲-b1t Рік тому

    Bro Thank you very much!!

  • @mariamcagadas6007
    @mariamcagadas6007 Рік тому

    Thanks bro

  • @harshnitnaware9143
    @harshnitnaware9143 2 роки тому

    Bro Code very good video, easy to understand. Hey bro can you paste down the code in the comment section

  • @hamzachiguer642
    @hamzachiguer642 2 роки тому

    Thank you bro

  • @pa-305
    @pa-305 3 роки тому

    best brooo

  • @appstocks5956
    @appstocks5956 2 роки тому

    tysm.

  • @daltonlagat9018
    @daltonlagat9018 Рік тому

    dope

  • @vpenywise
    @vpenywise 3 роки тому +1

    I never thought about replacing the parameters of the constructor with the Setters! :) What are the benefits of doing this?

  • @mohamedbenkhalifa1299
    @mohamedbenkhalifa1299 2 роки тому

    Thanks a lot bro!

  • @baubaudinamo
    @baubaudinamo 3 роки тому

    Good video Bro

  • @huuloc8719
    @huuloc8719 3 роки тому

    Nice.

  • @MashoriMentors
    @MashoriMentors Рік тому

    thank u bro

  • @kemann3815
    @kemann3815 3 роки тому

    Da best

  • @dildil6815
    @dildil6815 2 роки тому

    thank you brooooooooooo

  • @ibrahimylmaz8378
    @ibrahimylmaz8378 2 роки тому

    thanks bro

  • @romario92730
    @romario92730 3 роки тому

    Thanks, Bro!

  • @mohamedelfadli3125
    @mohamedelfadli3125 Рік тому

    understood bro.

  • @minhtetpaing1695
    @minhtetpaing1695 3 роки тому

    Thank you so much sir.

  • @rafaelsantana9946
    @rafaelsantana9946 Рік тому

    Dropping a comment :)

  • @tapiwakalitawo8013
    @tapiwakalitawo8013 3 роки тому

    thanks, this was really helpful

  • @thejealousones4189
    @thejealousones4189 10 місяців тому

    public String coding(){
    return "encapsulation is so co0oll!"
    }

  • @arunnteam1901
    @arunnteam1901 2 роки тому

    thank u

  • @ma8969
    @ma8969 2 роки тому

    thanks

  • @robertwide6592
    @robertwide6592 2 роки тому

    niceuuu

  • @champab5350
    @champab5350 2 роки тому

    thanku

  • @mudassirnaz1813
    @mudassirnaz1813 3 роки тому

    Thanks

  • @michaelandreisacaguing3848
    @michaelandreisacaguing3848 2 роки тому

    moreeee pleassseee

  • @luisgabrielmarinmunoz4814
    @luisgabrielmarinmunoz4814 2 роки тому

    👍🏻👍🏻

  • @wallstreetbets7741
    @wallstreetbets7741 2 роки тому

    thx

  • @soumelee5661
    @soumelee5661 2 роки тому

    🎁 good vid