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
@seanjesuharun17843 жыл бұрын
same doubt will the object be point to the memory address of string pool which having the string literal as "Navin"???
@DeepakKumar-dw1re3 жыл бұрын
You are absolutely Right...
@AmanTheMystery3 жыл бұрын
@@seanjesuharun1784 if any string is created using new keyword then for which a new string is created in heap memory , not in string pool..
@afsanacabu22902 жыл бұрын
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 Жыл бұрын
My question exactly.
@shyamelakapalli10516 жыл бұрын
String s=new String ("syam"); if you use s.intern(); then only it points to string pool until then it points to heap.
@yuvarajs37478 жыл бұрын
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.
@namratasanger57456 жыл бұрын
What they have asked you in interview regarding string can you tell me?
@ajithranrox55246 жыл бұрын
maybe its the Grammer!
@withlovesandeep44246 жыл бұрын
@@namratasanger5745 same experience for me also.. Why String is immutable ? Difference between String str=String("abc") and String str1="abc"
@namratasanger57456 жыл бұрын
@@withlovesandeep4424 they both differ because of how they point and store the data isn't that's the right answer?
@sarin3746 жыл бұрын
ajithran rox 😂😂
@vibinvibs78414 жыл бұрын
thank you sir fr teaching us . u r one of the great teacher ever@ navin reddy
@harithkumar45017 жыл бұрын
I watch complete adds on your videos , so that you can earn some money .
@mypersonal19974 жыл бұрын
😂
@GodiPM2 жыл бұрын
Hell is wa8ting
@RohitShinde-xh7vo2 жыл бұрын
🤣🤣🤣🤣🤣
@arfatbagwan482 жыл бұрын
🤣
@gyanajyotisahoo43662 жыл бұрын
Good job man 😂😂😂
@preetird83853 жыл бұрын
@0:36 When Navin says "mutability is a crime" Me: "It's true..Corona should have been a String(immutable)" 😂🥲 April: 2021
@waxylayer83533 жыл бұрын
Funny
@anshsarin193 жыл бұрын
its "Navin"
@preetird83853 жыл бұрын
@@anshsarin19 lol ok bigger problems here.. I'll correct that using String buffer 👍
@Anushaaa_3 жыл бұрын
😂
@SurajPandey-vi9gr6 ай бұрын
Amazing Telusko you are such a good teacher
@AvidWanderlust3 жыл бұрын
"Welcome back aliens" is immutable
@terrificsuper5 жыл бұрын
Good work my dude
@EthicAITales6 жыл бұрын
I cant find the app in play store. Wonderful videos. Crisp and clear explanation
@aymanmomin4324 жыл бұрын
Sir can you please make a video on heap and stack memory along with a separate video on a roadmap for desktop application developers
@shahriarmim46966 жыл бұрын
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 !
@toramihai6 жыл бұрын
He's a person, he can do a mistake, wright? ;) He learned us a lots of things for free, we should thank him...
@shahriarmim46966 жыл бұрын
Ofcourse. that's beyond dispute ! @toramihai
@toramihai6 жыл бұрын
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
@coden39026 жыл бұрын
@@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.
@sidharthvijayakumar35214 жыл бұрын
True new keyword makes a new object
@SachinOnTheGo5 жыл бұрын
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.
@bissallahekele53203 жыл бұрын
Will a new 'abc' literal be placed in pool after calling new, or the previous 'abc' will be referenced?
@bissallahekele53203 жыл бұрын
Okay, 'abc' will be placed in pool if it doesn't exist. Else the previous 'abc' is referenced
@harisudan66377 жыл бұрын
Hi navin, whenever u teach any concept could you give a program code example it will useful to understand the concept easily
@_surajSisale2 жыл бұрын
UHR THE BEST TEACHER EVER
@muhammadomersaleem49197 жыл бұрын
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?
@ankitanand27028 жыл бұрын
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.
@cam7minus13 жыл бұрын
Thank you that makes a lot of sense
@swathikumar30746 жыл бұрын
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()
@akshaysaini97406 жыл бұрын
.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-qi8th4 жыл бұрын
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-ig4xb4 жыл бұрын
I also faced name issue. People used to send or write to wrong Naveen. Nice video
@pareshhere4 жыл бұрын
Looking you drawing on board and now all animations... That's mutable... 😁
@sarithaj43234 жыл бұрын
Please create a video on stack and heap memory
@mehrosenasir39665 жыл бұрын
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"?
@mechvishwanath5 жыл бұрын
I think it's not possible to point old str as reference updated with new one ...
@ramg91353 жыл бұрын
same doubt to me
@Victor-tl4dk3 жыл бұрын
Thanks for the video! Consider getting a better mic!!
@divyaturlapaty72716 жыл бұрын
please correct that part sir about new String("Navin") creating a new object..:)
@saravanabalaji19134 жыл бұрын
Well explained sir Thank you...!👌✨
@lakshayarora76327 жыл бұрын
Sir I have been listening to your videos "Java Tutorial For Beginners".Will these videos cover the entire core java syllabus?
@Malone-vq2ft7 жыл бұрын
5:19 What kind of object is that, that have a memory address. I thought only references could hold memory addresses.
@bittooaggarwal57764 жыл бұрын
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.
@komalpare20194 жыл бұрын
I have some doubts in string immutablity
@ranjitharengaraj19924 жыл бұрын
I really really need this answer where did u learn java or string concept....pls reply..
@RestIess.Gambler2 ай бұрын
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-vq2ft7 жыл бұрын
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();
@gaganyadav24484 жыл бұрын
"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 Жыл бұрын
Hi Navin, I've one doubt. Is it possible to declare and define methods in java separately like C?
@aviroxi3 жыл бұрын
something special with 101 i see it many times....
@harrshiil3 жыл бұрын
Are all primitive data types immutable or only String is immutable?
@jagannathrao-cq9wg3 ай бұрын
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"
@sumitbabel54154 жыл бұрын
Amazingly explained
@webapplicationguide37985 жыл бұрын
Thank you Navin !!
@techarticlesorg Жыл бұрын
navin sir are u able to speak telugu language??
@urmilapatil16434 жыл бұрын
If str1="hello" ;str2="hi";str1=str1+str2;sop(str1);what's the output?
@satishkavre71974 жыл бұрын
Wrong questions Urmila patil mam pls check ur questions first
@AbhishekSingh-rc1st4 жыл бұрын
@Satish Kavre why you said question is wrong ,i think output will be hellohi
@satishkavre71974 жыл бұрын
@abhishek singh I think u don't know if value of variables is same but there reference must be different
@AbhishekSingh-rc1st4 жыл бұрын
@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!
@nameisadi12873 жыл бұрын
@@AbhishekSingh-rc1st I think string is immutable Nd how can the value of str1 be changed? Am I wrong ?
@shilpamore13455 жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
I also have the same doubt
@pratikghotekar86647 жыл бұрын
Hello sir, Can you please tell me wat does synchronization means in terms of stringbuilder and stringbuffer classes? An exmple wud be appricaited.
@balakumaran60562 жыл бұрын
Easy to understand
@ramg91353 жыл бұрын
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
@raaviyashwanth42743 жыл бұрын
this is my interview question we cant manipulate string but we can assign a new value
@mdnoorzafirmondal73983 жыл бұрын
Can we take a string array without initialization nd then give inputs nd then calculate it's length?
@vasukannan.s74234 жыл бұрын
In above video, if i did not create another variable "str1", then i changed the"str = reddy" mean,, how can i access the "navin"
@saurabhsharma14103 жыл бұрын
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..
@sripathivenkatreddy62515 жыл бұрын
Hello Sir, if i create String s=new String("SVREDDY"); how many objects will create in memory.
@unknowncreature58325 жыл бұрын
2
@shankars42814 жыл бұрын
2. One in heap and one in string pool. If this string already exists in string pool, it will not create new one.
@2rajatkiit8 жыл бұрын
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.
@jvsnyc4 жыл бұрын
People were saying that was only true until JDK 7 in other videos. I haven't checked yet...
@harshkumrawat99177 жыл бұрын
Sir can u pls make a video on immutable and mutable objects I got this question in interview
@avigeek6 жыл бұрын
best ever explanation
@Muthuvlog1044 жыл бұрын
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
@gavravdhongadi98244 жыл бұрын
Both are not the same, int is a data type and String is class
@Muthuvlog1044 жыл бұрын
@@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
@titasdey4 жыл бұрын
@@gavravdhongadi9824 int is a struct.
@theblindprogrammer4 жыл бұрын
int does not have methods, you can't find a size of an int primitive for example. String, however, has methods.
@Turnpost25525 жыл бұрын
Nicely done
@thebunerikhan7 жыл бұрын
This man is awesome.
@vivekpandey69795 жыл бұрын
what happen to string "navin" is it accssesible or it goes in garbage???
@simulink95643 жыл бұрын
Hmm good 🙂.. But in different videos, blogs different informations 😶 which confusing me 😐. This video make sense for me a bit more. Goog.
@koushikn30163 жыл бұрын
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.
@jackyoga6 жыл бұрын
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-el4lx3 жыл бұрын
I think new string has some additional functionalities which string literal does not have like integer wrapper class has parseInt ect .
@akhilsai95335 жыл бұрын
there is no app found??? in play store
@rakeshanand20086 жыл бұрын
What is synchronized & non-synchronized in java? For e.g Array List is not synchronized.
@prathameshbagekari79665 жыл бұрын
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..
@srinathk13225 жыл бұрын
when declaring string like this String str="navin"; whether str is an variable or an object
@avi_cool_dude5 жыл бұрын
it is a reference variable not object ...object is navin
@manikandaprabhu9595 жыл бұрын
variable
@venkateshbelgaonkar77855 жыл бұрын
It's call object reference variable which can be used to refer to a particular object
@thunderbolzz31424 жыл бұрын
Its a variable...
@kesitkusumo6287 жыл бұрын
Thanks Navin !
@TheGuroguro123 жыл бұрын
Thank you!
@DSA_Coding4 жыл бұрын
great sir
@joshi98kishan6 жыл бұрын
How string immutability boost the performance of a system?
@navyasri56026 жыл бұрын
How string is secure???
@rakeshanand20086 жыл бұрын
What is the difference between main(String args[ ]) , main(String[ ] args) & main(String [args]) ?
@theblindprogrammer4 жыл бұрын
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]){}
@maheshpanchakarla50945 жыл бұрын
Why " String " is not colored in java in eclipse editor....?
@Basitify5 жыл бұрын
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
@UhOohSpaghettiOs7 жыл бұрын
Thanks Naveen
@shobhareddy12903 жыл бұрын
I have one doubt please fix it sir String s1="super" String s2="cat" S1=s1+s2 Is this immutable object
@shobhareddy12903 жыл бұрын
Pls reply
@ArunraajSingh7 жыл бұрын
best explanation dude
@Justicewarrior7954 жыл бұрын
Thanks Naveen))
@ajaykumarpradhan22395 жыл бұрын
Wrong,Sir the new keyword will create object in heap area and String literal not equal or point to the String object
@gurudakshin64205 жыл бұрын
Lets say If I hv millions of text values are there. Don't you think it will create an hotspot in memory??
@satishchadokar5 жыл бұрын
This is not y ans can u give ans of why string is immutable not his benefits
@vikrantthakkar44936 жыл бұрын
Please explain that how the system knows or find to duplicate values assign to string in heap memmory
@devangikacha14775 жыл бұрын
I searched this... Compiler will create list of all string literals at compile time with their respective address
@arunkumar-tz1di8 жыл бұрын
string n=new string("arun"); string n1=new string("arun"); how many objects is created
@nitulatapadhi1126 жыл бұрын
3
@nomadicbanda5 жыл бұрын
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..?
@abhimanyurathore71855 жыл бұрын
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
@hectorflores11765 жыл бұрын
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
@armpap15 жыл бұрын
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.
@sudhanshuroy96732 жыл бұрын
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
@munaswamy65956 жыл бұрын
How new string ("Naveen'); use string pool value explain
@ramanajeyachandran96227 жыл бұрын
If I ignore the str1 obj then how will the memory allocation happen
@Rohan1224 жыл бұрын
This is incomplete.Why didnt you tell how to make a class immutable?
@Lucky-uz3je6 жыл бұрын
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
@vivekpandey69795 жыл бұрын
salute you sir...love u
@sunethhewage31193 жыл бұрын
thank you
@saadmanahmed8606 жыл бұрын
naveen...sir u r a dynamic beak...awesome.
@roadsideHeropanti95897 жыл бұрын
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
@PramodSubramanyam107 жыл бұрын
Sir u forgot to teach about constant pool and non constant pool...
@Crox--Youtube--Channel6 жыл бұрын
kachak packk odkd
@harithaarumugam13574 жыл бұрын
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
@sunnylohana6458 жыл бұрын
String str="Navin"; str="Reddy"; In this case String object (Navin) will be replaced By Reddy Or it will exist?
@subrahmanyampenkey11268 жыл бұрын
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.
@ArunraajSingh7 жыл бұрын
Does string object in Heap hold the reference of the object in String pool as navin said?
@prasadligade3537 жыл бұрын
it would be better if you structure - I was not sure if you were explaining immutable or mutable.
@arveersingh97288 жыл бұрын
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-qt5jn8 жыл бұрын
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.
@subrahmanyampenkey11268 жыл бұрын
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.
@1234jackist8 жыл бұрын
First one will be stored in code memory and 2nd one in heap
@Malone-vq2ft7 жыл бұрын
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
@jitendradas45973 жыл бұрын
This video tells how string is made immutable not why string is immutable
@shubhambhake22075 жыл бұрын
Bt my que why this is immutable?
@VivekRavinair4 жыл бұрын
I guess this is explained @ 3.15
@manishjha25795 жыл бұрын
Sir how can I class learn tupple and array?
@theblindprogrammer4 жыл бұрын
// 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");