#40 Encapsulation in Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 มิ.ย. 2024
  • Telusko Courses:
    Spring and Microservices Live Course : bit.ly/springmslive
    Coupon: TELUSKO25 (25% Discount)
    Industry-Ready Java Spring Microservices Developer Live : bit.ly/JavaMS2
    Complete Java Developer Course : bit.ly/Comp-Java-Dev-2
    Coupon: TELUSKO20 (20% Discount)
    Udemy Courses:
    Java:- bit.ly/JavaUdemyTelusko
    Spring:- bit.ly/SpringUdemyTelusko
    Java For Programmers:- bit.ly/javaProgrammers
    For More Queries WhatsApp or Call on : +919008963671
    website : courses.telusko.com/
    In this lecture we are discussing:
    1)What is encapsulation?
    2)how to achieve encapsulation
    3)Benefits of encapsulation
    4)how to use private data?
    #1
    What is encapsulation?
    = binding data with method to make your program secure is known as encapsulation.
    Consider encapsulation as we have capsule and inside capsule everything inside a class is wrapped or encapsulated.
    e.g
    class A{ private int a;
    public void setA(int num){a=num;}
    public int getA(){return a;}
    }
    //here you can see that we can bind data with method inside a curly braces, it seems look like a capsule inside everything is present.
    #2
    how to achieve encapsulation?
    -- through access specifiers private,protected,public,default . We can achieve
    encapsulation.
    #3
    Benefit of encapsulation
    i)Helpful in to achieve abstraction
    ii)for security point of view it is most beneficial.
    iii)you can maintain log file through method when you bind your data with method.
    #4
    how to use private data?
    -- using setters and getters method we can set and get the value of variable.
    -- private int num;
    public int getNum( )
    {
    return num;
    }
    public void setNum(int num)
    {
    this.num=num;
    }
    Note:
    Always make variable as private and method as public to achieve security in program.
    Github repo : github.com/navinreddy20/Javac...
    Java:- bit.ly/JavaUdemyTelusko
    Spring:- bit.ly/SpringUdemyTelusko
    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
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 76

  • @user-so8bb4bt3u
    @user-so8bb4bt3u หลายเดือนก่อน +2

    00:04 Encapsulation is a part of object oriented programming.
    01:33 Data is stored in the brain in the format of variables
    02:57 Data access control in object-oriented programming
    04:22 Private variables can only be accessed within the same class.
    05:56 Data access is restricted using methods.
    07:16 Private variables can only be accessed within the class that they are defined in.
    08:51 Setting values for variables and accessing them using methods.
    10:22 Encapsulation is a way to bind data and methods together

  • @dr.renukapatel9403
    @dr.renukapatel9403 ปีที่แล้ว +9

    the way you explain any topic is awesome, specially examples....

  • @subajaelango1535
    @subajaelango1535 8 หลายเดือนก่อน +10

    Actually sir you're my favorite trainer 🔥

  • @user-yz5ub8tb2t
    @user-yz5ub8tb2t 8 หลายเดือนก่อน +4

    Sir, you're tin god and one of my favourite and i like you, god will bless you helping a lot for who needs technical stack to grow their skill-set, hope you provide more content like this, finally your flow of explanation was outstanding, and i like you a lot and a lot more...🔥

  • @SoulOfBharat
    @SoulOfBharat 21 วันที่ผ่านมา

    there is no hesitation that you are the best trainer. you really understand how one should be taught it means you understand the problem a student face while studying and grasping the concept. love from the capital of india and from Bihar.

  • @sakthipriya8653
    @sakthipriya8653 9 หลายเดือนก่อน +12

    Its 2 complete hrs, I'm still watching your playlist. Hats off Mr. Navin 👏

  • @AyeshaKhan-om9mu
    @AyeshaKhan-om9mu ปีที่แล้ว +19

    Sir your teaching skills are very good 💯 it's very helpful Java playlist for beginners thankyou so much and Allah bless you ✨👍

  • @jananisrivaideesh1316
    @jananisrivaideesh1316 11 หลายเดือนก่อน +5

    You are superb sir💯💯💯the way of teaching is in easily understandable manner

  • @wolverine3419
    @wolverine3419 5 หลายเดือนก่อน +5

    the way you explain this is magical. I went through videos to find out what encapsulation is and from you i found it. Highly Appreciated Man!

    • @MFM88832
      @MFM88832 2 หลายเดือนก่อน

      You've used the perfect word, it is just "magical". Telusko has a special talent for teaching!

  • @shortnews1819
    @shortnews1819 ปีที่แล้ว +5

    You are Superb, the way you taught is excellent.

  • @prakrutijani4205
    @prakrutijani4205 4 หลายเดือนก่อน

    I m experienced java developer .. i started watching this playlist to refresh but.. i ended up actually learning making me realize.. i dont know stuff still.However, I loved your teaching way.

  • @RGMUTEX
    @RGMUTEX 6 หลายเดือนก่อน

    Your teaching style is marvelous❤. Love from Nepal!

  • @aniketankush218
    @aniketankush218 หลายเดือนก่อน

    Sir your way of explaining is just brilliant!👏

  • @yashaswinihm4288
    @yashaswinihm4288 5 หลายเดือนก่อน +1

    Just explained like a wow.Omg wow 🔥

  • @user-mq2cb4rx4g
    @user-mq2cb4rx4g 10 หลายเดือนก่อน +1

    That is fantastic, sir, you are a legend.

  • @debarghyamajumder998
    @debarghyamajumder998 13 วันที่ผ่านมา +1

    Your Teaching is Great Sir! 💛

  • @suieyP7
    @suieyP7 6 หลายเดือนก่อน

    Superb sir. Thank you very much.

  • @ghunsenh
    @ghunsenh 6 หลายเดือนก่อน

    Nice explanation of getters and setters

  • @ch.Rambabu-goud
    @ch.Rambabu-goud 4 หลายเดือนก่อน

    I am extremely happy to see your vedioed

  • @vallikumar1281
    @vallikumar1281 ปีที่แล้ว +1

    expected one.. Thank you sir..

  • @user-yj7ub6dw5n
    @user-yj7ub6dw5n 7 หลายเดือนก่อน

    Sir your explanation is amezing tqs alot you are equal to God for me

  • @aishwaryasinnur2256
    @aishwaryasinnur2256 9 หลายเดือนก่อน

    really easy to understand sir 😍😍thanku

  • @SB-pk2ss
    @SB-pk2ss 10 หลายเดือนก่อน +2

    you don't need to use a static block if you just want to initialze a field
    private static String name = "Phone";
    would be enough.
    but if you need some complex manipulations, requires several lines of code, than yes, there static blocks come in

  • @rahulpawar5927
    @rahulpawar5927 4 หลายเดือนก่อน

    very good explaination sir.

  • @khankashif7586
    @khankashif7586 6 หลายเดือนก่อน

    Explanation way is so easy

  • @saurabhhedau3300
    @saurabhhedau3300 6 หลายเดือนก่อน

    best ever example you told here sir

  • @vinodonweb
    @vinodonweb 8 หลายเดือนก่อน

    amazing teacshing method 👍👍

  • @balajikavitha8835
    @balajikavitha8835 ปีที่แล้ว +1

    Nice explanation

  • @kaku-bm1ti
    @kaku-bm1ti 2 หลายเดือนก่อน

    thank you sir 👑

  • @LearnEnglishMM
    @LearnEnglishMM 7 หลายเดือนก่อน +4

    You are using examples from personal life; it’s good to let others learn things well. Try to give a minimum of two examples in each video per topic. Thanks.

  • @it.b.61.prashantsingh87
    @it.b.61.prashantsingh87 3 หลายเดือนก่อน

    Explanantion was top notch! But my question is we use private access modifier so that other classes can't use it, and then we create get and set method through which we can change and access the value, if we are including get and set method for private variable, why we simply can't keep the vaiable public if in the end we need to access and change the data.

  • @lepakshirh7419
    @lepakshirh7419 14 วันที่ผ่านมา

    Tqsm sir for sharing knowledge thoroughly🤝🫂

  • @vigneshrp1294
    @vigneshrp1294 4 หลายเดือนก่อน

    I have a doubt from a long time and couldnt find the answer.......We use access modifiers to control the accessiblity within the program to ensure encapsulation.....so if we have a private variable and if still we can access it through a public getter method then what is the use of having a private variable.....it can be public instead right?

  • @adityapatil7396
    @adityapatil7396 8 หลายเดือนก่อน

    Can we achieve encapsulation by declaring variables protected instead of private ?

  • @syedfaizan5841
    @syedfaizan5841 9 หลายเดือนก่อน

    Thanks ❤

  • @user-xc5tg3zi4e
    @user-xc5tg3zi4e 3 หลายเดือนก่อน +1

    @Telusko
    I have a question sir,
    We can even call the getAge() method by simply passing the value and calling it under Demo class, even age is private in class Human. I tried it and worked well, which states that we don't need setAge() method to set the value, can simply pass through the getAge() and fetch the value.
    Please explain sir, how I am wrong and why do we need get, set methods here? I am pretty sure there must be point behind there :)
    For eg:
    public int getAge(int a)
    {
    age = a;
    return a;
    }
    And while calling it under class demo, we can define:
    Human obj = new Human();
    int final = obj.getAge(56);
    System.out.println(final);

    • @Tolly633
      @Tolly633 3 หลายเดือนก่อน

      If u try to just age()method passing the value under demo class from calling function age method to called function age() without get method. If u can declare variables as private u can't access variables without set or get methods. But u did declare variables as private at the same time u used get /set method. That's the reason u got an output(u haven't no error)

  • @shaikbasha3882
    @shaikbasha3882 ปีที่แล้ว +3

    you stored lot of information in your brain and by seeing itself everyoone can understand :) just kidding , lovely explanation

  • @manikandans1996
    @manikandans1996 10 หลายเดือนก่อน +1

    Sir pls provide notes for this playlist

  • @jatinsharma3792
    @jatinsharma3792 5 หลายเดือนก่อน

    Yes, but is it important to make the class in such a way that we should asign the private vable value directly withou using the setter method.? Why we need to create the strcuture to set the data only and to fetch the data ? I mean what is the actual real life purpose of doin this activity which you are saying Encapsulation ?

  • @luckygold777
    @luckygold777 11 หลายเดือนก่อน +1

    Sir, can u please tell me what is the point if we can access the data and change the data even if it's private? what is the advantage of the variable not being accessed directly.....Please respond as soon as possible sir.

    • @a.m.e.e.e.r
      @a.m.e.e.e.r 7 หลายเดือนก่อน

      As you heard he said only via methods, so if you don't make "setName" method for example, no one can change the data, while they can GET the data via "getName" it depends on the methods you create. and yeah everyone can touch it if they have your pc, but it's different when it's on the app/game/web you make. Hope it helped. 😊

  • @vinaysaiakula9475
    @vinaysaiakula9475 5 หลายเดือนก่อน

    Sir what if we keep method as private 🤔

  • @iam_robinroy
    @iam_robinroy 11 หลายเดือนก่อน

    ❤tnku sir

  • @broyea6943
    @broyea6943 4 หลายเดือนก่อน

    I just learned about encapsulation right now😂, does this mean I should stop using constructors and use setters instead?

  • @navasshariff.s9426
    @navasshariff.s9426 9 หลายเดือนก่อน

    Allah bless uuu🎉

  • @chemistryworl
    @chemistryworl 9 หลายเดือนก่อน

    U r lit sir 🔥

  • @muhammedashkar692
    @muhammedashkar692 10 หลายเดือนก่อน +1

    breaks my head and takes his name and says "oh there is his name"🤣🤣

  • @NirajKumar-ip1gq
    @NirajKumar-ip1gq 10 หลายเดือนก่อน

    obj.setAge(a: 30); I didn't understood this

  • @puruagni1927
    @puruagni1927 หลายเดือนก่อน

    Why are you not updating VS Code? Please update VS Code.

  • @sirrisathwik8332
    @sirrisathwik8332 ปีที่แล้ว +3

    telugaa bhaiyaa

  • @rdxdevil5083
    @rdxdevil5083 9 หลายเดือนก่อน

    very good sir i got it
    but encapsulation means only public method can access it
    encapsulation means data hiding
    but we are going to public the data
    can someone clear mt doubt....

    • @neerajgarg9096
      @neerajgarg9096 9 หลายเดือนก่อน

      we are not going to public data member instead we are going to public the member functions which help to get and set the value of our private data member
      see the below code
      class Encapsulation{
      private int x;
      // now this data member is hidden from outside world as it is private but to set its value and get its value we need to define functions which are public and can be used
      public void set(int a){
      x=a;
      }
      public int get(){
      return x;
      }
      }

  • @prudvidiyya9226
    @prudvidiyya9226 6 หลายเดือนก่อน

  • @reshmashetty1471
    @reshmashetty1471 6 หลายเดือนก่อน

    "break my head and say... Hey! I got the data" 🤣🤣🤣🤣

  • @ganeshkumarv3895
    @ganeshkumarv3895 ปีที่แล้ว +1

    why there isn't this.age = age or return this.age ?

    • @aeroabrar_31
      @aeroabrar_31 ปีที่แล้ว

      Yes you can, but the variable name which is coming as a parameter should be 'age' .

    • @ArpithaHK
      @ArpithaHK ปีที่แล้ว +2

      The parameter which is passing to setter method is same as the instance variable, then "this" must be used.
      for ex:
      public void setAge(String age); {
      this.age = age;
      }

    • @sachinkhatri1077
      @sachinkhatri1077 11 หลายเดือนก่อน

      U can use that if u set your methods parameters name exactly like instance variables. By the way thats a good practice to use proper name in methods and use this keyword to refer.

  • @Realfactsofficial-mz4tz
    @Realfactsofficial-mz4tz 2 หลายเดือนก่อน

    sir your video good but it is too lenthy and long

  • @user-so8bb4bt3u
    @user-so8bb4bt3u หลายเดือนก่อน

    HE is talking about the movie wall -e where he used the words pixel
    pls give a me a like

  • @0shaad
    @0shaad 10 หลายเดือนก่อน

    adam scandler's pixel

  • @princet0429
    @princet0429 8 หลายเดือนก่อน

    mm

  • @rakshanch2126
    @rakshanch2126 17 วันที่ผ่านมา

    fire uuuuu

  • @kvelez
    @kvelez 8 หลายเดือนก่อน

    public class Main{
    public static void main(String[] args) {
    Human me = new Human(30, "Mario");
    System.out.println(me.GetName() + " " + me.GetAge());
    }
    }
    class Human{
    private int age;//private attribute
    private String name;
    public Human(int age, String name){//constructor
    this.age = age;//setting
    this.name = name;
    }
    public void SetAge(int age){//set value
    this.age = age;
    }
    public int GetAge(){//output
    return age;
    }
    public void SetName(String name){//setter
    this.name = name;
    }
    public String GetName(){//getter
    return name;
    }
    }

  • @adithidesai8690
    @adithidesai8690 8 หลายเดือนก่อน

    6:28 Jeffrey Dahmer's way of accessing the data

  • @sultankodirov
    @sultankodirov 6 หลายเดือนก่อน

    you can user my name as a trainer hahahaaahahhaahahahah

    • @sultankodirov
      @sultankodirov 6 หลายเดือนก่อน

      I use by the way )))))hahahaha

  • @authenticworld7271
    @authenticworld7271 ปีที่แล้ว +1

    And your age is 41

    • @thebacheafghan
      @thebacheafghan ปีที่แล้ว +3

      you cannot define someone's age. you are ageist. you are cancelled.

  • @dummyaxle2099
    @dummyaxle2099 7 หลายเดือนก่อน

    You use too many words, cut it by 1/3