Transcript for:
Java String Handling Deep Dive

[Music] you in the last two videos we covered about immutability mutability equals method what is the difference between sting and sing before okay up to that clear now the next case is very important case right sir if I can't a string yes is equal to new string of juga string yes he's equal to new string of druga next string yes is equal to du --ga what EDA difference between these two things can you please tell the most dangerous point string s is equal to new sting of druga string s is equal to draaga what is the difference between these two things friends the most dangerous concept next da almost up another discussion based on this example only you require two lesion very very carefully sir can you please tell what the difference between these two things swinging a silicon using of druga stingiest is equal to druga remember that in the posture case okay in the posture case two objects will be created but in the second case only one object will be created remember that in the posture case two objects will be created but in the second case only one object will be created how we read are very the difference it's not like do you know whenever we are using new operator whenever we are using new operator compulsory universe it will be created in the hip area okay Veta contain two Duga and ax you see the reference variable for this forgetting inter-country Duga you see the reference variable for this next our new string of druga new string of droga sorry it's a little bright for you first string the literal for the future purpose okay one object will be created in SCP area forgetting what is that yes P string a constant a pool remember this one what it is yes it is a string a constant the pool okay you new object will be created in the ACP area survey D the reference variable no explicit reference variable but internally implicit reference variable will be maintained by the JVM can immediately Mosca serve I did the deed of this one the need of this one is reusing same object for future purpose are getting so two objects will be created one is in the hip area yes he's pointing to that heap object another copy will be created in ACP area for the future purpose sir water future purpose simple point you should have a reuse operating in the next level examples you can able to get okay well then immediately Mosca sir this object this object is available for garbage collection not not no no because implicitly implicitly reference variable will be maintained by JVM if any object created because of because I'm string the constant Litoral Litoral Litoral implicit reference variable will be maintained by JVM this object is not eligible for garbage collection remember that but immediately you may ask her suck this year CP v r TC area is there until 1.6 version until 1.6 version yes CP it apart ah sir me that a year yeah method again yeah yes if it apart of method area are permit Jen are getting like permanent permanent generation okay hit the bottom method area are permit Jen okay like buttah from one point seven version onwards for efficient memory utilization sir ACP area is moving to keep only okay in the hip area some water reservoir for SCP okay in the in the permian do you know meter area yes CP zombies fixer sizes but once it is more to the paper no my ACP can expandable regarding so just because of memory utilization you can just stuff from 1.7 version and word this SCP is move order to okay apparently remember but whoever Chan it is a part of me that area but not inside hip area okay well sub this is just for internal sake but anyway you are not required to worry so here how many objects you got can you attend two objects got created one is in the hip area second one in the ACP yes he is always pointing to that hip area right so quietly subject to play Sarah this object up for future purposeful what is that future purpose I will explain in the future don't worry about that okay well but in this case string EEOC's equal to du gard easy collateral or not yes it's a literal it's an apron something you know in this case in this case only one object will be created in the SCP year yeah in this case only one object will be created in SCP year yeah remember this concern in the ACP only one object will be created you see the reference point will do that but anyway mistake JVM will check is there any object the content with this content already available in there CPR now if it is already there if it is already there then only then only so then it is going to reuse the same object if the object is not already there then only the new object will be created and yes he's pointing to that but anyway object at creation in the hip area is always mandatory whenever we are using new operator compulsory a new object will be created but uh if you are going to create like this so object creation is not mandatory pasta JVM wheelchair in the SCP area do you have any object within this content or not if the object is already there ryuuta same object so if the object is not already there then only create a new object that's all so what is the difference between this one under this one UD scare total hominy object you are created to object will be created under in these case how many objects will be created sir only one object that in the SCP area that's not no sir why it is a second object placed in SCP because the reason is for future purpose flour we use reusable deep purpose look at this object not having any reference easy to people forgot my collection aetna sorry it is not visible for garbage collection because internal difference will be maintained by JVM itself clear sir in the last example just we had a discussion about the keep and ACP object creation let me continue some more example so that you people can get much cloud directive here observe I'm taking string s1 is equal to new string off Duga string s1 is you got you still got broken string yes 2 is equal to new string ah-oogah string s2 is you continue single Turki next string yes sir 3 is equal to-- daruka string s 3 is equal to Trueba string ha yessuh 4 is equal to 2 string s4 is equalto troopa Tata can you please tell just because of this line how many objects would got created yeah respond just because of this line how many objects have got could get it how many are there in the general heap how many are there in the SCP yet done please confirm total ammonium Jake's got created is it only one object to object R 3 R 4 R 5 are getting R 5 r 6 how many how many will be there in the hip area how many will be there in SCP area yes if we want to be have some guess in your mind so that you can able to understand dancer very clearly if I start explaining can you please guess how many up there in the hip area - how many are there in their City area huh remember okay just let me start explanation so that you people can feel more comfortable right here do you know after first align deep area SCP area no legend legend there are some conclusions also I want to talk string s1 is equal to new singer Drogo whenever we are using new operator sorry any website will be created in the hip area remember compulsory you new object will be created in the hip area that's why Durga Durga yes someone is pointing to him next it is a literal literal right for the future purpose one copy will be maintained in the ACP area yes CP area right okay been sub just took because a post line how many objects got to get it to objects got created one is in the hip area second one in the ACP area no string s2 is equal to neo stink after ooga singing STDs you called me on string of Durga so now whenever we are using new operator come on sir can you object will be created sir in the hip area can you watch it will be created yes - next ah this a copy has to place in the ACP but in ACP Durga contain all of the object is available or not yes if it is already there we are not required to place remember this one already care we are not required to place okay second line also completed trinka yes sir three is equal to do god where I require to create the subject I told already in the last example where I record a cricketer subject in the SCP area but in ACP area object creation is always optional posture JVM wheelchair is there any object already already pointing already not having the same content or not if any object already having the same content then existing object will be reused it won't create a new object that's why string yes a three yes a three is also pointing to druga string yes four is equal to druga yes up for is also pointing to the graph yes four is also fine filter Durga one day now can you please confirm total total sir how many objects got created only three objects got created one is in the ACP area two objects in the heap area right so the conclusion is whenever we are using new operator compulsory you watch it will be created in the hip area that's why there may be a chance of existing two objects are with the same content in the hip area yes Isidro god raga sim kundan de ba there is no chance of existing two objects with the same content in the ASAP area remember these ones are in the ICP area with CM contain only one object will be there same object will be reused multiple times so internally memory will be C over memory utilization will be improve all right clear now you for knowledge about ACP on the heap from zero to twenty percent price I'm sure if I will go for two more two or three more example then you will get much clarity don't require to worry to this clear so the next example related to heap and ACP I will upon sir string s is equal to new string of druga string is equal to string of draaga yes sir doctor can get up software yes sir is equal to your start can't get up solutions okay well can you please tell total how many objects will be created in the hip area how many there sa P area how many there can you please yes friends can you please tell total how many objects will be created how many present in the hip area how many present in SCP area yes okay well so compulsory you people should know some answer in your mind okay maybe 3 4 2 4 or 6 for something like you should have some clarity okay now have a look once period general heap and the SCP area poster line string a city called new string of Duga what this one not required to keep any explanation even in the last two examples also we covered yes is equal to using of druga one copy will be created in the hip area for the future purpose another copy will be created in SCP area okay well Duga like this yes sir da can get all software yes a dot can get our software software like this I'm taking some do you know yes sir that can get up software here abjure software easy a string literal software is a string a little later but if restring a literal one copy will be created in the string concerned full because the name a we observed string constant a pole it is doing a constant string electro means a string constant for a first finger constant one copy will be created in the SCP area that's why a faster software will be created in the SCP area ok software got created in ACP area okay Ben next yes do you know so yes sir doc can get up software already what is yes yes it druga container software draaga software do you know so string is immutable you can't change the content if you are trying to perform the change compulsory new object will be created do you know because of runtime operation may be made that a call because of runtime operation if an object is required to create that option is always going to create only in the hip area but not in ACP remember this one sir sir I call can get because of that univox it will be created runtime operation if an object God created that the new object will be created only in the hip area but not in ESCP yes see Pimenta far constants string literals ax not because of from running operation created objects so now yes Eric can get up software yes he's already dooga doo Ruger software yaniv object got created forgetting durga software any website God created right okay for this a new object do you have any reference variable no no no we are not assigning to any reference variable that's fine this object eligible for got pay collection okay anyway it is eligible for GC next ah yes is equal to yes it are can get our solutions is here yes rot can get our solution solution solutions are is a constant string constant compulsory one copy will be there in the SCP year yeah okay solutions are easier contain easy easy one copy will be there in the SCP area because it's a string electron why for every single a troll one copy will be created in a city for the reusable D purpose next time yes sir the arc can get absolution because he is always pointing to druga durga that target of solutions now Duga solutions will be created a new object because of runtime operation if an object is required to create that object is always going to be placed only in the area next uh DISA resulta we are assigning to yes here I 70s now onward this yes sir is pointing to this object regarding a 1 watt TCS is pointing to this object if you print yes happily your content through girl solutions that's all can you please tell total how many objects were created how many there in the hip area how many there in the SCP six up chicks got created because of the score three present in the hip area three present in the ASAP under these are two objects eligible for garbage collection only these objects not eligible for garbage collection in the heap anyway these are not eligible for DC because implicit reference variables will be maintained by J YUM now are you getting clarity okay I hope but just to take a bit special care so for every example you are going to learn some new thing maybe after one not pre-exam 'pl yes all the things are going to be completed then you will get much clarity about this concept clear for love read but keep on listening very important [Music]