Hey Abhilash! The day I watched this video just after receiving your channel update, the very next day I had my interview and guess what the interviewer asked me this particular question and he had given me the exact same example (every bit was similar) and I also gave him the same explanation and guess what I cleared that round. The moment I heard this question I was like thank you , thank you Abhilash for this video, it saved one of my opportunities. You are fab man! Thanks a ton :) Keep teaching, I will keep learning :) Bless you
Just randomly watched this video and ended up liking and subscribing the channel. It's so good to see that you guys are contributing so much in training and educating the developer's community.
Lovely explanation! But still there is a catch which can break this I think : in student constructor you are directly assigning adress ex : this.address = address; It's should be something like this.addres = new Address ( adress.city , adress.state, adress.country) . Because when you created adress in main method , you still know that refrence . So alway clone before assigning in constructor
You are doing awesome Job, I have literally cracked interviews of many companies by watching your Spring concepts, thanks so much for your valuabe teaching,also please if possible create video for microservices with spring boot also.
superb, i wasn't aware of so many other possibilities, Thanku so much. definitely it will be very helpful in the interviews & thanks for sharing the real time approach also as it wouldn't be a new thing in future coj of your informative videos. Really each & every aspect is covered.
I went to your website and saw Spring boot course and it costs 15000 !!!! Why man why.. U r the best trainer for me .. Everyone can't offord such high price course. I request u to add your course in udemy with much less cost. ☺🙂
Sir, I am very helpful and lucky that i am able to learn n understand Java / spring by your uploaded youtube video. I request you to provide spring boot and spring microservice video tutorial in upcoming days asap. please...!
Could you please upload Java core videos (I am very excited to learn the fundamentals from you. You are covering the in-depth knowledge which on one covered in my knowledge so far..)
Nicely explained....I have one double ,what is the use of making the class final as already all the data members are final ,no setter method, get method is not returning the original object.
I have a question, what if the Address object that is being used to pass to the Student class constructor is manipulated. The method, where we are creating the Address object has the reference to it. Now though the student object cannot be used to manipulate Address, but the address reference can still manipulate the Address Object inside the Student Object. I think we should clone the passed Address Object as well and then assign it to the Student address member.
Student1 s=new Student1(1, "gayathri"); System.out.println(s); s=new Student1(2,"devi"); System.out.println(s); with this the values we can change right even though the variables are final
Hi Abhilash, In this Student Class constructor, i think we need this.addr = new Address(addr.city,addr.state); this statement instead of directly assigning the reference like this this.addr = addr i hope this is the correct way.correct me if it is wrong.
Hi Abhi, The point you mentioned during explanation of advantages of Immutable objects - "thread safety is guaranteed because data inconsistency is avoided in a multi-threaded environment". How can data inconsistency arise for a immutable object when it cannot be modified in the first place? or did I miss something?
Appreciate your teaching ways with explanation but if you make it within 10 minutes video not 40, 50 minutes for a small topic. That would be great for learner otherwise will skip
Everything is good Abhilash the only thing I wanted to say, some portion of the video is a little exaggerated which is not required, the video could have been a little short.
Hi Abhilash, it's very clear and nice video. I have doubt can we give clone object of addres obj in the get method of student instead copy constructor. As implementing colnable interface in address class
Hi @Selenium Express, is the below code too violation of immutable class. If yes, please help in correcting. Address address = new Address("MAA", "Tamil Nadu"); Student student = new Student("Me", 20, address); System.out.println(student);
but what if we change the content of Address class object using homeAddress object here we are creating separate copy so it works as expected. try this example: Address homeAddress=new Address("delhi", "Delhi", "India"); ImmutableClasses ic=new ImmutableClasses(1,"Aashish",homeAddress); System.out.println(ic+" "+ic.hashCode()); homeAddress.setCity("Kotdwar"); homeAddress.setState("Uttarakhand"); System.out.println(ic+" "+ic.hashCode()); Rest everything is fine we can add below lines to the constructor of Immtable class-> public ImmutableClasses(int id, String name,Address address) { this.id = id; this.name = name; Address clone=new Address(address); this.address=clone; } it will change the content of homeAddress object. @selenium express please correct me if i am wrong.
Your example has 1 bug. If you do any changes in homeAdress object then it will break immutable class concept. Don't take it otherwise. I have been learning very good concepts from your videos
Why are u repeating the same thing too many times and wasting our time. It's a 10 min video. Bro Better don't do videos seriously frustrating and wasting time by repeating
Hi Abhilash, Very impressive explanation :) But I have a doubt - Immutability means " Once an object is initialized, we are not allowed to change its content(value). And when we try to change its content, if there is any change in the content then new object will be created, if there is no change in the content then the original object should be returned" . Just given String behavior example below.... package com.corejava.string; public class StringTest { public static void main(String[] args) {
String str1 = new String("Murali"); String str2 = new String("Murali"); String str3 = new String("Murali Tekumatla"); String str4 = str1.replace('M', 'M'); String str5 = str1.replace('M', 'T');
} } Output: str1 ======Murali=======-1978977868 str2 ======Murali=======-1978977868 str3 ======Murali Tekumatla=======1155040398 str4 ======Murali=======-1978977868 str5 ======Turali=======-1778573811 str1 ======Murali=======-1978977868 1. In above example, str1 created. 2. str2 object created with same content hence it return original object as hashcode is same as str1. 3. str3 created with differenct content hence new obj is created with diff hashcode. 4. str4 - trying replace char 'M' with 'M', no content change hence original obj is returned. 5. str5 - trying replace char 'M' with 'T', content change is there hence new obj is created. I think we are missing this behavior in our Student-Address example in this video - can you please comment on this. - Thanks
Hey Abhilash! The day I watched this video just after receiving your channel update, the very next day I had my interview and guess what the interviewer asked me this particular question and he had given me the exact same example (every bit was similar) and I also gave him the same explanation and guess what I cleared that round. The moment I heard this question I was like thank you , thank you Abhilash for this video, it saved one of my opportunities. You are fab man! Thanks a ton :) Keep teaching, I will keep learning :) Bless you
Congrats, Pranoti ! 😊
Just randomly watched this video and ended up liking and subscribing the channel.
It's so good to see that you guys are contributing so much in training and educating the developer's community.
Lovely explanation! But still there is a catch which can break this I think : in student constructor you are directly assigning adress ex : this.address = address;
It's should be something like this.addres = new Address ( adress.city , adress.state, adress.country) .
Because when you created adress in main method , you still know that refrence . So alway clone before assigning in constructor
You are doing awesome Job, I have literally cracked interviews of many companies by watching your Spring concepts, thanks so much for your valuabe teaching,also please if possible create video for microservices with spring boot also.
Your video defines how much effort you have puted when you have learnt this concepts
Clean... Clear... Crisp.... This is one of the best explanation i ever heard. Kudos to you all.
Your teaching like feed with spoon for students, The best lecturer in RUclips, he must get more subscribers !!!!!!
superb, i wasn't aware of so many other possibilities, Thanku so much. definitely it will be very helpful in the interviews & thanks for sharing the real time approach also as it wouldn't be a new thing in future coj of your informative videos. Really each & every aspect is covered.
I went to your website and saw Spring boot course and it costs 15000 !!!!
Why man why.. U r the best trainer for me .. Everyone can't offord such high price course. I request u to add your course in udemy with much less cost. ☺🙂
Sir, I am very helpful and lucky that i am able to learn n understand Java / spring by your uploaded youtube video. I request you to provide spring boot and spring microservice video tutorial in upcoming days asap. please...!
Abhilash I got selected just watching your tutorials. THANKS A LOT TON CRORE...subscriber 🙏
Clear and Crisp Explanation Abhilash. Thanks for sharing.
Brother im completely impressed. I never understand this topic before like that
Damn man once you start watching his videos there is no go back ♥️
again watching this video literally so great informative video..
Love u bro... u r a motivation an inspiration... the reason i started finding interest in coding
❤❤
One of best video on Immutable class
Big thanks man. Way of teaching is great.
Could you please upload Java core videos (I am very excited to learn the fundamentals from you. You are covering the in-depth knowledge which on one covered in my knowledge so far..)
Nicely explained....I have one double ,what is the use of making the class final as already all the data members are final ,no setter method, get method is not returning the original object.
Hi Mr Abhilash i miss you soo much. I miss also your videos. You are the best teach in youtube you must know that.
Happy to see after longdays
Instead of creating clona object for address do convert into immutable of address class then state of data won't change right
Increasing confidence on java.. Thank you 😍
Great to have you back Sir. Eagerly waiting for the follow-up video. 👍🏼
Hi Abhilash Thnaks for this video, that's very great each and exery step explained well, can you please make one video on complete Data JPA
very well explained sir.Thank you for this video.
Great explanations....really helpful for interview
You deserve a beer bro...superb explanation 💪💪
I have a question, what if the Address object that is being used to pass to the Student class constructor is manipulated. The method, where we are creating the Address object has the reference to it. Now though the student object cannot be used to manipulate Address, but the address reference can still manipulate the Address Object inside the Student Object. I think we should clone the passed Address Object as well and then assign it to the Student address member.
Student1 s=new Student1(1, "gayathri");
System.out.println(s);
s=new Student1(2,"devi");
System.out.println(s);
with this the values we can change right even though the variables are final
Abhi, try to add more live interview..it's interesting to watch and helpful that how to present during interview. Nice explanation.
Hi Abhilash, In this Student Class constructor, i think we need this.addr = new Address(addr.city,addr.state); this statement instead of directly assigning the reference like this this.addr = addr i hope this is the correct way.correct me if it is wrong.
Thanks Abhilash ☺️
Hi sir finally I got job in mnc company after seeing your videos so many thanks to you
Congratulations 🎊 All the best !!
This was really helpful content. Thanks Abhilash
Hi Abhi,
The point you mentioned during explanation of advantages of Immutable objects - "thread safety is guaranteed because data inconsistency is avoided in a multi-threaded environment".
How can data inconsistency arise for a immutable object when it cannot be modified in the first place? or did I miss something?
Very Nice Explanation!!
Appreciate your teaching ways with explanation but if you make it within 10 minutes video not 40, 50 minutes for a small topic. That would be great for learner otherwise will skip
Everything is good Abhilash the only thing I wanted to say, some portion of the video is a little exaggerated which is not required, the video could have been a little short.
Amazing explaination
Hi Abhilash, it's very clear and nice video. I have doubt can we give clone object of addres obj in the get method of student instead copy constructor. As implementing colnable interface in address class
Very nice quations
good explanation. thanks.
Is been a while. Good to here from you.
Amazing video, Abhilash.
Hi Abhilash
Can you take concurrency Concepts in Java and make videos?
Simply awesome
hi brother, plz make the video in ......."debugging concepts" .....in java
super..
Hi @Selenium Express,
is the below code too violation of immutable class. If yes, please help in correcting.
Address address = new Address("MAA", "Tamil Nadu");
Student student = new Student("Me", 20, address);
System.out.println(student);
address.setCity("BLR");
address.setState("Karnataka");
System.out.println(student);
Hey
in which video have you explained why to declare immutable class as final?
please link it
but what if we change the content of Address class object using homeAddress object here we are creating separate copy so it works as expected.
try this example:
Address homeAddress=new Address("delhi", "Delhi", "India");
ImmutableClasses ic=new ImmutableClasses(1,"Aashish",homeAddress);
System.out.println(ic+" "+ic.hashCode());
homeAddress.setCity("Kotdwar");
homeAddress.setState("Uttarakhand");
System.out.println(ic+" "+ic.hashCode());
Rest everything is fine we can add below lines to the constructor of Immtable class->
public ImmutableClasses(int id, String name,Address address) {
this.id = id;
this.name = name;
Address clone=new Address(address);
this.address=clone;
}
it will change the content of homeAddress object. @selenium express please correct me if i am wrong.
pls upload the video for spring boot snd microservices
Quality content 🔥🔥
can you make a vedio of spring mvc with firebase push notification.
💫
Thank u so much!
Great stuff 🙂
❤❤❤
I think one scenario is missing. If I have list object, how will you deal with that? This scenario should be covered.
Good stuff
Abilas we waiting for spring boot course over 1 year, and now we must to pay. That course is most important to us for job.
A tip: you can watch series on flixzone. I've been using them for watching lots of of movies lately.
@Nico Lucian Yup, been watching on Flixzone for since november myself :D
Hi
I have one query:
Can we create a duplicate object of the immutable class using serializable or reflection API?
s
You missed FINAL keyword before class consequences
Please give me a favor i need to learn spring boot can you post some videos about it. Sorry for my English
So you will be creating new object for each get method. Is this a correct approach
Your example has 1 bug. If you do any changes in homeAdress object then it will break immutable class concept. Don't take it otherwise. I have been learning very good concepts from your videos
Yes. To fix this, you need to change the student constructor
I used cloning for address object
In Address class, implement Clonable and add clone method. @Override protected Address clone(){return new Address(this.city,this.state,this.country); }
And in Student constructor
public Student(int id, String name, Address address) {this.id = id; this.name = name; this.address = address.clone(); }
Waiting for spring boot microservices video
Is that penny from big bang theory
Isn't this kind of copying things called "defensive programming"?! Correct me if i'm wrong
When is the next session??
Hey Abhilash! You really have put on some weight.😂
😅
Why are u repeating the same thing too many times and wasting our time. It's a 10 min video. Bro Better don't do videos seriously frustrating and wasting time by repeating
pahle toh apna pronunciation correct karo...Please dont try to sound like foreigner .Be you ,be original
Hi Himanshu ! Thank you for taking time and writing a feedback.🙂
You put on weight u were good when u was lean🤣
Your knowledge directly proportional to weight
😂😂
Boss sorry but your videos are too lengthy, really difficult to watch such a long video for small topics..
Hi Abhilash,
Very impressive explanation :)
But I have a doubt - Immutability means " Once an object is initialized, we are not allowed to change its content(value). And when we try to change its content, if there is any change in the content then new object will be created, if there is no change in the content then the original object should be returned" . Just given String behavior example below....
package com.corejava.string;
public class StringTest {
public static void main(String[] args) {
String str1 = new String("Murali");
String str2 = new String("Murali");
String str3 = new String("Murali Tekumatla");
String str4 = str1.replace('M', 'M');
String str5 = str1.replace('M', 'T');
System.out.println("str1 ======" + str1 + "=======" + str1.hashCode());
System.out.println("str2 ======" + str2 + "=======" + str2.hashCode());
System.out.println("str3 ======" + str3 + "=======" + str3.hashCode());
System.out.println("str4 ======" + str4 + "=======" + str4.hashCode());
System.out.println("str5 ======" + str5 + "=======" + str5.hashCode());
System.out.println("str1 ======" + str1 + "=======" + str1.hashCode());
}
}
Output:
str1 ======Murali=======-1978977868
str2 ======Murali=======-1978977868
str3 ======Murali Tekumatla=======1155040398
str4 ======Murali=======-1978977868
str5 ======Turali=======-1778573811
str1 ======Murali=======-1978977868
1. In above example, str1 created.
2. str2 object created with same content hence it return original object as hashcode is same as str1.
3. str3 created with differenct content hence new obj is created with diff hashcode.
4. str4 - trying replace char 'M' with 'M', no content change hence original obj is returned.
5. str5 - trying replace char 'M' with 'T', content change is there hence new obj is created.
I think we are missing this behavior in our Student-Address example in this video - can you please comment on this.
- Thanks