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

Поділитися
Вставка
  • Опубліковано 18 бер 2021
  • ~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:
    ua-cam.com/users/Naveen%20Au...
    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/COJqZUPB02r5sB7...
    Naveen AutomationLabs Paid Courses:
    Java & Selenium:
    naveenautomationlabs.com/manua...
    Java & API +POSTMAN + RestAssured + HttpClient:
    naveenautomationlabs.com/selen...
  • Наука та технологія

КОМЕНТАРІ • 89

  • @sanghamitrabhowmicklive3013
    @sanghamitrabhowmicklive3013 3 роки тому +11

    How can someone explain with this level of clarity. I am amazed by your explanation skills, you are just the best👏

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

  • @spaininsights
    @spaininsights 3 роки тому +4

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

  • @JainNamit
    @JainNamit 3 роки тому +4

    Love these interview question series.

  • @kavishautomationfactory170
    @kavishautomationfactory170 3 роки тому +1

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

  • @snehaparekh8502
    @snehaparekh8502 3 роки тому +1

    Incredible job naveen, thank you very much 🙏

  • @RajeshChilkamari
    @RajeshChilkamari 3 роки тому +1

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

  • @rukhma9307
    @rukhma9307 2 роки тому +3

    By far the best explanation of String objects!

  • @pachimalaanu1302
    @pachimalaanu1302 2 роки тому +1

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

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

  • @jayantamandal9732
    @jayantamandal9732 3 роки тому +2

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

  • @MadirajuKChaitanya
    @MadirajuKChaitanya 3 роки тому +1

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

  • @atulchavan4330
    @atulchavan4330 3 роки тому +1

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

  • @sreevidyarejeesh8695
    @sreevidyarejeesh8695 3 роки тому +1

    Love this series👍

  • @vinith2320
    @vinith2320 3 роки тому +1

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

  • @adeebatariq6200
    @adeebatariq6200 2 роки тому

    Amazing!! Loved it!

  • @sivaswamy6923
    @sivaswamy6923 2 роки тому

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

  • @bhavikapatel7421
    @bhavikapatel7421 3 роки тому +1

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

  • @thalapathyprasad9511
    @thalapathyprasad9511 3 роки тому +1

    Great explanation 👏

  • @artimandale8286
    @artimandale8286 4 місяці тому

    Amazing explanation, Naveen 😊 really hats off to you

  • @MyKalps
    @MyKalps 3 роки тому +1

    thank you very much naveen ...

  • @SumitSharma-qq4hk
    @SumitSharma-qq4hk 3 роки тому +1

    Very helpful 👍...

  • @rohitkumark2087
    @rohitkumark2087 3 роки тому

    Thank you ,awesome explanation..

  • @deepchand517
    @deepchand517 7 днів тому

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

  • @chinmaypawtekar4054
    @chinmaypawtekar4054 3 роки тому +1

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

  • @codewithcuriosity-cwc3155
    @codewithcuriosity-cwc3155 2 роки тому

    Thanks a lot it's very helpful

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

  • @nishikantwairkar6866
    @nishikantwairkar6866 3 роки тому

    Amazing series

  • @namitharose9231
    @namitharose9231 2 роки тому

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

  • @sureshisoft4555
    @sureshisoft4555 3 роки тому

    Super Naveen

  • @rizwanshahid1447
    @rizwanshahid1447 2 роки тому

    thanks Naveen

  • @luckykodam6615
    @luckykodam6615 3 роки тому +2

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

  • @syedafarzana960
    @syedafarzana960 3 роки тому

    Ossom sir

  • @visualart8609
    @visualart8609 2 роки тому

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

  • @shankardayal6928
    @shankardayal6928 3 роки тому

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

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

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

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

  • @vishalavishala1883
    @vishalavishala1883 3 роки тому +4

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

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

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

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

  • @ilavarasansriraman4140
    @ilavarasansriraman4140 3 роки тому +1

    Add these Java programs in new playlist

  • @rockyrajeshyt6658
    @rockyrajeshyt6658 3 роки тому +1

    1st comment good afternoon sir

  • @tsara1395
    @tsara1395 3 роки тому +1

    Could u make interview questions on business analysts junior.

  • @sridharlanka2721
    @sridharlanka2721 3 роки тому

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

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

  • @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 11 місяців тому

      It will create only one in SCP. But if in scp there is already "Hello" present then it won't create in SCP

  • @hareeshc9732
    @hareeshc9732 3 роки тому

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

  • @nishigandhasawant2632
    @nishigandhasawant2632 3 роки тому

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

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

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

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

  • @gowrisankarsonti809
    @gowrisankarsonti809 2 роки тому

    0:29 -- one object is created

  • @riteshranjanmishra967
    @riteshranjanmishra967 3 роки тому

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

  • @sriyanshjain6645
    @sriyanshjain6645 3 роки тому

    Your telegram invite link expire in About section of your channel can you please send me invite link please

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

  • @talog4102
    @talog4102 2 роки тому +1

    Why String doesn't use scp only

  • @himanshupokhriyal6883
    @himanshupokhriyal6883 Рік тому

    Output->Only 1 string object

  • @raushantiwari2865
    @raushantiwari2865 3 роки тому +1

    2 one in heap and one in scp

  • @shambhand5556
    @shambhand5556 2 роки тому

    Could you please prove how two objects are created when we just write String n1 = new String("Hello World");`

  • @fareensayyad3147
    @fareensayyad3147 3 роки тому +1

    2 object

  • @PAVANKS-ct1iw
    @PAVANKS-ct1iw Місяць тому

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

  • @yogender8094
    @yogender8094 3 роки тому +1

    It will create 2 object

  • @sriyanshjain6645
    @sriyanshjain6645 3 роки тому

    Naveen can you please send me your telegram channel link

  • @nishantlaxkar7451
    @nishantlaxkar7451 Рік тому

    At 5:45 3 object will be 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.

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

  • @pedurujagadish5048
    @pedurujagadish5048 2 роки тому

    One object

  • @rockyrajeshyt6658
    @rockyrajeshyt6658 3 роки тому

    2 objects

  • @sivashankar-ix4df
    @sivashankar-ix4df 3 роки тому

    1 object

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

  • @aadeshtanekar2059
    @aadeshtanekar2059 3 роки тому

    one

  • @ashutoshsingh-uh4io
    @ashutoshsingh-uh4io 3 роки тому

    2

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

  • @naveenkumarsingh1900
    @naveenkumarsingh1900 3 роки тому +1

    2 object