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

Поделиться
HTML-код
  • Опубликовано: 22 ноя 2024

Комментарии • 91

  • @sanghamitrabhowmicklive3013
    @sanghamitrabhowmicklive3013 3 года назад +14

    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

    • @shaikmuneer5991
      @shaikmuneer5991 9 дней назад

      ​@@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..

  • @rukhma9307
    @rukhma9307 2 года назад +3

    By far the best explanation of String objects!

  • @barkhachetwani9735
    @barkhachetwani9735 3 года назад +2

    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.....

  • @sivaswamy6923
    @sivaswamy6923 2 года назад

    Thanks Naveen....... People with zero knowledge on Java can understand your explanation from basix.. You are different

  • @SarangHoley
    @SarangHoley 3 года назад +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 👍😊

  • @pachimalaanu1302
    @pachimalaanu1302 2 года назад +1

    Able to understand very clear. Really appreciating for your efforts. Thank you sir

  • @JainNamit
    @JainNamit 3 года назад +4

    Love these interview question series.

  • @kavishautomationfactory170
    @kavishautomationfactory170 3 года назад +1

    New series is started. Thanks Naveen. Please upload more videos.

  • @spaininsights
    @spaininsights 3 года назад +4

    These interview questions series is really very helpful. Thanks a lot sir.

  • @deepchand517
    @deepchand517 3 месяца назад

    Very best explanation very nice concept I got concept from this video thanks..

  • @namitharose9231
    @namitharose9231 2 года назад

    Such a beautiful explanation...sir,please can you explain how many objects will be created if we concat 2 strings

  • @MadirajuKChaitanya
    @MadirajuKChaitanya 3 года назад +1

    Naveen Ji, Thank you for sharing this information...👍👍🙏🙂

  • @jayantamandal9732
    @jayantamandal9732 3 года назад +2

    Thanks a Lot for taking up this topic. Concept is clear now

  • @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.

  • @artimandale8286
    @artimandale8286 8 месяцев назад

    Amazing explanation, Naveen 😊 really hats off to you

  • @vivekguptacs
    @vivekguptacs 3 года назад +1

    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)

  • @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.

  • @snehaparekh8502
    @snehaparekh8502 3 года назад +1

    Incredible job naveen, thank you very much 🙏

  • @MyKalps
    @MyKalps 3 года назад +1

    thank you very much naveen ...

  • @deepchand517
    @deepchand517 2 месяца назад

    Thanks sir I got more clarification from this video❤❤❤

  • @bhavikapatel7421
    @bhavikapatel7421 3 года назад +1

    Thank u Naveen Sir. Its's really cleared and helpful. :)

  • @RajeshChilkamari
    @RajeshChilkamari 3 года назад +1

    Great series again Naveen!! Very helpful!! Thanks a lot!!

  • @thalapathyprasad9511
    @thalapathyprasad9511 3 года назад +1

    Great explanation 👏

  • @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

  • @codewithcuriosity-cwc3155
    @codewithcuriosity-cwc3155 2 года назад

    Thanks a lot it's very helpful

  • @atulchavan4330
    @atulchavan4330 3 года назад +1

    Wow ! that was an amazing explanation. Nobody does it better ;)

  • @rizwanshahid1447
    @rizwanshahid1447 3 года назад

    thanks Naveen

  • @sreevidyarejeesh8695
    @sreevidyarejeesh8695 3 года назад +1

    Love this series👍

  • @visualart8609
    @visualart8609 2 года назад

    Thank you sir. I have given wrong answer in an interview, now i realised what is the actual concept

  • @drhattyxd-s_15fps2
    @drhattyxd-s_15fps2 3 года назад +1

    brother can you make a video on how to build graphic library in c/c++
    from scratch

  • @rohitkumark2087
    @rohitkumark2087 3 года назад

    Thank you ,awesome explanation..

  • @jenishmoses
    @jenishmoses 3 года назад +2

    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

  • @nishikantwairkar6866
    @nishikantwairkar6866 3 года назад

    Amazing series

  • @vishalavishala1883
    @vishalavishala1883 3 года назад +4

    Total 3, from string literals 1object + 2more objects.

  • @shankardayal6928
    @shankardayal6928 3 года назад

    @naveen , is it possible to count number of objects created in program? This is an question asked from me

  • @dowlathbashag65
    @dowlathbashag65 3 года назад +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?

  • @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.

  • @SumitSharma-qq4hk
    @SumitSharma-qq4hk 3 года назад +1

    Very helpful 👍...

  • @vinith2320
    @vinith2320 3 года назад +1

    Thanks Man👍
    I really appreciate your effort
    Keep uploading more like this

  • @ritikajoura5995
    @ritikajoura5995 3 года назад +1

    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

  • @chinmaypawtekar_Vlog
    @chinmaypawtekar_Vlog 3 года назад +1

    Subscribed and liked.... Informative video... 👍

  • @sridharlanka2721
    @sridharlanka2721 3 года назад

    Please Clarify the Sequence of Memory allocation for Object and Reference in
    SPM , HEAP and STACK

  • @sureshisoft4555
    @sureshisoft4555 3 года назад

    Super Naveen

  • @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()

  • @tsara1395
    @tsara1395 3 года назад +1

    Could u make interview questions on business analysts junior.

  • @nishigandhasawant2632
    @nishigandhasawant2632 3 года назад

    It will be create 2 objects .one create in heap memory and other create in string pool

  • @gowrisankarsonti809
    @gowrisankarsonti809 3 года назад

    0:29 -- one object is created

  • @adeebatariq6200
    @adeebatariq6200 2 года назад

    Amazing!! Loved it!

  • @ilavarasansriraman4140
    @ilavarasansriraman4140 3 года назад +1

    Add these Java programs in new playlist

  • @metronadsouza506
    @metronadsouza506 3 года назад +4

    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
    *
    */

  • @hareeshc9732
    @hareeshc9732 3 года назад

    Hi Naveen API automation Testing using bdd cucumber framework please upload the videos

  • @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

  • @luckykodam6615
    @luckykodam6615 3 года назад +2

    Awesome Naveen! Thank you for the interview series helping a lot..👍

  • @himanshupokhriyal6883
    @himanshupokhriyal6883 Год назад

    Output->Only 1 string object

  • @riteshranjanmishra967
    @riteshranjanmishra967 3 года назад

    Two object. One is Heap and other in SCP
    For second case 3 objects

  • @syedafarzana960
    @syedafarzana960 3 года назад

    Ossom sir

  • @nishantlaxkar7451
    @nishantlaxkar7451 2 года назад

    At 5:45 3 object will be created

  • @talog4102
    @talog4102 2 года назад +1

    Why String doesn't use scp only

  • @vicsgarg6127
    @vicsgarg6127 3 года назад +1

    why in case when we declare object first and then string literal it create total three objects not 2 in your first expression

  • @PAVANKS-ct1iw
    @PAVANKS-ct1iw 5 месяцев назад

    what if String n1 = new String("Hello World");
    String n2=new String("My World");
    Now how many objects are created

  • @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.

  • @shambhand5556
    @shambhand5556 2 года назад

    Could you please prove how two objects are created when we just write String n1 = 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 года назад +1

      It will create one string object as "new world" in string pool referred by S1 variable.

  • @sriyanshjain6645
    @sriyanshjain6645 3 года назад

    Naveen can you please send me your telegram channel link

  • @raushantiwari2865
    @raushantiwari2865 3 года назад +1

    2 one in heap and one in scp

  • @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.

  • @naveenkumarsingh1900
    @naveenkumarsingh1900 3 года назад +1

    2 object

  • @yogender8094
    @yogender8094 3 года назад +1

    It will create 2 object

  • @rockyrajeshyt6658
    @rockyrajeshyt6658 3 года назад +1

    1st comment good afternoon sir

  • @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")

  • @pedurujagadish5048
    @pedurujagadish5048 2 года назад

    One object

  • @rockyrajeshyt6658
    @rockyrajeshyt6658 3 года назад

    2 objects

  • @sivashankar-ix4df
    @sivashankar-ix4df 3 года назад

    1 object

  • @ashutoshsingh-uh4io
    @ashutoshsingh-uh4io 3 года назад

    2

  • @aadeshtanekar2059
    @aadeshtanekar2059 3 года назад

    one

  • @fareensayyad3147
    @fareensayyad3147 3 года назад +1

    2 object