Please Comment, Subscribe and Click Bell🔔🔔🔔 Icon for More Updates. To learn software course from our experts please register here for online training: goo.gl/HIB0wL
@adaylightsmile79614 жыл бұрын
(wrong) --------------> ( not immutable 00:10:51 ) [{there actually I confused}] in the previous diagram if the string is given as mutable then only we get NULL and only IM-MUTABLE WE GET 1 Value. [{ Finally whole Explanation is GOOD }].. :) i am here to help you by mentioning that and then concept will get helpful
@anudeepyendrapalli43568 жыл бұрын
Excellent sir.Good to see you on youtube. please do Keep posting videos like this to enjoy your lecture. 4 years back when I was a fresher I have learnt Java from you and now I am working for MNC. Thanks a lot for your dedicated teaching and inspiration.
@jvsnyc4 жыл бұрын
Watching this, I realize I once failed an interview by suggesting that a mutable object could be used as a key in a map!! The question wasn't posed in such an obvious way, I never would have gotten that wrong. While discussing a solution they asked "So, what else could we have used as a key here?" and might have suggested the mutable object as a possibility. I said "Yeah, sure" because I was nervous and wanted to get whatever else in. They had a lot of candidates and someone got to say "Yay, we just narrowed down." I really didn't realize it until just now watching this discussion. Knowing something well enough to answer a question phrased directly is different from knowing it well enough to see it and deal with it in the wild. I see how preparing one for these kinds of things that affect both ones code and interviews is being considered by these teachers.
@hireme38647 жыл бұрын
Sorry, but your theory and example does not make any sense. Below is the reason for String being immutable Security: parameters are typically represented as String in network connections, database connection urls, usernames/passwords etc. If it were mutable, these parameters could be easily changed. Synchronization and concurrency: making String immutable automatically makes them thread safe thereby solving the synchronization issues. Caching: when compiler optimizes your String objects, it sees that if two objects have same value (a="test", and b="test") and thus you need only one string object (for both a and b, these two will point to the same object). Class loading: String is used as arguments for class loading. If mutable, it could result in wrong class being loaded (because mutable objects change their state).
@mani16976 жыл бұрын
I totally agree with you
@vinodkumar-tn9uy6 жыл бұрын
Super explanation
@vinaysipayee84496 жыл бұрын
Awesome buddy..! (y)
@smitapadhi72146 жыл бұрын
i have lots of doubt in String chapter can anyone help me go get best way to understand this chapter, i need in very urgently.
@sagarshekhar62965 жыл бұрын
To the point....
@hareesh178 жыл бұрын
Hi Hari Krishna, This is a one good reasonfor String Immutability. I found few more good reasons for string immutability in StackOverflow thread. stackoverflow.com/questions/22397861/why-is-string-immutable-in-java String is immutable for several reasons, here is a summary: Security: parameters are typically represented as String in network connections, database connection urls, usernames/passwords etc. If it were mutable, these parameters could be easily changed. Synchronization and concurrency: making String immutable automatically makes them thread safe thereby solving the synchronization issues. Caching: when compiler optimizes your String objects, it sees that if two objects have same value (a="test", and b="test") and thus you need only one string object (for both a and b, these two will point to the same object). Class loading: String is used as arguments for class loading. If mutable, it could result in wrong class being loaded (because mutable objects change their state). That being said, immutability of String only means you cannot change it using its public API. You can in fact bypass the normal API using reflection. See the answer here.
@JavaHariKrishna8 жыл бұрын
Thank you for the valuable information Hareesh :-)
@AmitKumar-qh4ow7 жыл бұрын
Dear Sir, Thanks for the Video, I want to know that if we will use s1.toUpperCase(), it will change to HK but this object will be lost because s1.toUpperCase() is not referenced by same reference s1 or some other new reference.
@gadaakhil6 жыл бұрын
Hi Amit, That's not the case since the HashTable will still hold the reference to the lower case "hk" when we call hashTable.put("hk", 1), so it won't be garbage collected. Best Wishes.
@2singam4 жыл бұрын
Really it's very good nd clearly explained, thank you sir.
@noth3708 жыл бұрын
After watching this video ...My soul is saying only one word awesome Hari sir............
@erucky216 жыл бұрын
your soul has malfunction
@manashranjan12675 жыл бұрын
Thanks Sir Hari sir means Hari sir only whole team trying to convince that for pooling purpose string is immutable but Hari Krishna sir prove that why string is immutable
@prangshumaity90586 жыл бұрын
Super sir.no one can teach this point.this make your students unique from other.
@lawanutech99776 жыл бұрын
Hashmap uses generics HashMap.So,keys can be of different datatype too.It is not a strong reason for String Immutability.
@chrissmith21373 жыл бұрын
Other object equivalents of primitive datatypes like Integer, Long, Boolean, etc are also immutable.
@amitclick996 жыл бұрын
If you try to get Object obj= ht.get("HK"); means upper case then you will get null ..it means value 1 is not created for after making it s.toUpperCase();
@rajeshgupta24136 жыл бұрын
Great explanation sir. Thank you sir for deep explanation
@anandashok73014 жыл бұрын
First of all the way you used toUpperCase() is wrong. It will change the value and create another object in String constant pool, but it will not return the converted value to s1. The basic String Class operation.
@nanavanalla109 ай бұрын
HK sir didn't mentioned that "HK" will store in s1, they just making us clear that s1.toUppercase(); will not change the already existing value "hk" in String constant pool. If you want to create an object in string constant pool then need to create an string again like String s2 = s1.toUpperCase(); And then you can store in Hashtable as ht.put (s2, 4); If you perfect at Java then you will get it now atleast. Otherwise you can only do it from your side and execute it. String s2 = s1.toUpperCase(); this one HK sir didn't written so you confused I think, indirectly Sir telling that it should be stored in one more string and we can put in map.
@shekhar06sontakke5 жыл бұрын
Great explanation Sir!!
@arunchalla54535 жыл бұрын
One small correction, String s1 = "hk"; Hashtable ht = new Hashtable(); ht.put(s1, "1"); ht.put("Ravi", "2"); ht.put("Raju", "3"); s1.toUpperCase(); --> this should be s1 = s1.toUppercase(); to make s1 as HK System.out.println(ht.get("hk")); Your program has no effect on s1 as mentioned reason above. Moreover you need to pass ht.get(s1) instead of ht.get("hk") to see if calling s1.uppercase() has really changed the value from hk to HK. Just to make it clear, calling string methods on string value will not have affect untill you say s1 = s1.toUpperCase(); and observe that this is new object and that old object with s1 = hk is destroyed.
@meenakumari-ov9tx8 жыл бұрын
Thanq sir..your explained very neatly..it is easy to understand non IT students...please add collection videos also..
@JavaHariKrishna8 жыл бұрын
I will release Collection videos very soon. Actually these string concept videos are the prerequisites to Collection concept. In collection programming I will use all these String concepts, so first I recoded these concepts videos.
@135sudeep18 жыл бұрын
thanks Sir, I face this question in interview, now i can give the answer, I forget this answer because of long time. Ultimate video. eagerly waiting for your next videos.
@erucky216 жыл бұрын
i need to say your conscious is very neat
@girinani4357 жыл бұрын
you are one of the best in Ameerpet Institutes, Nice explanation , not only explanation, also you are trying to motivate
@karunkausal91513 жыл бұрын
Hello sir Today in one interview i have said this answer for string immutable but then interviewer asked me how is it possible string introduced in java Early and hashmap introduced later. So is it possible
@himeshgupta64783 жыл бұрын
I think string is a primitive so it should get passed by value in java( and all non- primitive obj are passed as references) and thus the map key shouldn't change.... Would be glad if you clarify me on this sir..
@saicharan92308 жыл бұрын
proud to be your student sir
@umeshnadargi2194 жыл бұрын
Great explaination
@akhilraj57515 жыл бұрын
very clear explanation. thanku!
@digitallearning-297 жыл бұрын
thanku so much sir....plz make these type of videos,..all the best sir...
@adaylightsmile79614 жыл бұрын
(wrong) --------------> ( not immutable 00:10:51 ) [{there actually I confused}] in the previous diagram if the string is given as mutable then only we get NULL and only IM-MUTABLE WE GET 1 Value. [{ Finally whole Explanation is GOOD }].. :) i am here to help you by mentioning that and then concept will get helpful
@chrissmith21373 жыл бұрын
Very nice explanation. You sound like that funny Indian Guru, Mr. Nithyananda.
@gadaakhil6 жыл бұрын
Very well explained.
@manmathkumarbehera41536 жыл бұрын
superb explanation Sir..
@jvsnyc4 жыл бұрын
A few people seem to be confused by the fact that he is showing "Here's what would happen if String wasn't immutable and .concat() or .toUpperCase() worked in place, instead of the world we do live in where String IS immutable and those methods make a new string somewhere else and give you back a reference to it (unless it already existed in String Pool of course)." On television and in movies, when they show something different from reality they make the screen all blurry or wavy to show it is just imagination, then clear it away when they come back to reality. Java Strings are immutable, functions that work on them make and return new objects. All kinds of weird and bad things that never happen to us in Java would happen otherwise. You should be very careful when using Maps to use keys that make sense. This little video is pretty important, and the fact that people came up with a few additional reasons is good but doesn't detract from this presentation.
@manishanker24888 жыл бұрын
string class introduced in Java 1.0 where as collection are introduced in 1.2 and what is the relation ship between string class and collection
@JavaHariKrishna8 жыл бұрын
In Java 1.0 we have a class called Hashtable collection, it will store objects in Key,Value pair format. So, for this class String and wrapper classes are created as immutable objects. In Java 1.2 more classes are added as alternative to Vector and Hashtable classes. I hope you got my point :-)
@karthikkasturi57808 жыл бұрын
thankyou sir for your video..but i have a question that..we use integer also as a key in hastable but it is immutable..why? plz explan about this sir?
@JavaHariKrishna8 жыл бұрын
Reason is same Generally strings and numbers are used as keys hash table for maintaining values. So String object and Wrapper classes(Byte, Short, Integer, Long, Float, Double, Character, Boolean) classes are created as immutable object classes.
@unpopular1236 жыл бұрын
@@JavaHariKrishna when we use string as key in hashtable , value for that key is actually stored against hashcode of key not against key, so i think your explaination is wrong
@arjunganesan49916 жыл бұрын
thank you so much.. you are awesome sir..
@challarajesh18157 жыл бұрын
good explanation. thank u sir please can provide the why eaquals() and hashcode() method and why override both methods
@subrahmanyampenkey11268 жыл бұрын
Perfect explanation
@rubenflores23187 жыл бұрын
Muy bueno, gracias (Y)
@kalyankumar28437 жыл бұрын
Superb explanations sir
@ervikassharma38258 жыл бұрын
This is Gud way to learn Java but sir Can u plz upload MultiThreading Videos plzz Sir
@finetechie55506 жыл бұрын
Sir, since String is final and immutable, why we allowed to modified with its new object,even though we can't use previous data
@ankittiwary37128 жыл бұрын
great explanation!!
@kalam48684 жыл бұрын
Excellent
@manjug15597 жыл бұрын
Good Explanation sir..
@shaileshsaxena15877 жыл бұрын
Thanks for explanations - why string is immutable -by HasMap.Please see belwo code import java.util.HashMap; public class MutableDemo { public static void main(String[] args) { HashMap m = new HashMap(); StringBuffer sb1 = new StringBuffer("jj"); StringBuffer sb2 = new StringBuffer("kk"); m.put(sb1, 1); m.put(sb2, 5); System.out.println(m); sb1.append('u');//performing operation on sb1 System.out.println(sb1);//it will print jju System.out.println(m.get(sb1));// it is giving output as=1 which initially inserted in map } } out put = {jj=1, kk=5} jju 1 Note = i am able to print value of key sb1 after performing operation on it. StringBuffer is mutable.
@damjandjordjevic19946 жыл бұрын
haha. did you figure it out, or did you forget about this comment?
@sunkararamarao32546 жыл бұрын
Super sir.....vvvvvvvnice.....
@Ravikumar-gj6qw6 жыл бұрын
Super explanation Sir tq
@akhileshkumarbhagat93197 жыл бұрын
Amazing explanation
@kuldeeptiwari-mm2cp8 жыл бұрын
sir plz once talk about singlton and its creation, uses and importance...............thank you sir
@nagabhushanamgaddam62928 жыл бұрын
Nice explanation sirr
@Rakeshkumar-fn1sv8 жыл бұрын
Thank you sir provide this video
@saikrishnahari8 жыл бұрын
Nice sir good explanation
@sagarikadas11968 жыл бұрын
Thank you so much sir
@rajeshchalla60857 жыл бұрын
good explain sir i u dont mind why hashcode()method and equals() override andsuppose not overriding what is problam.please explain sir
@skajharuddin68102 жыл бұрын
He is best
@tunikisandeep70868 жыл бұрын
Awesome !!
@ashoknuthalapati67278 жыл бұрын
HI Sir, Other than string we can also use all wrapper classes as key for storing in hashmap.
@JavaHariKrishna8 жыл бұрын
Yes
@NaveenKumar-bn5ov7 жыл бұрын
Nice explanation sir :) We want you to upload all core java tutorials.
@rajarajangeoraja6 жыл бұрын
You rocks sir.never expected this kind of superb explanation..Great..
@arpitmandlik13127 жыл бұрын
Thank you sir ji
@naseemahmad78978 жыл бұрын
thanks sir plz upload collection class video
@georgemichael25726 жыл бұрын
Thanks a lot ..one doubt. Can we modify string by +=operator ??
@kirani.2012 жыл бұрын
Mostly no
@ganeshgulhane88147 жыл бұрын
Sir can you please make the videos on threading concept in java
@srikanth296 жыл бұрын
Thank u sir. Very helpful
@venkateshtelugu75826 жыл бұрын
Hello Where did u completed ur b.tech
@srikanth296 жыл бұрын
who r u and y r u asking
@venkateshtelugu75826 жыл бұрын
I think ur completed ur b.tech in kurnool Is it right....
@srikanth296 жыл бұрын
no no
@ArunraajSingh7 жыл бұрын
*your theory is wrong sir,* get () method can pass only key type parameter. Even if string is immutable, get() method will return always null value until it passes a key-integer type value. get(2) = this will print "Ravi" get("hk") = will always print null
@anulearntech7 жыл бұрын
what is key type parameter? but key doesn't need to be integer only, it can be of any type including string, in fact you could even have a user defined object as a key.
@ArunraajSingh7 жыл бұрын
i didnt say that key can only be integer type. I said "get() method will return always null value unless it passes a key-integer type value."
@anulearntech7 жыл бұрын
Arun Singh how can get method pass, you will jave to pass na. and ill have to only pass a string to it if at declaration of collection is made in such a way hashmap a = new hashmap(); a.put("aap",1); a.put("bjp",2); a.put("cong",3); sysout(a.get("aap")); //should print 1
@sandyrockz8237 жыл бұрын
your logic right but its different in MAP INTERFACE.. instead of commenting straight away you should check it once.. in map if you are using get () method you need to give KEY which will give the value of the key.. Mr Hari krishna is very experienced java trainer in naresh it
@mallikarjun1007 жыл бұрын
nice sir
@lastminutejava82776 жыл бұрын
but we always do string x="raju"; than raju is a key but where is the value to stored in hash-table can you please explain me this
@divyangshah995 жыл бұрын
this is absurd , cant we directly pass s1 while getting the value , that way even if it has changed , will give the correct value ,
@piyush121217 жыл бұрын
We can create our custom class and use it as a key by overriding hashCode() and equals() method. What you said might be part of the reason but I don't believe it's true. Do you have any reference to SUN Micro systems claiming what you're saying? Did you even google the answer to this question ?
@JavaHariKrishna7 жыл бұрын
Dear Piyush Chaudhary, you are talking about custom object, I am talking about String object. Did you find is there any wrong in my explanation or did you find any explanation from sun docs about why strong is immutable, pls share us we are ready to learn😊
@piyush121217 жыл бұрын
@Hari Krishna By that logic "Integer" class is also mutable because of this reason. But wait, there is no Integer pool like String. I think your explanation is hilarious. Try putting your logic for this answer on StackOverflow and see how many up-votes you get.
@JavaHariKrishna7 жыл бұрын
Hi Piyush Chaudhary, I did not say Sting is immutable because for supporting String pooling. I gave different explanation. And thanks for referring stackoverflow site, pls check other comments one of the viewer also given comment on this video by supporting my explanation is correct with proof from stackoverflow site in this video I want to address pooling is not the main reason for making objects immutable, if so other objects wrapper classes and File class, no need to be created as immutable.
@piyush121217 жыл бұрын
Perhaps you did not understand what I said. I know you said String pooling is there because String is immutable. So by that logic they should have also implemented Integer pooling because Integer class is also immutable. Please read that guy's comment again. That guy never gave any proof. He just gave a URL which contains good reasons for string being immutable.
@jvsnyc4 жыл бұрын
@@piyush12121 I don't think it is just a coincidence, but it is funny. The reason that Integer io = new Integer( intValue ); is deprecated in modern versions of Java, in favor of Integer io = Integer.valueOf( intValue ); is precisely because they now implement.....INTEGER POOLING!
@meghathakur76606 жыл бұрын
Before attending core Java I were hate with core Java BT now I m fan of u sir
@kunalvarade296 жыл бұрын
How can we use object as key in Map?
@supriyasingh7637 жыл бұрын
But we can pass s1 in the get() method
@Dyslexic_Neuron5 жыл бұрын
what if we write s1=s1.toUpperCase() ??
@pravinkottawar7 жыл бұрын
Sir, Integer i = 20; i = 30; System.out.println(i); Output is 30 so how can Integer is immutable ?
@richcohen59367 жыл бұрын
wrapper classes represent primitive types, and primitive types are mutable. No they're not (and String isn't a primitive). But since primitive types aren't objects anyway, they can't really be called mutable / immutable in the first place.
@yuvanagasai33397 жыл бұрын
Sir plzz upload video on java.util.regex
@erucky216 жыл бұрын
no offence but why dont you teach in your native tongue or in a language you are good
@sureshg83266 жыл бұрын
You are discussed only one point of string class Immutable. there are other reasons also like
@yuvrajkthorat6 жыл бұрын
Yes...agree to many of you....this is only adavatage of string being Immutable.....string class did not become due to Hashmap
@harikrishnahkb5 жыл бұрын
Yes Suresh, I agreed with you, but in all cases you addressing are internally uses (key,value) only. So for easy understanding I just took Hashtable as an example.
@faheemahmadofficial77015 жыл бұрын
everything ends with a with this person ... personA stringA...etc
@devireddyfavreddy47856 жыл бұрын
What about int
@KrishnaGangaraju7 жыл бұрын
because of u guys lot of scrap in it from Hyderabad
@JavaHariKrishna7 жыл бұрын
Krishna Gangaraju can you pls share your thought on this topic, so that all we will learn from your ideas too. Just leaving one comment may not justify, try to correct my mistake if any and Help others to learn 😊
@niteeshchandanshire43814 жыл бұрын
Awesome explanation sir
@maheshagga94383 жыл бұрын
Nice explanation sir
@manojkumar-ul6ey5 жыл бұрын
Awesome explanation
@akhileshkumarbhagat93197 жыл бұрын
Unique explanation.
@divyangshah995 жыл бұрын
this is absurd , cant we directly pass s1 while getting the value , that way even if it has changed , will give the correct value ,