Hello Naveen! In min 5:00. There is something that makes me confused. After creating the 3 objects using new key word you create 2 literals that already exist in String pool then will not be necessary to create 2nd "Hello World" in the pool so at the end it will be 3 objects no 4 in the entire program as you mentioned. In 2 different programs the total of objects are 4 but not in only. Actually, in your next example you dont create a extra "Hello World" because already exist in the pool. Please, correct me if I am wrong.
Sir Have a question. In java program If ( n1.hascode()==n2.hascode()) return true n1.equals(n2) true Then why n1==n2 return false. ( Its satisfy hascode and equals contract)
Hi Naveen, I really love the way you explain the stuff and concepts. Wanted to clarify one thing with you.. When we create an object using new keyword, it will create an object in heap but does it create the object in String pool as well? Since there is no reference pointing to object created in StringPool then why will it create the object in StringPool? Will it not lead to poor memory management? As per my understanding, intern method takes care of doing that if it is not already available in scp.
it will create 2 objects one in heap area and another one is string constant pool area i.e SCP area(if the object is not there with the same content if object is already with same content i won't create new object) and string ref n1 is pointing to heap area object
String st = new String("Hello"); String s = "Hello";
System.out.println(st == s); //false Can you please clarify this, if the first statement creates an object on heap and also in string pools, then when why st == s is false, instead of true? also can you please explain the use of String.intern() method.
when you create Sting by using New keyword it create a new Sting in Non-Constant pool memory(Heap) ,where as by using Literal it create a sting in constant pool memory(Heap). so that references of both stings are different that the reason you get "false".instead of using == operator use equals() you will get true
Naveen 4:47 you said 4 objects created ...the same but here 8:49 you telling 3 objects. It quite confuse. Please clarify. Your videos are awesome thanks for your effort....
@@naveenautomationlabs Naveen, even though are different examples. On the first example I guess only 1 "Hello World" should be created in the pool. Isn't? Why create another "Hello World" in pool if already exist? The second example makes me more sense. Please, let me know why you create 2 "Hello World in the pool in the first example and only 1 in the second?
@2:10 one string object with literal as "new world" gt created without reference inside SCP. string objects present in SCP if not have reference variable are not applicable for garbage collection because a reference internally maintained by JVM.Is my understanding correct or not? Please clear my doubt.
Hi Naveen, 1 Query, On creating 2 string objects with new keyword and same string (ex: new ("Hello") and new ("Hello"), it will create 2 objects in Heap but how many will be there in SCP ? 1 or 2 ? Also and if there is already a string "Hello" present in SCP then will these statements create new String in SCP or will point to the existing one only?
Only 1 Hello object create in SCP.. .. and not pointing in SCP object until literals not given... (Without new operator) ex - string s1 = "hello" On this time object is pointing in SCP... as s1.
String s = new String("New World").intern(); what will be the difference after adding intern() with new String? How many object created and what is the use case or purpose to use intern()
String str1 = new String("Hello World"); String str2 = "Hello World"; if(str1 == str2) System.out.println("Strings str1 and str2 are equal"); else System.out.println("Strings str1 and str2 are not equals"); //output : Strings str1 and str2 are not equals /* If the new String causes the string to be added to the string pool (as you claim) then the next if statement * should return true...which it does not ... * When you create a string using new ...yes its created in the heap but it does not get * added to the string intern pool unless actually added * * Look at the next e.g. and checkout the difference for yourself */ String str3 = new String("Blue Sky").intern(); String str4 = "Blue Sky"; if(str3 == str4) System.out.println("Strings str3 and str4 are equal"); else System.out.println("Strings str3 and str4 are not equals"); //output : Strings str3 and str4 are equal /* In order to add a string created using new to the string intern pool is to specifically add it...as in case of str3 * str4 is a string literal and has the reference of str3 - since str3 was in the string intern pool * */
Navven Please tell me how to solve this type of problems like input String s="Tommorow", output="T$mm$$r$$$w". another one is input=2**7***9, and output is =23578279
while using string literals no Object is Create, but at video playback of 9:20 you are using String literal and saying one Object will be created. in the SCP. Since we are not using new keyword how can the Object be created. Correct me if I am wrong.?
Well this understanding of yours is wrong. When you create string with literals, it will be created inside the string pool only. When you use with new keyword, it will create two objects, one is in pool and one is in heap.
Anybody help me to give answer of below scenario. If first statement is String str1 = new String(" hello"); String str2 = " hello" In this case how many literal will be present in stringpool If answer is 2 .then why str2 didn't use already existing hello which was created first time.
@UCM5nE03DyluGKZwJ5w75Nzw there are no two "Hello World" in string pool in the video at 3:45. One is "New World" and another one is "Hello World". Please watch it once again.
How can someone explain with this level of clarity. I am amazed by your explanation skills, you are just the best👏
Thanks for watching
@@naveenautomationlabs4.56 I refer in other video I got information as object create 3 but you told 4.if I am wrong Plz correct me..
By far the best explanation of String objects!
Hello naveen... Thanku very much... I have worked as a manual tester... But only becoz of u i got a job in mnc as a automation tester.....
Thanks Naveen....... People with zero knowledge on Java can understand your explanation from basix.. You are different
With 10 mins a very important question got covered and for the same people will take sometimes ½ hour session, Thanks Naveen for the video 👍😊
Able to understand very clear. Really appreciating for your efforts. Thank you sir
Love these interview question series.
New series is started. Thanks Naveen. Please upload more videos.
These interview questions series is really very helpful. Thanks a lot sir.
Very best explanation very nice concept I got concept from this video thanks..
Such a beautiful explanation...sir,please can you explain how many objects will be created if we concat 2 strings
Naveen Ji, Thank you for sharing this information...👍👍🙏🙂
Thanks a Lot for taking up this topic. Concept is clear now
Hello Naveen! In min 5:00. There is something that makes me confused. After creating the 3 objects using new key word you create 2 literals that already exist in String pool then will not be necessary to create 2nd "Hello World" in the pool so at the end it will be 3 objects no 4 in the entire program as you mentioned. In 2 different programs the total of objects are 4 but not in only. Actually, in your next example you dont create a extra "Hello World" because already exist in the pool. Please, correct me if I am wrong.
Amazing explanation, Naveen 😊 really hats off to you
Sir
Have a question.
In java program
If ( n1.hascode()==n2.hascode()) return true
n1.equals(n2) true
Then why n1==n2 return false. ( Its satisfy hascode and equals contract)
Hi Naveen, I really love the way you explain the stuff and concepts.
Wanted to clarify one thing with you..
When we create an object using new keyword, it will create an object in heap but does it create the object in String pool as well?
Since there is no reference pointing to object created in StringPool then why will it create the object in StringPool?
Will it not lead to poor memory management?
As per my understanding, intern method takes care of doing that if it is not already available in scp.
Incredible job naveen, thank you very much 🙏
thank you very much naveen ...
Thanks sir I got more clarification from this video❤❤❤
Thank u Naveen Sir. Its's really cleared and helpful. :)
Great series again Naveen!! Very helpful!! Thanks a lot!!
Great explanation 👏
it will create 2 objects
one in heap area and
another one is string constant pool area i.e SCP area(if the object is not there with the same content if object is already with same content i won't create new object) and string ref n1 is pointing to heap area object
Thanks a lot it's very helpful
Wow ! that was an amazing explanation. Nobody does it better ;)
thanks Naveen
Love this series👍
Thank you sir. I have given wrong answer in an interview, now i realised what is the actual concept
brother can you make a video on how to build graphic library in c/c++
from scratch
Thank you ,awesome explanation..
String st = new String("Hello");
String s = "Hello";
System.out.println(st == s); //false
Can you please clarify this, if the first statement creates an object on heap and also in string pools, then when why st == s is false, instead of true?
also can you please explain the use of String.intern() method.
when you create Sting by using New keyword it create a new Sting in Non-Constant pool memory(Heap) ,where as by using Literal it create a sting in constant pool memory(Heap). so that references of both stings are different that the reason you get "false".instead of using == operator use equals() you will get true
Amazing series
Total 3, from string literals 1object + 2more objects.
@naveen , is it possible to count number of objects created in program? This is an question asked from me
Naveen 4:47 you said 4 objects created ...the same but here 8:49 you telling 3 objects. It quite confuse. Please clarify. Your videos are awesome thanks for your effort....
Both were different examples.
@@naveenautomationlabs Thanks Naveen for the prompt response.
@@naveenautomationlabs Naveen, even though are different examples. On the first example I guess only 1 "Hello World" should be created in the pool. Isn't? Why create another "Hello World" in pool if already exist? The second example makes me more sense. Please, let me know why you create 2 "Hello World in the pool in the first example and only 1 in the second?
@2:10 one string object with literal as "new world" gt created without reference inside SCP. string objects present in SCP if not have reference variable are not applicable for garbage collection because a reference internally maintained by JVM.Is my understanding correct or not? Please clear my doubt.
Very helpful 👍...
Thanks Man👍
I really appreciate your effort
Keep uploading more like this
Hi Naveen, 1 Query, On creating 2 string objects with new keyword and same string (ex: new ("Hello") and new ("Hello"), it will create 2 objects in Heap but how many will be there in SCP ? 1 or 2 ? Also and if there is already a string "Hello" present in SCP then will these statements create new String in SCP or will point to the existing one only?
Only 1 Hello object create in SCP.. .. and not pointing in SCP object until literals not given... (Without new operator) ex - string s1 = "hello"
On this time object is pointing in SCP... as s1.
It will create only one in SCP. But if in scp there is already "Hello" present then it won't create in SCP
Subscribed and liked.... Informative video... 👍
Please Clarify the Sequence of Memory allocation for Object and Reference in
SPM , HEAP and STACK
Super Naveen
String s = new String("New World").intern(); what will be the difference after adding intern() with new String? How many object created and what is the use case or purpose to use intern()
Could u make interview questions on business analysts junior.
It will be create 2 objects .one create in heap memory and other create in string pool
0:29 -- one object is created
Amazing!! Loved it!
Add these Java programs in new playlist
String str1 = new String("Hello World");
String str2 = "Hello World";
if(str1 == str2)
System.out.println("Strings str1 and str2 are equal");
else
System.out.println("Strings str1 and str2 are not equals");
//output : Strings str1 and str2 are not equals
/* If the new String causes the string to be added to the string pool (as you claim) then the next if statement
* should return true...which it does not ...
* When you create a string using new ...yes its created in the heap but it does not get
* added to the string intern pool unless actually added
*
* Look at the next e.g. and checkout the difference for yourself
*/
String str3 = new String("Blue Sky").intern();
String str4 = "Blue Sky";
if(str3 == str4)
System.out.println("Strings str3 and str4 are equal");
else
System.out.println("Strings str3 and str4 are not equals");
//output : Strings str3 and str4 are equal
/* In order to add a string created using new to the string intern pool is to specifically add it...as in case of str3
* str4 is a string literal and has the reference of str3 - since str3 was in the string intern pool
*
*/
Hi Naveen API automation Testing using bdd cucumber framework please upload the videos
Navven Please tell me how to solve this type of problems like input String s="Tommorow", output="T$mm$$r$$$w". another one is input=2**7***9, and output is =23578279
Awesome Naveen! Thank you for the interview series helping a lot..👍
Output->Only 1 string object
Two object. One is Heap and other in SCP
For second case 3 objects
Ossom sir
At 5:45 3 object will be created
Why String doesn't use scp only
why in case when we declare object first and then string literal it create total three objects not 2 in your first expression
I have same doubt..
what if String n1 = new String("Hello World");
String n2=new String("My World");
Now how many objects are created
public class StrObjectCreation {
public static void main(String[] args) {
String s1 = new String("You cannot change me");
String s2 = new String("You cannot change me");
System.out.println(s1 == s2);
String s3 = "You cannot change me";
System.out.println(s1 == s3);
String s4 = "You cannot change me";
System.out.println(s3 == s4);
String s5 = "You cannot "+"change me";
System.out.println(s4 == s5);
String s6 = "You cannot ";
String s7 = s6+"change me";
System.out.println(s4 == s7);
final String s8 = "You cannot ";
String s9 = s8+"change me";
System.out.println(s4 == s9);
}
}
Please check.
Could you please prove how two objects are created when we just write String n1 = new String("Hello World");`
Your telegram invite link expire in About section of your channel can you please send me invite link please
while using string literals no Object is Create, but at video playback of 9:20 you are using String literal and saying one Object will be created. in the SCP. Since we are not using new keyword how can the Object be created. Correct me if I am wrong.?
Well this understanding of yours is wrong. When you create string with literals, it will be created inside the string pool only. When you use with new keyword, it will create two objects, one is in pool and one is in heap.
@@naveenautomationlabs So if I create a single line String S1 = "new world". Will this line create any object it not.
It will create one string object as "new world" in string pool referred by S1 variable.
Naveen can you please send me your telegram channel link
2 one in heap and one in scp
Anybody help me to give answer of below scenario.
If first statement is
String str1 = new String(" hello");
String str2 = " hello"
In this case how many literal will be present in stringpool
If answer is 2 .then why str2 didn't use already existing hello which was created first time.
Only one literal in pool. And str2 will refer to "hello" from string pool. str1 will point to new object in heap.
@UCM5nE03DyluGKZwJ5w75Nzw there are no two "Hello World" in string pool in the video at 3:45. One is "New World" and another one is "Hello World". Please watch it once again.
2 object
It will create 2 object
1st comment good afternoon sir
0:22
2 Objects As The 'String' Class Is Used 2 Times In The Line,
1st in String n1,
2nd in new String("Hello World")
One object
2 objects
1 object
2
one
2 object