8.1 What is Encapsulation in Java Tutorial

  Рет қаралды 393,805

Telusko

Telusko

Күн бұрын

Check out our courses:
Spring and Microservices Weekend Live Batch : bit.ly/spring-...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : bit.ly/java-sp...
Recommend Books :
1. Head First Java : amzn.to/2owFrf0
2. Java Complete Reference : amzn.to/2osY04k
Java and Spring Framework For beginners with Spring Boot : - bit.ly/3LDMj8D
Java Tutorial for Beginners (2023) :- bit.ly/3yARVbN
For code click here
goo.gl/zYgAQZ
Encapsulation in Java
Binding Data with Method
Getters and Setters
Data Hiding
Encapsulation is one of the four fundamental OOP concepts.
Encapsulation is the technique of making the fields in a class private and providing access to the fields via public methods.
If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the fields within the class
Encapsulation is one of the four fundamental OOP concepts.
Encapsulation can be defined as a process of wrapping code and data together into a single unit.
Encapsulation is the technique of making the fields in a class private and providing access to the
fields via public methods.
If a field is declared private, it cannot be accessed by anyone outside the class, thereby hiding the
fields within the class
Editing Monitors :
amzn.to/2RfKWgL
amzn.to/2Q665JW
amzn.to/2OUP21a.
Editing Laptop :
ASUS ROG Strix - (new version) amzn.to/2RhumwO
Camera : amzn.to/2OR56AV
lens : amzn.to/2JihtQo
Mics
amzn.to/2RlIe9F
amzn.to/2yDkx5F
Check out our website: www.telusko.com
Follow Telusko on Twitter: / navinreddy20
Follow on Facebook:
Telusko : / teluskolearnings
Navin Reddy : / navintelusko
Follow Navin Reddy on Instagram: / navinreddy20
Subscribe to our other channel:
Navin Reddy : / @navinreddy
Telusko Hindi :
/ @teluskohindi
Subscribe to the channel and learn Programming in easy way.
Java Tutorial for Beginners : goo.gl/p10QfB
Scala Tutorials for Java Developers : goo.gl/8H1aE5
C Tutorial Playlist : goo.gl/8v92pu
Android Tutorial for Beginners Playlist : goo.gl/MzlIUJ
XML Tutorial : goo.gl/Eo79do
Design Patterns in Java : goo.gl/Kd2MWE
Socket Programming in Java : goo.gl/jlMEbg
Spring MVC Tutorial : goo.gl/9ubbG2
OpenShift Tutorial for Beginners : goo.gl/s58BQH
Spring Framework with Maven : goo.gl/MaEluO
Sql Tutorial for Beginners : goo.gl/x3PrTg
String Handling in Java : goo.gl/zUdPwa
Array in Java : goo.gl/uXTaUy
Java Servlet : goo.gl/R5nHp8
Exception Handling in Java : goo.gl/N4NbAW

Пікірлер: 174
@susobhandas6143
@susobhandas6143 4 жыл бұрын
bad video quality in this particular video: "looks like it was a hectic day, tired but still you're making video, no time for preperation" We salute for your hard work, एही तो है ना हमारी हिंदुस्तानी भाई
@kritisundurtv9606
@kritisundurtv9606 5 жыл бұрын
When he used to say guys instead of aliens😊
@anshumandas5392
@anshumandas5392 4 жыл бұрын
when he started thinking about gaining subscribers XD
@MrJonnis13
@MrJonnis13 10 жыл бұрын
Sir, you make a wonderful job here. Extremely helpful for a starter. Keep doing tutorials and we will keep following you.
@siva_subramaniam
@siva_subramaniam 2 жыл бұрын
clear and concise explanation. thank you so much.
@travelnlearn
@travelnlearn 2 жыл бұрын
Thanks bro for such useful update. May gbu with lots of love success and happiness
@MrHorizonkid
@MrHorizonkid 6 жыл бұрын
You made it so easy, many thanx from Pakistan!
@joeyjoejoo
@joeyjoejoo 9 жыл бұрын
Brilliantly explained. Good man.
@sharanyajidigam5216
@sharanyajidigam5216 7 жыл бұрын
Sir, at the duration, 5:38 , shouldn't it be S.O.P(obj.getI()), when calling the getI() function instead of S.O.P(getI())?
@saumyojitdas4212
@saumyojitdas4212 2 жыл бұрын
MAYBE because when operation of set is done through obj.setI() then we have to mention the object as i am passing value . in case of returning as the control will automatically flow from set to get thats why just caliing will do
@pratik2617
@pratik2617 2 жыл бұрын
yesss
@anmolthedeveloper
@anmolthedeveloper 8 жыл бұрын
you've got some awesome teaching skills 👌👍👍
@utkarshsingh1075
@utkarshsingh1075 6 жыл бұрын
Easily understood sir... Perfect description..
@mangeshpatil8810
@mangeshpatil8810 9 жыл бұрын
Thanks ... great explanation.
@sreejareddygummi4900
@sreejareddygummi4900 3 жыл бұрын
What is the use of private variables in java ? 🧐
@Joshuaomorales
@Joshuaomorales 8 жыл бұрын
You missed the obj.getI(). Good job though.
@gauravpathak560
@gauravpathak560 3 жыл бұрын
sir kindly make another video on encapsulation because video quality is not good afterall it may around 7 year old video
@harekrishnanayak5004
@harekrishnanayak5004 8 жыл бұрын
sir...in the main class i think it shud b sop(obj.getI());
@pradeepgodavarthi8313
@pradeepgodavarthi8313 7 жыл бұрын
if u have that sop in getI method then no need ..creating instance of the method ll do
@kumaiyavlogs5020
@kumaiyavlogs5020 7 жыл бұрын
getters and setter can you please clearly explain in about term ENCAPSULATION? why this word ENCAPSULATION came in JAVA ? despite of calling #using of getter and setter methods in java.
@ramandussa7803
@ramandussa7803 8 жыл бұрын
could you explain what is the difference between Encapsulation and Abstraction..
@eggiweggsi
@eggiweggsi 6 жыл бұрын
Thank you, Pajeet.
@justdanaus
@justdanaus 4 жыл бұрын
I really hate learning Java until I found your videos, I'm not sure if you're still on here, but thank you for your hard works!!! You're legend.
@rahulmadakatti
@rahulmadakatti 9 жыл бұрын
hello,i think that the sop should be sop(obj.getI())
@hydro6527
@hydro6527 5 жыл бұрын
Sir, add another video related to encapsulation(how it hide unwanted information and shows only necessary information)
@amitgupta-tz9cc
@amitgupta-tz9cc 9 жыл бұрын
in last line S.O.P(obj.getI());
@thanualekhya4413
@thanualekhya4413 9 жыл бұрын
its soooooo understandable
@syedkhalil6083
@syedkhalil6083 4 жыл бұрын
you are amazing , Hats of to your teaching Methodology
@barath9815
@barath9815 7 жыл бұрын
what u have entered in System.out.println(getI(); gives an error right one is System.out.pritnln(obj.getI());....sir
@avinashkotni1460
@avinashkotni1460 9 жыл бұрын
sir u said that memory is allocated for object by jvm in one lecture .. again u said that memory is allocated for object by constructor . which one is right... ??
@souvikpal6262
@souvikpal6262 7 жыл бұрын
shouldn't it be s.o.p(obj.getI()); at 5:38 . Please clarify my doubt . I may be wrong . :) Ty love your videos .
@napialex7539
@napialex7539 7 жыл бұрын
I'm screaming! the first video that helped me understood encapsulation! tnx
@reinobrowne9597
@reinobrowne9597 8 жыл бұрын
why you screaming at me ;(
@Chrisymcmb
@Chrisymcmb 7 жыл бұрын
lol
@TheGeorges101
@TheGeorges101 7 жыл бұрын
omg, i just said the same thing! Scrolled down then saw your comment
@9528102219
@9528102219 7 жыл бұрын
I lost me hairs from front part of my head... Can someone ask this guy how to bring it back
@Zzz-nv4xi
@Zzz-nv4xi 6 жыл бұрын
Nit K I just asked him ... he replied "Use getForeheadHairs() {} method" !
@PacLevkov
@PacLevkov 6 жыл бұрын
To get your attention.
@karthi9722
@karthi9722 3 жыл бұрын
Where exactly encapsulation is used?...what if the user too knows about the getter and setter method and changed the variable by accessing the method
@sajalhasan222
@sajalhasan222 9 жыл бұрын
Dear Sir,, you are best... I Love You...
@shivantkumarpandey2708
@shivantkumarpandey2708 4 жыл бұрын
sir how constructor is also called as classes
@zombnie
@zombnie 5 жыл бұрын
easy and quick. Thanks Navin. Your videos are great for revising concepts before my interviews.
@aparnavivekanandan4328
@aparnavivekanandan4328 3 жыл бұрын
Simple and Understanding explanation Sir. Thanks!
@mdaliashraf4544
@mdaliashraf4544 3 жыл бұрын
This guy is a gem when u are actually learning java
@rahul-sinha
@rahul-sinha 2 жыл бұрын
Still loving your lectures in 2021
@chvenu3494
@chvenu3494 7 жыл бұрын
As per your encapsulation video concept is not sufficient. For complete encapsulation we have to restrict with conditions in the Person class, then only we can encapsulate the data. Example: package eiq.samples; public class Person { private int age; public int getAge() { return age; } public void setAge(int age) { if(age < 16 || age > 60){ throw new RuntimeException("Invald Age"); } this.age = age; } } package eiq.samples; public class Encapsulation { public static void main(String[] args) { Person p = new Person(); p.setAge(16); System.out.println(); } }
@siddharthbhandari7601
@siddharthbhandari7601 6 жыл бұрын
Hi for multiple variable we can use one setter method but getter method we should use seprate for each variable as per below package simple.practice; class Encapsulation_J { private int i, j; public void setI(int k, int l) { i=k; j=l; } public int getI() { return i; } public int getI1() { return j; } } class A { public static void main(String[] args) { Encapsulation_J e=new Encapsulation_J(); e.setI(12, 15); System.out.println(e.getI1()); System.out.println(e.getI()); } }
@pratik2617
@pratik2617 2 жыл бұрын
package com.company; class A{ private int i; public void setI(int j){ i = j; } public int getI() { return i; } } public class Main{ public static void main(String[] args) { A obj = new A(); obj.setI(5); System.out.print(obj.getI()); } }
@pratik2617
@pratik2617 2 жыл бұрын
this code will run
@lancelottheknight7126
@lancelottheknight7126 6 жыл бұрын
To those who are wondering, S.O.P() stands for System.out.print() okay?
@113kishore
@113kishore 5 жыл бұрын
Anyway you are allowing the user to set value right ... Then how exactly you providing safe fairs access??
@Anilkumar-ec8sj
@Anilkumar-ec8sj 8 жыл бұрын
Thanks you sir , well explained . Picture/ video quality was not that great little blurr .. and it will be great if you can remove your pic for your channel and make a logo that will look better . :)
@DeepakKumar-hn5tz
@DeepakKumar-hn5tz 6 жыл бұрын
In your example although u have declared the property of class as private and u exposed accessor methods rather than accessing the property directly we can access using accessor methods so whats the difference in these approaches.
@anandprakash5880
@anandprakash5880 9 жыл бұрын
it should be obj.getI()
@tejasvimarumokham2623
@tejasvimarumokham2623 5 жыл бұрын
the video quality is not clear.....i mean the appearance
@bhoomikapandey2728
@bhoomikapandey2728 7 жыл бұрын
please explain.................... int m=100 ;int n=300 ;while(++m --n) ;system.out.println(m);
@leets4687
@leets4687 7 жыл бұрын
in while there should always be a boolean value in parenthesis. so you cannot increment, decrement, initialize or declare a value
@BabuKaliyamoorthy53
@BabuKaliyamoorthy53 10 жыл бұрын
Really amazing speech and points.Great ...keep it up sir.
@ramramesh130
@ramramesh130 5 жыл бұрын
Sir.. In this encapsulation getters and setter method is mondatory or we can use instant methods also...??
@Ozzyisunavailable
@Ozzyisunavailable 8 жыл бұрын
not sure if you fixed the problem since the video first came out but camera is a bit noisey, if you can birghten up the room a bit more it shoud get rid of that :] great tutorial though!
@bhavanim729
@bhavanim729 5 жыл бұрын
why should v change the value using method?? what is the use out of it. Please reply
@siddharthbhandari7601
@siddharthbhandari7601 6 жыл бұрын
we need to call getI() using below System.out.println(obj.getI());
@vijayr1329
@vijayr1329 Жыл бұрын
But when I typed this code it is showing can't find symbol method getI() ,plz any one reply if you know.
@brtlMJ
@brtlMJ 11 ай бұрын
Obj.get()
@jaydobariya7652
@jaydobariya7652 7 жыл бұрын
if we can change the value of private variable than what is need of encapsulation
@AviatorBro
@AviatorBro 6 жыл бұрын
very poor video quality.. content is good, but no use if u cant see it properly
@superimaginationland9026
@superimaginationland9026 7 жыл бұрын
i did the 360th like guys... thumbs up..
@rajulama9732
@rajulama9732 9 жыл бұрын
you are a Great Lecturer.................................................. Man!!!!!!!!!!!!!!!!!!!!!!!!!
@Nitesh22upsc
@Nitesh22upsc 6 жыл бұрын
Thanks a lot sir your oops videos saved me ...every questions in exam were from your videos
@saubhikdatta935
@saubhikdatta935 8 жыл бұрын
sop(obj.getI());plz correct it Sir
@manishasharma5937
@manishasharma5937 7 жыл бұрын
Nice... But try not using 'right' and 'ok' too much it irritates
@aymanmomin432
@aymanmomin432 4 жыл бұрын
why do we even use encapsulation ??
@shivashabanpour9218
@shivashabanpour9218 10 жыл бұрын
Thank's, wonderful job and so easy to understand.
@ArunraajSingh
@ArunraajSingh 7 жыл бұрын
If we can change the value of private variable indirectly(through setxx), then how is the private variable secured, how is it hidden?
@FaithBiete
@FaithBiete 7 жыл бұрын
This is what he did not explain.
@rohitsoni9325
@rohitsoni9325 8 жыл бұрын
Focussing Problem of Camera Sir... till @2:07
@h.cazador
@h.cazador 8 жыл бұрын
Great video, but writing is hard to see.
@nandakumar5406
@nandakumar5406 4 жыл бұрын
your videos are much useful sir, worth watching , you are awesome sir
@wiki4sport
@wiki4sport 8 жыл бұрын
Excellent video, congratulations, simple and good explained..
@travelnlearn
@travelnlearn 2 жыл бұрын
Very well explained
@sivasiri935
@sivasiri935 7 жыл бұрын
Hi sir,What is the use of making variable private?Suppose i have created 2 objects and trying to access variable.Any how ,for each object,JVM will allocate memory separately. So,if we assign value to the variable,it will applicable for particular object only.So,what is the use of privare variable...waiting for reply... Thanks
@tusharpatel8473
@tusharpatel8473 7 жыл бұрын
As you know, encapsulation means hiding internal details of your class from the end user ( entity that uses your class). Now I will give you a real life example. Suppose a doctor John gives patient 3 different powders and tells him that very time he is supposed to mix 3 mg of white powder, 2 mg of red and 4 mg of green, combine them and then take them with glass of water. On other hand doctor Smith gives a patient a simple 'Capsule' that contains the same amount of medicines. But now its not botheration to patient to know what is actually inside the capsule or go through the hassle of measuring the content. So using a 'Capsule' made it really convenient to end user (here patient) in similar way, when writing a class, if you expose how you are storing data, which data structure you are using to end user (here end user is the class that uses your class), then it is just unnecessary details your are flooding the end user with. You should give him simple way to use your class without exposing the complex details.
@prashantjha654
@prashantjha654 7 жыл бұрын
where do u live Sir, I want tution from you
@brianlaudrupchannel
@brianlaudrupchannel 9 жыл бұрын
so whats encapsulation mean? :(
@cartoonforkids7510
@cartoonforkids7510 6 жыл бұрын
should i learn java or python
@suryateja7525
@suryateja7525 6 жыл бұрын
Cartoon for kids, if you are good at java, learning python won't be a big deal, so start with java, then learn python too
@akashgupta6974
@akashgupta6974 7 жыл бұрын
last line Mai sop(obj.getI()); hoga Ni to cannot find symbol aye ga .......
@niitnh7683
@niitnh7683 5 жыл бұрын
some real time example for encapuslation???
@ikramasharfi5047
@ikramasharfi5047 7 жыл бұрын
pls add program for automorphic no. in java
@Chandral
@Chandral 5 жыл бұрын
Please turn off auto-focus
@merryz091
@merryz091 8 жыл бұрын
outstanding everything in all lectures.............
@chaitanyayarramsetti7336
@chaitanyayarramsetti7336 6 жыл бұрын
sir please make another video on encapsulation
@AshiksTechVlog
@AshiksTechVlog 5 жыл бұрын
video isn't clear
@brianlaudrupchannel
@brianlaudrupchannel 9 жыл бұрын
Why is HD 1080 look awful in your video?
@ismaelahumada929
@ismaelahumada929 8 жыл бұрын
+billyblackburn87 clearly just bad camera focus.
@SHUBHAMSINGH-mi7qf
@SHUBHAMSINGH-mi7qf 7 жыл бұрын
sir video quality is not good.......even in hd
@subodhsharma5928
@subodhsharma5928 9 жыл бұрын
Excellent lectures -it makes concept very clear -provide lectures on coding
@thanualekhya4413
@thanualekhya4413 9 жыл бұрын
please provide more lectures on coding part
@aarushigupta1106
@aarushigupta1106 9 жыл бұрын
sir if private variables can be modified out side the class though through methods indirectly then how does encàpsulation provide security or whats it use?
@faisalchaudhary311
@faisalchaudhary311 9 жыл бұрын
+Aarushi Gupta In Encapsulation, Public methods can access/modify only those private variable which are define in the public method and rest of the private variables are not accessible/can't be modified by public methods. This is how encapsulation provides security and it depends how you use Setter/ Getter methods.
@khadijafatima271
@khadijafatima271 4 жыл бұрын
Pl make a clear video
@m.alshammari2305
@m.alshammari2305 8 жыл бұрын
()Great Job Dude, but you should put Obj.getI
@vaishnavibhavsar1849
@vaishnavibhavsar1849 Жыл бұрын
Thank u sir😊
@thinkingdev102
@thinkingdev102 9 жыл бұрын
In all the codes I have never seen you using 'this' keyword? Is it not mandatory? I really don't know where to use and where not to.
@chiragkini
@chiragkini 8 жыл бұрын
wanted to refer to current intances like use this when u have ambiquity with names For eg: public Class Example{ private int x; public void setX(int x){ this.x=x; // here this.x is member variable. } }
@thinkingdev102
@thinkingdev102 8 жыл бұрын
Thanks Chirag.
@manishsinghrawat6879
@manishsinghrawat6879 3 жыл бұрын
The content of this video is too good. Well done sir👍
@Shifan76
@Shifan76 7 жыл бұрын
Hi, above code throws me an error, can anyone help me? thanks! class A { private int i; public void setI(int j) { i=j; } public int getI() { return i; } } class MainClass { public static void main() { A obj=new A(); obj.setI(5); System.out.println(obj.getI()); } }
@rishabhsharma667
@rishabhsharma667 7 жыл бұрын
You are making mistake in main method.Main method syntax is Public static void main(String args[ ])
@Shifan76
@Shifan76 7 жыл бұрын
Hey, thank you so much dude, i have made a mistake in the main method syntax, now it works.
@saishmhatrearts
@saishmhatrearts 8 жыл бұрын
awesome explaning in all videos
@sureshkone4864
@sureshkone4864 9 жыл бұрын
excellent tutorial and thank u
@unknown65549
@unknown65549 6 жыл бұрын
Something wrong in the main() ! This Statement Should be like; System.out.println(obj.getI());
@chitrakurupati8196
@chitrakurupati8196 5 жыл бұрын
Correct
@NirajPRoxx
@NirajPRoxx 5 жыл бұрын
You are amazing, you making it so easy to understand. Thank you sir.
@dogfish9965
@dogfish9965 8 жыл бұрын
great lesson. Easy to understand
@deograciousngereza4883
@deograciousngereza4883 9 жыл бұрын
waoow i think everybody got it well , congratulations bro
@sagarroy6649
@sagarroy6649 5 жыл бұрын
video quality is poor
@kamalpandey4807
@kamalpandey4807 6 жыл бұрын
Sir video is not clear
@ashwanikumarkumar7119
@ashwanikumarkumar7119 7 жыл бұрын
The best explaination
@sherothkar5809
@sherothkar5809 6 жыл бұрын
Max effort never waste keep going. sir!
@pemawangyal9231
@pemawangyal9231 9 жыл бұрын
Explanation is so clear and plain. Thank you Sir
8.2 Encapsulation Example in Java
4:05
Telusko
Рет қаралды 158 М.
8.3 What is Inheritance in Java | Lecture | Tutorial
8:53
Telusko
Рет қаралды 224 М.
Please Help This Poor Boy 🙏
00:40
Alan Chikin Chow
Рет қаралды 23 МЛН
Inside Out 2: ENVY & DISGUST STOLE JOY's DRINKS!!
00:32
AnythingAlexia
Рет қаралды 13 МЛН
Spongebob ate Patrick 😱 #meme #spongebob #gmod
00:15
Mr. LoLo
Рет қаралды 20 МЛН
Officer Rabbit is so bad. He made Luffy deaf. #funny #supersiblings #comedy
00:18
Funny superhero siblings
Рет қаралды 14 МЛН
MultiThreading in Java Theory
10:53
Telusko
Рет қаралды 834 М.
7.16 How to use Static Block in Java Tutorial
6:21
Telusko
Рет қаралды 136 М.
Riot just Confirmed HUGE Valorant Update!
9:44
Dittozkul
Рет қаралды 37 М.
Radxa X4: An N100 Pi
20:48
ExplainingComputers
Рет қаралды 60 М.
8.7 Polymorphism in Java
9:10
Telusko
Рет қаралды 277 М.
8.17 Abstract Class in Java Tutorial Theory
8:30
Telusko
Рет қаралды 223 М.
8.20 What is Interface in java with example
8:00
Telusko
Рет қаралды 171 М.
#4.2 Constructor in Java Theory
10:55
Telusko
Рет қаралды 415 М.
Please Help This Poor Boy 🙏
00:40
Alan Chikin Chow
Рет қаралды 23 МЛН