Тёмный

Interview Question: How many String Objects will be created? - String Objects & String Constant Pool 

Naveen AutomationLabs
Подписаться 389 тыс.
Просмотров 49 тыс.
50% 1

~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
www.youtube.co...
Follow me on my Facebook Page:
/ naveenqtpexpert
Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:
t.me/joinchat/...
Naveen AutomationLabs Paid Courses:
Java & Selenium:
naveenautomatio...
Java & API +POSTMAN + RestAssured + HttpClient:
naveenautomatio...

Опубликовано:

 

5 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 90   
@sanghamitrabhowmicklive3013
@sanghamitrabhowmicklive3013 3 года назад
How can someone explain with this level of clarity. I am amazed by your explanation skills, you are just the best👏
@naveenautomationlabs
@naveenautomationlabs 3 года назад
Thanks for watching
@rukhma9307
@rukhma9307 2 года назад
By far the best explanation of String objects!
@SarangHoley
@SarangHoley 3 года назад
With 10 mins a very important question got covered and for the same people will take sometimes ½ hour session, Thanks Naveen for the video 👍😊
@spaininsights
@spaininsights 3 года назад
These interview questions series is really very helpful. Thanks a lot sir.
@barkhachetwani9735
@barkhachetwani9735 3 года назад
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.....
@JainNamit
@JainNamit 3 года назад
Love these interview question series.
@pachimalaanu1302
@pachimalaanu1302 2 года назад
Able to understand very clear. Really appreciating for your efforts. Thank you sir
@kavishautomationfactory170
@kavishautomationfactory170 3 года назад
New series is started. Thanks Naveen. Please upload more videos.
@sivaswamy6923
@sivaswamy6923 2 года назад
Thanks Naveen....... People with zero knowledge on Java can understand your explanation from basix.. You are different
@jayantamandal9732
@jayantamandal9732 3 года назад
Thanks a Lot for taking up this topic. Concept is clear now
@dowlathbashag65
@dowlathbashag65 3 года назад
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
@naveenautomationlabs 3 года назад
Both were different examples.
@dowlathbashag65
@dowlathbashag65 3 года назад
@@naveenautomationlabs Thanks Naveen for the prompt response.
@RobinsonMartinezEngineer
@RobinsonMartinezEngineer Год назад
​​@@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?
@MadirajuKChaitanya
@MadirajuKChaitanya 3 года назад
Naveen Ji, Thank you for sharing this information...👍👍🙏🙂
@metronadsouza506
@metronadsouza506 3 года назад
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 * */
@namitharose9231
@namitharose9231 2 года назад
Such a beautiful explanation...sir,please can you explain how many objects will be created if we concat 2 strings
@RajeshChilkamari
@RajeshChilkamari 3 года назад
Great series again Naveen!! Very helpful!! Thanks a lot!!
@jenishmoses
@jenishmoses 3 года назад
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.
@boyapatipavankumar2088
@boyapatipavankumar2088 Год назад
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
@snehaparekh8502
@snehaparekh8502 3 года назад
Incredible job naveen, thank you very much 🙏
@dp_prajapati
@dp_prajapati 3 года назад
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.
@deepchand517
@deepchand517 2 месяца назад
Very best explanation very nice concept I got concept from this video thanks..
@atulchavan4330
@atulchavan4330 3 года назад
Wow ! that was an amazing explanation. Nobody does it better ;)
@bhavikapatel7421
@bhavikapatel7421 3 года назад
Thank u Naveen Sir. Its's really cleared and helpful. :)
@vishalavishala1883
@vishalavishala1883 3 года назад
Total 3, from string literals 1object + 2more objects.
@artimandale8286
@artimandale8286 6 месяцев назад
Amazing explanation, Naveen 😊 really hats off to you
@RobinsonMartinezEngineer
@RobinsonMartinezEngineer Год назад
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.
@MyKalps
@MyKalps 3 года назад
thank you very much naveen ...
@shankarcheerala3089
@shankarcheerala3089 2 года назад
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
@thalapathyprasad9511
@thalapathyprasad9511 3 года назад
Great explanation 👏
@luckykodam6615
@luckykodam6615 3 года назад
Awesome Naveen! Thank you for the interview series helping a lot..👍
@drhattyxd-s_15fps2
@drhattyxd-s_15fps2 3 года назад
brother can you make a video on how to build graphic library in c/c++ from scratch
@vinith2320
@vinith2320 3 года назад
Thanks Man👍 I really appreciate your effort Keep uploading more like this
@visualart8609
@visualart8609 2 года назад
Thank you sir. I have given wrong answer in an interview, now i realised what is the actual concept
@sreevidyarejeesh8695
@sreevidyarejeesh8695 3 года назад
Love this series👍
@vivekguptacs
@vivekguptacs 3 года назад
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)
@tsara1395
@tsara1395 3 года назад
Could u make interview questions on business analysts junior.
@chinmaypawtekar4054
@chinmaypawtekar4054 3 года назад
Subscribed and liked.... Informative video... 👍
@deepchand517
@deepchand517 28 дней назад
Thanks sir I got more clarification from this video❤❤❤
@codewithcuriosity-cwc3155
@codewithcuriosity-cwc3155 2 года назад
Thanks a lot it's very helpful
@SumitSharma-qq4hk
@SumitSharma-qq4hk 3 года назад
Very helpful 👍...
@sridharlanka2721
@sridharlanka2721 3 года назад
Please Clarify the Sequence of Memory allocation for Object and Reference in SPM , HEAP and STACK
@ilavarasansriraman4140
@ilavarasansriraman4140 3 года назад
Add these Java programs in new playlist
@nishigandhasawant2632
@nishigandhasawant2632 3 года назад
It will be create 2 objects .one create in heap memory and other create in string pool
@rohitkumark2087
@rohitkumark2087 3 года назад
Thank you ,awesome explanation..
@ritikajoura5995
@ritikajoura5995 3 года назад
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?
@ipsitapriyadarshini5707
@ipsitapriyadarshini5707 3 года назад
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.
@AshishDubeyash4you
@AshishDubeyash4you Год назад
It will create only one in SCP. But if in scp there is already "Hello" present then it won't create in SCP
@shankardayal6928
@shankardayal6928 3 года назад
@naveen , is it possible to count number of objects created in program? This is an question asked from me
@vivekmit
@vivekmit Год назад
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()
@SachinSharma-fr1vb
@SachinSharma-fr1vb 2 года назад
@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.
@hareeshc9732
@hareeshc9732 3 года назад
Hi Naveen API automation Testing using bdd cucumber framework please upload the videos
@nishikantwairkar6866
@nishikantwairkar6866 3 года назад
Amazing series
@talog4102
@talog4102 2 года назад
Why String doesn't use scp only
@rizwanshahid1447
@rizwanshahid1447 3 года назад
thanks Naveen
@adeebatariq6200
@adeebatariq6200 2 года назад
Amazing!! Loved it!
@vicsgarg6127
@vicsgarg6127 3 года назад
why in case when we declare object first and then string literal it create total three objects not 2 in your first expression
@vivekguptacs
@vivekguptacs 3 года назад
I have same doubt..
@PAVANKS-ct1iw
@PAVANKS-ct1iw 3 месяца назад
what if String n1 = new String("Hello World"); String n2=new String("My World"); Now how many objects are created
@sphanindra5981
@sphanindra5981 2 года назад
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
@sureshisoft4555
@sureshisoft4555 3 года назад
Super Naveen
@shambhand5556
@shambhand5556 2 года назад
Could you please prove how two objects are created when we just write String n1 = new String("Hello World");`
@riteshranjanmishra967
@riteshranjanmishra967 3 года назад
Two object. One is Heap and other in SCP For second case 3 objects
@gowrisankarsonti809
@gowrisankarsonti809 3 года назад
0:29 -- one object is created
@gametimewitharyan6665
@gametimewitharyan6665 3 года назад
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")
@sriyanshjain6645
@sriyanshjain6645 3 года назад
Your telegram invite link expire in About section of your channel can you please send me invite link please
@mayankvarshney6014
@mayankvarshney6014 3 года назад
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.?
@naveenautomationlabs
@naveenautomationlabs 3 года назад
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.
@mayankvarshney6014
@mayankvarshney6014 3 года назад
@@naveenautomationlabs So if I create a single line String S1 = "new world". Will this line create any object it not.
@naveenautomationlabs
@naveenautomationlabs 3 года назад
It will create one string object as "new world" in string pool referred by S1 variable.
@himanshupokhriyal6883
@himanshupokhriyal6883 Год назад
Output->Only 1 string object
@sriyanshjain6645
@sriyanshjain6645 3 года назад
Naveen can you please send me your telegram channel link
@syedafarzana960
@syedafarzana960 3 года назад
Ossom sir
@debaprasadsahoo3707
@debaprasadsahoo3707 3 года назад
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.
@vivekguptacs
@vivekguptacs 3 года назад
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.
@naveenautomationlabs
@naveenautomationlabs 3 года назад
Only one literal in pool. And str2 will refer to "hello" from string pool. str1 will point to new object in heap.
@naveenautomationlabs
@naveenautomationlabs 3 года назад
@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.
@nishantlaxkar7451
@nishantlaxkar7451 2 года назад
At 5:45 3 object will be created
@yogender8094
@yogender8094 3 года назад
It will create 2 object
@rockyrajeshyt6658
@rockyrajeshyt6658 3 года назад
1st comment good afternoon sir
@raushantiwari2865
@raushantiwari2865 3 года назад
2 one in heap and one in scp
@fareensayyad3147
@fareensayyad3147 3 года назад
2 object
@pedurujagadish5048
@pedurujagadish5048 2 года назад
One object
@sivashankar-ix4df
@sivashankar-ix4df 3 года назад
1 object
@rockyrajeshyt6658
@rockyrajeshyt6658 3 года назад
2 objects
@ashutoshsingh-uh4io
@ashutoshsingh-uh4io 3 года назад
2
@aadeshtanekar2059
@aadeshtanekar2059 3 года назад
one
@naveenkumarsingh1900
@naveenkumarsingh1900 3 года назад
2 object
Далее
Why String is Immutable and Final in Java?
19:59
Просмотров 88 тыс.
Star Pattern Logic - Part 1 - By Naveen AutomationLabs
22:34
String Immutable In Java Interview Question
9:47
Просмотров 21 тыс.