A precise breakdown of a fundamental concept that many claim to know but few implement correctly in practice. It successfully turns a dry interview topic into a clear lesson on robust software design.
Approfondir
Prérequis
- Pas de données disponibles.
Prochaines étapes
- Pas de données disponibles.
Approfondir
Xebia Interview experience Java DeveloperAjouté :
And about my rules and responsibilities, so I have developed several API in this project and I have written generic test cases as well. That is all about me.
Thank you.
>> [snorts] >> Sorry, I missed how many years do you have in the resume? I cannot find it.
Around 4.5.
>> 4.5. Yeah, yeah, sure. Okay, okay, fine, good.
So, are you comfortable in Java concepts? Yes.
>> For Java, right? Yes.
Can you please briefly explain me what is encapsulation in Java? Yeah, so encapsulation it means it wraps data and method into a single unit. It is called encapsulation. And we can say like it is a key concept. We can say like key point like encapsulation means data hiding. Class variable are usually usually declared private and access access to variable is provided through public like getter and setter methods and it helps protect data from unauthorized access.
Okay, okay.
What is the use of setters and getters?
Do you write any logic other than returning and setting that data?
Mhm.
So, set set Yeah, so in my project like I can say like I use setter for like set data and getter use for getting data.
Indirectly we can say and with the help of do and we can use at the rate data also we can use for this directly if we want to use.
What I mean is in the for example in the setter if I want to write some code, can I write in the setter code?
Before setting the data into class.
Is it Did you Have you ever written some code other than setting the data into the setter method? Mhm.
So, yeah, we can write like well validation logic we can write inside it.
Okay, okay. Okay, fine. So, that's they call it control access.
To data setting the data we are validating the data. So, that's you are writing in the validation.
Okay, fine. Do you know what is immutable objects in Java?
Yeah, so immutable it means we can't change immutable object it means like we can't change state cannot be changed after it is created.
Mhm. Yeah, so like all classes fields are usually we can say private and final.
Okay. Yeah, and the class does not provide we can say setter methods also.
Okay.
So, all methods are like whatever the getters can we use getters? So, we we use like value set only through my constructor and we use only like setter only we can say.
Setter or getter?
Setter only.
So, it does not provide setter only.
Sorry.
Okay, we don't provide the setter getter is allowed. Yeah, getter is allowed.
Okay, fine. So, I will show you one Java program related to this one. Mhm. Second.
>> [snorts] [cough] >> Yeah.
I'm sharing my screen. Mhm, okay.
Do you see the screen?
Yes, sir.
It's visible, right? Yeah. Yeah, visible.
Yeah, so like you said for example, we'll just Yeah. We have employee class.
Okay, this has three fields ID, name Department, okay. Like you said that private and final.
Mhm. I already followed the rules and also you said that constructor constructor is also is there ID, name and this one I'm setting the values in the constructor.
And here the getters.
Mhm, okay. I did not write the getter for get ID and get name. So, this is get ID get name.
Get ID comma get name. I did not write the full implementation here. Mhm. Okay.
And then get department. Mhm.
This is my employee class from here to here. Mhm, okay. So, now I have one more class department is a simple POJO class.
It is not immutable.
Mhm.
Constructor setters and getters. This is normal POJO class with department ID and department name. Okay, mhm. Simple POJO class nothing here nothing is there here. Mhm. What I'm doing is I'm creating I want to create employee like immutable object.
Employee is equal to new employee of one comma Gauss my name and new department one comma PD.
Mhm, okay. I'm passing the department object to this constructor employee class. Mhm. Okay, now what I'm doing is in the next line I'm asking get department. Mhm. That means in the employee class we have a getter that is called get department. I'm calling this method here.
And then I'm saying set department because the department has this one.
Set DEP. Mhm.
Okay.
So, here I'm changing the name because here I have the setters and getters of uh department.
Mhm.
So, now my employee class is not anymore uh immutable because I can change the content of department. That means this one.
This content.
I can modify the value inside this one.
Mhm. So, by calling the set department is equal to HR. So, I'm changing the value from PD to HR.
Mhm.
So, employee class is no because it is not possible to change the content of one comma Gauss because there is no setters in the employee class.
Mhm. But there is no setter for department also, but there is a getter.
Right? I'm using this getter get department rather than setter.
Mhm.
>> So, using the setter I'm getting the department. I'm setting setting the name. Set DEP is equal to HR. Mhm.
So, now how to deal with this case so that others cannot change my department name.
Department name.
So, for this uh So, in this case we can say like employee class like immutable class, but it is actually not fully immutable.
Yes. So, department >> Department is Yeah, department is the problem.
>> Yeah, yeah. So, we can say like a department is mutable object because it has a setter.
Yes, this is a mutable object. Yes. So, It has setter, yeah. Yeah, so we can say like even like department is final some we can We can say like if we like department final so still it can do like employee.getDepartment We can say like uh um mhm We can say It prevent the it prevent others from modifying the department. We use defensive copying we can say. Instead of returning the original department object we return a new copy of it. We can do it. Okay.
So, where do I make change? Do you mean in which method I have to make changes?
So, for this >> Or I can share or I can change share my code in your chat then you can copy paste and you can change the code so that it will work. Yeah.
Uh Sure.
Sure.
>> [snorts] >> I'm stopping sharing my screen. Okay.
You can share your screen and copy that in the notepad plus plus or notepad.
Mhm.
Is it visible for you?
Uh yes. Okay.
>> [clears throat] [snorts] [snorts] [snorts] [snorts] >> Shh.
Vidéos Similaires
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











