9.9 String is Immutable

  Рет қаралды 318,980

Telusko

Telusko

Күн бұрын

Пікірлер
@thefreeguy774
@thefreeguy774 Жыл бұрын
You are the best Java Instructor
@dhavalshah69
@dhavalshah69 5 жыл бұрын
I think when you do new String ("Navin") it will create a new object 103 - Navin in the heap memory. In the video it say it will refer to the same one
@seanjesuharun1784
@seanjesuharun1784 3 жыл бұрын
same doubt will the object be point to the memory address of string pool which having the string literal as "Navin"???
@DeepakKumar-dw1re
@DeepakKumar-dw1re 3 жыл бұрын
You are absolutely Right...
@AmanTheMystery
@AmanTheMystery 3 жыл бұрын
@@seanjesuharun1784 if any string is created using new keyword then for which a new string is created in heap memory , not in string pool..
@afsanacabu2290
@afsanacabu2290 2 жыл бұрын
Is this true? I read the same somewhere else. Iam confused now. If by using new keyword also it refers to string pool or if the value is stored in string pool,then what is the purpose of using string intern() method.
@soumyadipbhowmik2220
@soumyadipbhowmik2220 Жыл бұрын
My question exactly.
@shyamelakapalli1051
@shyamelakapalli1051 6 жыл бұрын
String s=new String ("syam"); if you use s.intern(); then only it points to string pool until then it points to heap.
@yuvarajs3747
@yuvarajs3747 8 жыл бұрын
Hai Navin Reddy, Please give us proper answer for String memory management and String is Immutable, In interview I told answer for string immutable As you taught in this video They rejected me in first round itself.
@namratasanger5745
@namratasanger5745 6 жыл бұрын
What they have asked you in interview regarding string can you tell me?
@ajithranrox5524
@ajithranrox5524 6 жыл бұрын
maybe its the Grammer!
@withlovesandeep4424
@withlovesandeep4424 6 жыл бұрын
@@namratasanger5745 same experience for me also.. Why String is immutable ? Difference between String str=String("abc") and String str1="abc"
@namratasanger5745
@namratasanger5745 6 жыл бұрын
@@withlovesandeep4424 they both differ because of how they point and store the data isn't that's the right answer?
@sarin374
@sarin374 6 жыл бұрын
ajithran rox 😂😂
@vibinvibs7841
@vibinvibs7841 4 жыл бұрын
thank you sir fr teaching us . u r one of the great teacher ever@ navin reddy
@harithkumar4501
@harithkumar4501 7 жыл бұрын
I watch complete adds on your videos , so that you can earn some money .
@mypersonal1997
@mypersonal1997 4 жыл бұрын
😂
@GodiPM
@GodiPM 2 жыл бұрын
Hell is wa8ting
@RohitShinde-xh7vo
@RohitShinde-xh7vo 2 жыл бұрын
🤣🤣🤣🤣🤣
@arfatbagwan48
@arfatbagwan48 2 жыл бұрын
🤣
@gyanajyotisahoo4366
@gyanajyotisahoo4366 2 жыл бұрын
Good job man 😂😂😂
@preetird8385
@preetird8385 3 жыл бұрын
@0:36 When Navin says "mutability is a crime" Me: "It's true..Corona should have been a String(immutable)" 😂🥲 April: 2021
@waxylayer8353
@waxylayer8353 3 жыл бұрын
Funny
@anshsarin19
@anshsarin19 3 жыл бұрын
its "Navin"
@preetird8385
@preetird8385 3 жыл бұрын
@@anshsarin19 lol ok bigger problems here.. I'll correct that using String buffer 👍
@Anushaaa_
@Anushaaa_ 3 жыл бұрын
😂
@SurajPandey-vi9gr
@SurajPandey-vi9gr 6 ай бұрын
Amazing Telusko you are such a good teacher
@AvidWanderlust
@AvidWanderlust 3 жыл бұрын
"Welcome back aliens" is immutable
@terrificsuper
@terrificsuper 5 жыл бұрын
Good work my dude
@EthicAITales
@EthicAITales 6 жыл бұрын
I cant find the app in play store. Wonderful videos. Crisp and clear explanation
@aymanmomin432
@aymanmomin432 4 жыл бұрын
Sir can you please make a video on heap and stack memory along with a separate video on a roadmap for desktop application developers
@shahriarmim4696
@shahriarmim4696 6 жыл бұрын
owwhoo ! Telusko is always been great ! But I don't know how he had mistaken at 4:57 his new String("navin"); will create a new object on heap outside of the String Pool where 'navin' exists and this 'navin' is not that 'navin' from String Pool !
@toramihai
@toramihai 6 жыл бұрын
He's a person, he can do a mistake, wright? ;) He learned us a lots of things for free, we should thank him...
@shahriarmim4696
@shahriarmim4696 6 жыл бұрын
Ofcourse. that's beyond dispute ! @toramihai
@toramihai
@toramihai 6 жыл бұрын
I've searched a little and I think the stuff goes like that: when you have String a = new String ("abc") it will be two objects created, one that is abc in string pool and one from new keyword in heap, the object from heap will point to the pool object for his value...i hope i understood well
@coden3902
@coden3902 6 жыл бұрын
@@toramihai Yes right ....i was also wondering the same ! and if we want to put a into pool we have to use a.intern() method.
@sidharthvijayakumar3521
@sidharthvijayakumar3521 4 жыл бұрын
True new keyword makes a new object
@SachinOnTheGo
@SachinOnTheGo 5 жыл бұрын
Creating New Strings Earlier we promised to talk more about the subtle differences between the various methods of creating a String. Let's look at a couple of examples of how a String might be created, and let's further assume that no other String objects exist in the pool: String s = "abc"; // creates one String object and one // reference variable In this simple case, "abc" will go in the pool and s will refer to it. String s = new String("abc"); // creates two objects, // and one reference variable In this case, because we used the new keyword, Java will create a new String object in normal (nonpool) memory, and s will refer to it. In addition, the literal "abc" will be placed in the pool.
@bissallahekele5320
@bissallahekele5320 3 жыл бұрын
Will a new 'abc' literal be placed in pool after calling new, or the previous 'abc' will be referenced?
@bissallahekele5320
@bissallahekele5320 3 жыл бұрын
Okay, 'abc' will be placed in pool if it doesn't exist. Else the previous 'abc' is referenced
@harisudan6637
@harisudan6637 7 жыл бұрын
Hi navin, whenever u teach any concept could you give a program code example it will useful to understand the concept easily
@_surajSisale
@_surajSisale 2 жыл бұрын
UHR THE BEST TEACHER EVER
@muhammadomersaleem4919
@muhammadomersaleem4919 7 жыл бұрын
Hi, what if we do not create str1 object and change str to "Reddy". Will it also create new string in string pool or will it change/replace Navin with Reddy? If first case is true then what will happen with Navin in string pool?
@ankitanand2702
@ankitanand2702 8 жыл бұрын
Due to string immutability you can safely return them from functions. If strings were mutable anyone could have changed your return value. Thats why serialization is done also.
@cam7minus1
@cam7minus1 3 жыл бұрын
Thank you that makes a lot of sense
@swathikumar3074
@swathikumar3074 6 жыл бұрын
Sorry for saying.this is wrong when ever we create string using new keyword it will never pointing to string pool it will create new string in heap .if u want to put that value into sting pool there is a method called intern()
@akshaysaini9740
@akshaysaini9740 6 жыл бұрын
.if u want to put that value into heap than this method is called intern() String myString = new String( "old String" ); String myCache = myString; System.out.println( "equal: " + myString.equals( myCache ) ); System.out.println( "same: " + ( myString == myCache ) ); output: equal: true same: true String myString = new String( "old String" ); String myCache = myString.intern(); System.out.println( "equal: " + myString.equals( myCache ) ); System.out.println( "same: " + ( myString == myCache ) ); output: equal: true same: false
@mrx-qi8th
@mrx-qi8th 4 жыл бұрын
string s1=new string("navin"); will this create a s1 variable inside main frame of stack? correct me if i'm wrong. what i have in mind is that { we have s1 inside stack filled with the memory location of heap memory now "new string" we have 4Bytes in heap memory filled with the address of "navin" in pool string am i right?
@NavinKumar-ig4xb
@NavinKumar-ig4xb 4 жыл бұрын
I also faced name issue. People used to send or write to wrong Naveen. Nice video
@pareshhere
@pareshhere 4 жыл бұрын
Looking you drawing on board and now all animations... That's mutable... 😁
@sarithaj4323
@sarithaj4323 4 жыл бұрын
Please create a video on stack and heap memory
@mehrosenasir3966
@mehrosenasir3966 5 жыл бұрын
If String str="Navin" and let's say it has an address in heap as 100. Now as you said, If I do this like str="Reddy" this will assign a new address to str lets say 101. Now the question is both values are present in the heap memory but how can I now point the old str which has value "Navin"?
@mechvishwanath
@mechvishwanath 5 жыл бұрын
I think it's not possible to point old str as reference updated with new one ...
@ramg9135
@ramg9135 3 жыл бұрын
same doubt to me
@Victor-tl4dk
@Victor-tl4dk 3 жыл бұрын
Thanks for the video! Consider getting a better mic!!
@divyaturlapaty7271
@divyaturlapaty7271 6 жыл бұрын
please correct that part sir about new String("Navin") creating a new object..:)
@saravanabalaji1913
@saravanabalaji1913 4 жыл бұрын
Well explained sir Thank you...!👌✨
@lakshayarora7632
@lakshayarora7632 7 жыл бұрын
Sir I have been listening to your videos "Java Tutorial For Beginners".Will these videos cover the entire core java syllabus?
@Malone-vq2ft
@Malone-vq2ft 7 жыл бұрын
5:19 What kind of object is that, that have a memory address. I thought only references could hold memory addresses.
@bittooaggarwal5776
@bittooaggarwal5776 4 жыл бұрын
String s1 = "Shiva"; String s2 = "Shiva"; s1 = "Neelkantha"; String s3 = new String("Shiva"); String s4 = "Shiva"; System.out.println(System.identityHashCode(s1) + " : "+System.identityHashCode(s2) + " : " + System.identityHashCode(s3) + " : " +System.identityHashCode(s4)); System.out.println(s3.equals(s2)); System.out.println(s3.equals(s4)); System.out.println(s3 == s4); System.out.println(s2 == s4); maybe this code can you help you get a bit of clarification, here both s3 has different memory location than s2 and s4 but its value is same.
@komalpare2019
@komalpare2019 4 жыл бұрын
I have some doubts in string immutablity
@ranjitharengaraj1992
@ranjitharengaraj1992 4 жыл бұрын
I really really need this answer where did u learn java or string concept....pls reply..
@RestIess.Gambler
@RestIess.Gambler 2 ай бұрын
I'm soo confused. If I can't change the value then, explain: string str = "navin"; string str = "freddy"; print(str); Why does it print "freddy" and not "navin". The value of the first string has been changed from navin to freddy, right? I need someone to clear me up.
@Malone-vq2ft
@Malone-vq2ft 7 жыл бұрын
class StringPoolTest1{ public static void main(String[] args){ String s0 = "hello ".concat("world"); } } "hello " and "world" are located in the String Pool is "hello world" located in it as well? If not, where is it? Only in the Heap? What happens between the Heap and the String Pool when s0.intern();
@gaganyadav2448
@gaganyadav2448 4 жыл бұрын
"Hello World" will be located in heap as you are using concat which is a runtime operation + both "hello" and "world" will be stored in string pool as well because both of them are constant values
@csegarrage
@csegarrage Жыл бұрын
Hi Navin, I've one doubt. Is it possible to declare and define methods in java separately like C?
@aviroxi
@aviroxi 3 жыл бұрын
something special with 101 i see it many times....
@harrshiil
@harrshiil 3 жыл бұрын
Are all primitive data types immutable or only String is immutable?
@jagannathrao-cq9wg
@jagannathrao-cq9wg 3 ай бұрын
Hi sir, Nice explanation, but you have not clearly explained about, String ss = "navin"; ss="java"; then it will print "java" as string is immutable that all we know. but if we want ss="navin" then how to print because we have modified the ss="java"
@sumitbabel5415
@sumitbabel5415 4 жыл бұрын
Amazingly explained
@webapplicationguide3798
@webapplicationguide3798 5 жыл бұрын
Thank you Navin !!
@techarticlesorg
@techarticlesorg Жыл бұрын
navin sir are u able to speak telugu language??
@urmilapatil1643
@urmilapatil1643 4 жыл бұрын
If str1="hello" ;str2="hi";str1=str1+str2;sop(str1);what's the output?
@satishkavre7197
@satishkavre7197 4 жыл бұрын
Wrong questions Urmila patil mam pls check ur questions first
@AbhishekSingh-rc1st
@AbhishekSingh-rc1st 4 жыл бұрын
@Satish Kavre why you said question is wrong ,i think output will be hellohi
@satishkavre7197
@satishkavre7197 4 жыл бұрын
@abhishek singh I think u don't know if value of variables is same but there reference must be different
@AbhishekSingh-rc1st
@AbhishekSingh-rc1st 4 жыл бұрын
@Satish Kavre bt here in question neither value nor reference are same.str1 and str2 both different references and point to different addresses ,we concatenate both and put the result in str1. Try to dry run the code!
@nameisadi1287
@nameisadi1287 3 жыл бұрын
@@AbhishekSingh-rc1st I think string is immutable Nd how can the value of str1 be changed? Am I wrong ?
@shilpamore1345
@shilpamore1345 5 жыл бұрын
Hello Navin, i come across the sentence that strings being immutable avoids race condition. I am not able to visualize this. Can you please explain it?
@RahulKumar-w9j9q
@RahulKumar-w9j9q Жыл бұрын
what will happen in the below case String s1= "Navi"; s1+="n"; String s2 = "Navin"; Will s1 and s2 be sharing same reference or different. If it is different, does it mean + operator creating new Object in the heap.
@Abhishek-kt7tk
@Abhishek-kt7tk Жыл бұрын
I also have the same doubt
@pratikghotekar8664
@pratikghotekar8664 7 жыл бұрын
Hello sir, Can you please tell me wat does synchronization means in terms of stringbuilder and stringbuffer classes? An exmple wud be appricaited.
@balakumaran6056
@balakumaran6056 2 жыл бұрын
Easy to understand
@ramg9135
@ramg9135 3 жыл бұрын
okay. reference changed in stack(str 101 to 103) then now str is 103 . 103 is reddy. then it is changed so , how it is immutable in your explanation
@raaviyashwanth4274
@raaviyashwanth4274 3 жыл бұрын
this is my interview question we cant manipulate string but we can assign a new value
@mdnoorzafirmondal7398
@mdnoorzafirmondal7398 3 жыл бұрын
Can we take a string array without initialization nd then give inputs nd then calculate it's length?
@vasukannan.s7423
@vasukannan.s7423 4 жыл бұрын
In above video, if i did not create another variable "str1", then i changed the"str = reddy" mean,, how can i access the "navin"
@saurabhsharma1410
@saurabhsharma1410 3 жыл бұрын
Does it mean that if we create String object using 'new' keyword then it doesn't make any entry in Stack memory? Please clarify this..
@sripathivenkatreddy6251
@sripathivenkatreddy6251 5 жыл бұрын
Hello Sir, if i create String s=new String("SVREDDY"); how many objects will create in memory.
@unknowncreature5832
@unknowncreature5832 5 жыл бұрын
2
@shankars4281
@shankars4281 4 жыл бұрын
2. One in heap and one in string pool. If this string already exists in string pool, it will not create new one.
@2rajatkiit
@2rajatkiit 8 жыл бұрын
String constant pool is created in Method Area not heap area. We access it by using intern () method which create object in heap area of that string.
@jvsnyc
@jvsnyc 4 жыл бұрын
People were saying that was only true until JDK 7 in other videos. I haven't checked yet...
@harshkumrawat9917
@harshkumrawat9917 7 жыл бұрын
Sir can u pls make a video on immutable and mutable objects I got this question in interview
@avigeek
@avigeek 6 жыл бұрын
best ever explanation
@Muthuvlog104
@Muthuvlog104 4 жыл бұрын
Hi Navin, Can you explain the difference between primitive datatype int and String . as i see both works the same way except the fact they hold different content
@gavravdhongadi9824
@gavravdhongadi9824 4 жыл бұрын
Both are not the same, int is a data type and String is class
@Muthuvlog104
@Muthuvlog104 4 жыл бұрын
@@gavravdhongadi9824 okay.. but the way they both store seems same.. except the fact one stores in stack and the other in heap. So got the qn
@titasdey
@titasdey 4 жыл бұрын
@@gavravdhongadi9824 int is a struct.
@theblindprogrammer
@theblindprogrammer 4 жыл бұрын
int does not have methods, you can't find a size of an int primitive for example. String, however, has methods.
@Turnpost2552
@Turnpost2552 5 жыл бұрын
Nicely done
@thebunerikhan
@thebunerikhan 7 жыл бұрын
This man is awesome.
@vivekpandey6979
@vivekpandey6979 5 жыл бұрын
what happen to string "navin" is it accssesible or it goes in garbage???
@simulink9564
@simulink9564 3 жыл бұрын
Hmm good 🙂.. But in different videos, blogs different informations 😶 which confusing me 😐. This video make sense for me a bit more. Goog.
@koushikn3016
@koushikn3016 3 жыл бұрын
I was looking for a job since last month or I had been looking for a job from last two months. Hope that advertising girl in the end doesn't make any grammar mistakes next time.
@jackyoga
@jackyoga 6 жыл бұрын
Hi Navin, first of all thanks for this video but need more explanation on this topic. As string literal and new String both are creating immutable then what's difference , why we really need to use new String if String literal is creating immutable object?
@harrypotter-el4lx
@harrypotter-el4lx 3 жыл бұрын
I think new string has some additional functionalities which string literal does not have like integer wrapper class has parseInt ect .
@akhilsai9533
@akhilsai9533 5 жыл бұрын
there is no app found??? in play store
@rakeshanand2008
@rakeshanand2008 6 жыл бұрын
What is synchronized & non-synchronized in java? For e.g Array List is not synchronized.
@prathameshbagekari7966
@prathameshbagekari7966 5 жыл бұрын
Synchronized basically means thread-safe. A synchronized method or datatype is the one which will function as expected in cases of execution of multiple threads at a time. Now you'll ask that, then why there are non-synchronized methods. So, remember that non synchronized ones are faster than the synchronized ones. So when you know that your program does not involve multithreading, you can be sure to use a non-synchronized method or datatype..
@srinathk1322
@srinathk1322 5 жыл бұрын
when declaring string like this String str="navin"; whether str is an variable or an object
@avi_cool_dude
@avi_cool_dude 5 жыл бұрын
it is a reference variable not object ...object is navin
@manikandaprabhu959
@manikandaprabhu959 5 жыл бұрын
variable
@venkateshbelgaonkar7785
@venkateshbelgaonkar7785 5 жыл бұрын
It's call object reference variable which can be used to refer to a particular object
@thunderbolzz3142
@thunderbolzz3142 4 жыл бұрын
Its a variable...
@kesitkusumo628
@kesitkusumo628 7 жыл бұрын
Thanks Navin !
@TheGuroguro12
@TheGuroguro12 3 жыл бұрын
Thank you!
@DSA_Coding
@DSA_Coding 4 жыл бұрын
great sir
@joshi98kishan
@joshi98kishan 6 жыл бұрын
How string immutability boost the performance of a system?
@navyasri5602
@navyasri5602 6 жыл бұрын
How string is secure???
@rakeshanand2008
@rakeshanand2008 6 жыл бұрын
What is the difference between main(String args[ ]) , main(String[ ] args) & main(String [args]) ?
@theblindprogrammer
@theblindprogrammer 4 жыл бұрын
There is no difference between this two: public static void main(String args[]){....} public static void main(String[] args ){....} you can even change the name of "args", you can write like this if you want to. public static void main(String mike[]){...} This is not correct, however: public static void main(String [args]){}
@maheshpanchakarla5094
@maheshpanchakarla5094 5 жыл бұрын
Why " String " is not colored in java in eclipse editor....?
@Basitify
@Basitify 5 жыл бұрын
I might be wrong but I don't thing "String" is colored in any IDE because it is a non-primitive data type and a Class and most IDEs either have primitive data types or keywords as colored
@UhOohSpaghettiOs
@UhOohSpaghettiOs 7 жыл бұрын
Thanks Naveen
@shobhareddy1290
@shobhareddy1290 3 жыл бұрын
I have one doubt please fix it sir String s1="super" String s2="cat" S1=s1+s2 Is this immutable object
@shobhareddy1290
@shobhareddy1290 3 жыл бұрын
Pls reply
@ArunraajSingh
@ArunraajSingh 7 жыл бұрын
best explanation dude
@Justicewarrior795
@Justicewarrior795 4 жыл бұрын
Thanks Naveen))
@ajaykumarpradhan2239
@ajaykumarpradhan2239 5 жыл бұрын
Wrong,Sir the new keyword will create object in heap area and String literal not equal or point to the String object
@gurudakshin6420
@gurudakshin6420 5 жыл бұрын
Lets say If I hv millions of text values are there. Don't you think it will create an hotspot in memory??
@satishchadokar
@satishchadokar 5 жыл бұрын
This is not y ans can u give ans of why string is immutable not his benefits
@vikrantthakkar4493
@vikrantthakkar4493 6 жыл бұрын
Please explain that how the system knows or find to duplicate values assign to string in heap memmory
@devangikacha1477
@devangikacha1477 5 жыл бұрын
I searched this... Compiler will create list of all string literals at compile time with their respective address
@arunkumar-tz1di
@arunkumar-tz1di 8 жыл бұрын
string n=new string("arun"); string n1=new string("arun"); how many objects is created
@nitulatapadhi112
@nitulatapadhi112 6 жыл бұрын
3
@nomadicbanda
@nomadicbanda 5 жыл бұрын
String s1 = "Hello"; String s2 = "Hello"; String s3 = new String ("Hello Java"); String s4 = new String("Hello Java"); How many objects will be created in this lines..?
@abhimanyurathore7185
@abhimanyurathore7185 5 жыл бұрын
Hi, Mahesh Meena I am also a beginner. But 3 will be my guess. // sop(a==b); //true Sop(a.equals(b));//true Sop(a.equals(c));//true Sop(a==c);//false Sop(c==d);//false Sop(c.equals(d));//true
@hectorflores1176
@hectorflores1176 5 жыл бұрын
Try it by your own is simple. Print in console the hashCode of each string. System.out.println(s1.hashCode()); System.out.println(s2.hashCode()); System.out.println(s3.hashCode()); System.out.println(s4.hashCode()); The output is: 69609650 69609650 387417328 387417328
@armpap1
@armpap1 5 жыл бұрын
The answer is 6, and hash codes will be equal if the values are equal, but it doesnt mean that those stored in the same object, two objects in different places in the heap can have the same value.
@sudhanshuroy9673
@sudhanshuroy9673 2 жыл бұрын
You don't explain in detail when we create two string with new keyword then why there address are same and equels to return false
@munaswamy6595
@munaswamy6595 6 жыл бұрын
How new string ("Naveen'); use string pool value explain
@ramanajeyachandran9622
@ramanajeyachandran9622 7 жыл бұрын
If I ignore the str1 obj then how will the memory allocation happen
@Rohan122
@Rohan122 4 жыл бұрын
This is incomplete.Why didnt you tell how to make a class immutable?
@Lucky-uz3je
@Lucky-uz3je 6 жыл бұрын
Correct explanation, copied from below comment. Please refer this for String object creation with new keyword. whenever we create string using new keyword it will never pointing to string pool it will create new string in heap .if u want to put that value into sting pool there is a method called intern(). Please pin this answer to understand people correctly. String myString = new String( "old String" ); String myCache = myString; System.out.println( "equal: " + myString.equals( myCache ) ); System.out.println( "same: " + ( myString == myCache ) ); output: equal: true same: true String myString = new String( "old String" ); String myCache = myString.intern(); System.out.println( "equal: " + myString.equals( myCache ) ); System.out.println( "same: " + ( myString == myCache ) ); output: equal: true same: false
@vivekpandey6979
@vivekpandey6979 5 жыл бұрын
salute you sir...love u
@sunethhewage3119
@sunethhewage3119 3 жыл бұрын
thank you
@saadmanahmed860
@saadmanahmed860 6 жыл бұрын
naveen...sir u r a dynamic beak...awesome.
@roadsideHeropanti9589
@roadsideHeropanti9589 7 жыл бұрын
sir would i like to improve your app...so plz give me Chance... I have 2 plus experience in android....just bcz it's Helpfull for students
@PramodSubramanyam10
@PramodSubramanyam10 7 жыл бұрын
Sir u forgot to teach about constant pool and non constant pool...
@Crox--Youtube--Channel
@Crox--Youtube--Channel 6 жыл бұрын
kachak packk odkd
@harithaarumugam1357
@harithaarumugam1357 4 жыл бұрын
public class Example { public static void main (String[] args) { stringMatch("Haritha","Haritha"); } public static int stringMatch(String a, String b) { int len = Math.min(a.length(), b.length()); for (int i=0;i
@sunnylohana645
@sunnylohana645 8 жыл бұрын
String str="Navin"; str="Reddy"; In this case String object (Navin) will be replaced By Reddy Or it will exist?
@subrahmanyampenkey1126
@subrahmanyampenkey1126 8 жыл бұрын
Both the objects "Navin" and "Reddy" exits in the string pool.when ever you assign str = "Reddy" its just map the str reference to "Reddy" object it won't delete "Navin" object from string pool.lets assume if you create a one more new reference variable as str1="Navin". it will not create "Navin" again its just find the "Navin" object in the string pool if its there its simply maps that reference to str1.
@ArunraajSingh
@ArunraajSingh 7 жыл бұрын
Does string object in Heap hold the reference of the object in String pool as navin said?
@prasadligade353
@prasadligade353 7 жыл бұрын
it would be better if you structure - I was not sure if you were explaining immutable or mutable.
@arveersingh9728
@arveersingh9728 8 жыл бұрын
what is the difference between String str="abc"; and String str=new String("abc"),is it only that the later uses heap memory and the former does not?
@ArjunSingh-qt5jn
@ArjunSingh-qt5jn 8 жыл бұрын
both are same bro , infact both give you a reference variable of type str pointing to the string object that is "abc" both do same work with new or without it.
@subrahmanyampenkey1126
@subrahmanyampenkey1126 8 жыл бұрын
Main difference is when you create String str="abc"; it will create "abc" object in the String pool. but when you create String str = new String("abc"); it will create two objects one in String pool as "abc" and one in heap memory as (new String("abc"); this new String("abc") again its refers to the object "abc" in the string pool. that's why output will be the same for both the cases.
@1234jackist
@1234jackist 8 жыл бұрын
First one will be stored in code memory and 2nd one in heap
@Malone-vq2ft
@Malone-vq2ft 7 жыл бұрын
Based on what is explained, is there a difference? String str="abc"; creates an object in String Pool and returns a memory address to a reference. String str=new String("abc") creates an object in the Heap, but what kind of object it is, if it is holding only a memory address from the Heap ? Can you kindly explain? Thank you
@jitendradas4597
@jitendradas4597 3 жыл бұрын
This video tells how string is made immutable not why string is immutable
@shubhambhake2207
@shubhambhake2207 5 жыл бұрын
Bt my que why this is immutable?
@VivekRavinair
@VivekRavinair 4 жыл бұрын
I guess this is explained @ 3.15
@manishjha2579
@manishjha2579 5 жыл бұрын
Sir how can I class learn tupple and array?
@theblindprogrammer
@theblindprogrammer 4 жыл бұрын
// an array 1) String[] names = {"Bob", "John", "Mike"}; 2) String[] names = new String[3]; names[0] = new String("Bob"); names[1] = new String("John"); names[2] = new String("Alex");
@ashishagnihotri5566
@ashishagnihotri5566 2 жыл бұрын
still watchin in 2022
StringBuffer and StringBuilder in Java
6:35
Telusko
Рет қаралды 222 М.
Why string is immutable in java || The 4 reasons you must know || part 1
20:53
Непосредственно Каха: сумка
0:53
К-Media
Рет қаралды 12 МЛН
УЛИЧНЫЕ МУЗЫКАНТЫ В СОЧИ 🤘🏻
0:33
РОК ЗАВОД
Рет қаралды 7 МЛН
14.5 LinkedList vs ArrayList in Java
9:16
Telusko
Рет қаралды 416 М.
#35 Mutable vs Immutable String in Java
6:23
Telusko
Рет қаралды 165 М.
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 997 М.
Logging in Java using Log4J
1:06:44
Telusko
Рет қаралды 10 М.
Java Strings are Immutable - Here's What That Actually Means
7:06
Coding with John
Рет қаралды 628 М.
String Immutable In Java Interview Question
9:47
Naveen AutomationLabs
Рет қаралды 22 М.
Collection and Generics in Java
14:32
Telusko
Рет қаралды 784 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23