String Immutable In Java Interview Question

Поділитися
Вставка
  • Опубліковано 25 лис 2024

КОМЕНТАРІ • 22

  • @naveenautomationlabs
    @naveenautomationlabs  2 роки тому +9

    One small correction in the video, when we concatenate x and y it will generate a new String in heap memory not in SCP. So in this example, "abcabc" will be stored inside the heap memory.
    this is the internal implementation of concat() method in java:
    Concat method:
    public String concat(String str)
    {
    int otherLen = str.length();
    if (otherLen == 0) {
    return this;
    }
    int len = value.length;
    char buf[] = Arrays.copyOf(value, len + otherLen);
    str.getChars(buf, len);
    return new String(buf, true);
    }

  • @varshashinde6641
    @varshashinde6641 2 роки тому +4

    Great... Create series like this which covers small nd important topic... Waiting for next one...👍

  • @shilpashravge5393
    @shilpashravge5393 Рік тому +1

    thank you Naveen :)

  • @artimandale8286
    @artimandale8286 6 місяців тому

    Simply amazing

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

    First comment sir...youre superb sir

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

    Hi Naveen,
    Can you please tell me solutions for the question in the below.
    Split a String but don't split when character repeats.. input s="aHHHbYY";
    Out put would be like output:[a, HHH, b, YY]
    Thanks in advance.
    Ragards,
    Kanvitha

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

    Amazing explanation......

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

    Hi Naveen, could you please tell some tips to clear client round. It would be helpful

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

    The value of x is abc Naveen in this question

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

    Very helpful video but just one correction, at 7:51 you mentioned Strings are the most commonly used data type. But it is not data type, it is class. We can call it data storage but not data type.

    • @naveenautomationlabs
      @naveenautomationlabs  Рік тому +1

      String is a non primitive data type, all the classes in java comes under non primitive data types category. It is also called derived data type or reference type which refers to an object.
      So yes String is a data type.

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

    Good video make a series'

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

    Since abcabc is not refered by anyone , will it be removed by GC ?

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

      No, GC can not access the SCP area. It is wiped off when JVM is shutdown. Because of SCP, it is faster to use String.

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

      @@Iam_namangupta But from Java 7 SCP is the part of heap memory only

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

      Yup, SCP area is part of Heap, but is special area and JVM knows that it is not suppose to remove the constants inside it even if there is no reference to them.

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

      ​ @CricJammer If the SCP is not garbage collected until the JVM is shut down, is there a possibility that SCP can go out of memory? or it will start to use the native OS memory?

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

      SCP takes advantage of special treatment from the garbage collector. The garbage collector does not visit SCP with the same frequency (cycles) as other memory zones but it does.

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

    abc

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

    x