Why String is Immutable and Final in Java?

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

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

  • @punitdixit8268
    @punitdixit8268 4 года назад +11

    Note: From Java 7 onwards, the Java String Pool is stored in the Heap space.

  • @anilleo18
    @anilleo18 6 лет назад +5

    thanks for your time naveen...we r very much thankful towards your work

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

    This is the best explanation. Nobody can match you. Thanks

  • @ਪੰਜ-ਆਬ-ਛ6ਚ
    @ਪੰਜ-ਆਬ-ਛ6ਚ 3 года назад

    Hi Naveen,
    Thanks for spending so much time while creating the knowledge.
    I am still in doubt on immutability, to me, it seems every variable is immutable:
    String s1 = "Java";
    String s2 = "Java";
    String s3 = s1;
    s3 = "NewJava";
    System.out.println(s1);
    System.out.println(s2);
    System.out.println(s3);
    System.out.println(s1);
    int i1 = 10;
    int i2 = i1;
    i2=20;
    System.out.println(i1);
    Integer i3 = 30;
    int i4 = i3;
    i4 = 40;
    System.out.println(i3);

  • @nitish915
    @nitish915 6 лет назад +4

    String constant pool is in heap area.

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

    Important note: Java String Constant Pool is created inside Heap area.

  • @astuteacerbic
    @astuteacerbic 4 года назад +1

    Thanks Naveen for sharing. God bless you.

  • @USP7
    @USP7 6 лет назад +2

    Hi Naveen ,
    Can you make video on Role & Responsibility of tester in AWS cloud computing. much needed

  • @k.ravichandra1049
    @k.ravichandra1049 2 года назад +1

    Excellent explanation Naveen bro

  • @qwertkeys30
    @qwertkeys30 4 года назад +1

    Hi, I doubt Why strings are called immutable, because if give like this String s="hi" and in the next line, we give s="hello" the value of s will change right please help me to understand anyone.

  • @lamberto6405
    @lamberto6405 5 лет назад +1

    It would be great to see more code examples, specially tricky ones. There is 20 minutes of explanation with simple examples but some questions on tests are much trickier and students still fall into the trap.

  • @bikashdeuja9015
    @bikashdeuja9015 6 лет назад +1

    Can you please give me the Java tutor for Selenium that you have in your video. Couldn't find the right link.
    Thanks

  • @tejastoley6714
    @tejastoley6714 5 лет назад

    what happen when we declare like
    String s = new String("tejas");
    String s1 = new String("toley");
    is the ref. stored in heap memory?

  • @jvsnyc
    @jvsnyc 4 года назад

    I don't want to start some East-Coast/West-Coast Gangster Rap War here, but I did notice something. On the answer given by Naresh i Technologies channel here on RUclips, they emphasize very much something that you don't, and mention these only in passing. Some viewers angrily suggested that the "Real Reasons" were what you show here. However, while everything in here is true, I think there is a second reason that was there from the very beginning and became even more important over time and is what is emphasized by Hari Krishna in his video:
    Suitability of the very common data types of Sting/Integer/other wrapper classes as keys in Hashtable objects, and later HashMap objects, and also later members of SortedSet/NavigableSet or keys of SortedMap objects. His presentation suggests that this was primary and the other things all good, but came later. Anyway, you do highlight why final is necessary for these classes even tho there are plenty of times one wishes one could subclass them for legitimate and honorable purposes, the security danger is too great. Cheers.

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

    I need ur full videos of java

  • @shanthikandasamy
    @shanthikandasamy 5 лет назад +1

    How can I have live chat with you to discuss about selenium/java If I became the member of this?

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

    one confusion sir
    immutable String value are change value or not change

  • @venkateshandea1767
    @venkateshandea1767 6 лет назад +1

    Hi naveen anna, can u make any videos on selenium with c# atleast some advanced videos like framework level

  • @mayurkhare1928
    @mayurkhare1928 6 лет назад +1

    Hi Naveen
    My question is how to add firepath, firebug in latest mozila 'Quantum'

    • @vandanadhiman5532
      @vandanadhiman5532 6 лет назад

      I dont think there is a way except downgrading your firefox to the 46-49 versions.

    • @srihari4827
      @srihari4827 6 лет назад +1

      I think chropath for Firefox would help you if you are working with latest version

  • @vivekkurhe9881
    @vivekkurhe9881 6 лет назад +1

    Hi naveen please make some videos on protractor, it will be very helpful

  • @nukalasagar7078
    @nukalasagar7078 6 лет назад +1

    hi bro, if we create strings in non-constant loop like String s1=new String("java"); then how string is immutable,please kindly explain it

    • @virtexamit
      @virtexamit 6 лет назад +1

      When we create String using new operator 2 things happened 1st object created on heap and also same string also create on pool. Hope this help.

  • @sparshpandey2878
    @sparshpandey2878 6 лет назад +1

    Awesome Video , Can you please make one video on this program -> "You are given an array of 0s and 1s in random order. Segregate 0s on left side and 1s on right side of the array. Traverse array only once". I encountered this question in of the interviews I gave.
    Thanks in Advance

    • @truthlover3522
      @truthlover3522 6 лет назад

      public class segregate {
      public static void main(String[] args) {
      // TODO Auto-generSated method stub
      int arr[] = {1,0,0,1,0,1,0,0,1,0,1};
      System.out.println(arr.length);
      int j = -1;
      for (int i = 0; i < arr.length; i++) {
      // if number is smaller than 1
      // then swap it with j-th number
      if (arr[i] < 1) {
      j++;
      int temp = arr[j];
      arr[j] = arr[i];
      arr[i] = temp;
      }
      }
      System.out.println("");
      for(int m=0;m

    • @jarvisfriday7452
      @jarvisfriday7452 4 года назад

      By using this method we can segregate as per ur question
      Arrays.sort(a[]);

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

      arr = [1,0,0,0,1,1]
      d = {}
      for i in arr:
      d[i] = d.get(i,[]) + [i]
      new_arr = []
      if 0 in d:
      for i in range(len(d[0])):
      new_arr +=[0]
      if 1 in d:
      for i in range(len(d[1])):
      new_arr+=[1]
      print(new_arr)

  • @gayathrik8569
    @gayathrik8569 5 лет назад

    Since immutable string is sharing memory, how this can provide high security?

    • @jvsnyc
      @jvsnyc 4 года назад

      Because there is no easy way to write to that shared memory, unlike the Wild, Wild West of the C++ heap where pointers roam wild and free like tigers.

  • @gunaykhalilbayli1786
    @gunaykhalilbayli1786 5 лет назад +2

    great explanation as always.

  • @bharatvarshney2666
    @bharatvarshney2666 6 лет назад

    nicely explanation , thanks naveen

  • @gnsc
    @gnsc 6 лет назад

    awsome naveen bro.nice way of telling....👌

  • @priya-vf3jc
    @priya-vf3jc 6 лет назад

    my question is regarding Xpath ... as u said in drop down session like By.id() in main()... but wen v separately save xpaths in .propertiesfile and wen v want to automate that through keywords.java class den how to use it ...
    public void choose(String objectname, String data)
    {
    Select select = new Select(driver.findElement(By.xpath(prop.getProperty(objectname))));
    select.selectByVisibleText("working"); // ???
    }
    leadstatus= //*[@id='23:3372;a']/div/a dis is how i saved in objectrepository.propertiesfile
    ???

  • @HH_Linkmusic
    @HH_Linkmusic 5 лет назад

    Thank you so much! Very detailed explanation.

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

      sorry to be so offtopic but does anybody know of a way to get back into an Instagram account?
      I was dumb forgot the login password. I would appreciate any tricks you can offer me.

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

      @Winston Corey Instablaster :)

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

      @Randall William thanks for your reply. I got to the site through google and im trying it out now.
      I see it takes a while so I will reply here later with my results.

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

      @Randall William It worked and I actually got access to my account again. I am so happy!
      Thanks so much, you really help me out :D

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

      @Winston Corey glad I could help :)

  • @vamsim9671
    @vamsim9671 6 лет назад +1

    Hi naveen, please nake videos on protractor ...

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

    Hi Naveen, thanks for your helpful videos.
    If for an example
    String s="abc";
    s=s.concat("def");
    System.out.println(s);
    O/p: abc def
    So string value got changed.
    Could you please explain string is immutable concept using the above example

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

      After concatenate new object("abcdef") is created. Now s will refer to new object rather than old object("abc"). Old object is not changed and is no more referred by reference(s).

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

      @@uk7826 thank you

  • @sivakumar-mu3wj
    @sivakumar-mu3wj 3 года назад +1

    S1 will not change if S2 value is changed
    package com.basics.packageone;
    public class pkg_1_n12_stringTest {
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    String v1 = "Hai";
    System.out.println("V1 is " + v1);
    String v2 = "Hai";
    System.out.println("v2 is " + v2);
    v2 = "Bye";
    System.out.println("V2 after change is " + v2);
    System.out.println("V1 after change is " + v1);
    }
    }