9.9 String is Immutable

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

КОМЕНТАРІ • 223

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

    You are the best Java Instructor

  • @dhavalshah69
    @dhavalshah69 4 роки тому +21

    I think when you do new String ("Navin") it will create a new object 103 - Navin in the heap memory. In the video it say it will refer to the same one

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

      same doubt will the object be point to the memory address of string pool which having the string literal as "Navin"???

    • @DeepakKumar-dw1re
      @DeepakKumar-dw1re 2 роки тому

      You are absolutely Right...

    • @AmanTheMystery
      @AmanTheMystery 2 роки тому +2

      @@seanjesuharun1784 if any string is created using new keyword then for which a new string is created in heap memory , not in string pool..

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

      Is this true? I read the same somewhere else. Iam confused now. If by using new keyword also it refers to string pool or if the value is stored in string pool,then what is the purpose of using string intern() method.

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

      My question exactly.

  • @shyamelakapalli1051
    @shyamelakapalli1051 6 років тому +10

    String s=new String ("syam"); if you use s.intern(); then only it points to string pool until then it points to heap.

  • @vibinvibs7841
    @vibinvibs7841 3 роки тому +5

    thank you sir fr teaching us . u r one of the great teacher ever@ navin reddy

  • @yuvarajs3747
    @yuvarajs3747 8 років тому +23

    Hai Navin Reddy, Please give us proper answer for String memory management and String is Immutable, In interview I told answer for string immutable As you taught in this video They rejected me in first round itself.

    • @namratasanger5745
      @namratasanger5745 6 років тому

      What they have asked you in interview regarding string can you tell me?

    • @ajithranrox5524
      @ajithranrox5524 6 років тому +1

      maybe its the Grammer!

    • @withlovesandeep4424
      @withlovesandeep4424 6 років тому +1

      @@namratasanger5745 same experience for me also..
      Why String is immutable ?
      Difference between
      String str=String("abc") and
      String str1="abc"

    • @namratasanger5745
      @namratasanger5745 6 років тому

      @@withlovesandeep4424 they both differ because of how they point and store the data isn't that's the right answer?

    • @sarin374
      @sarin374 5 років тому

      ajithran rox 😂😂

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

    "Welcome back aliens" is immutable

  • @harithkumar4501
    @harithkumar4501 6 років тому +111

    I watch complete adds on your videos , so that you can earn some money .

  • @SurajPandey-vi9gr
    @SurajPandey-vi9gr 4 місяці тому

    Amazing Telusko you are such a good teacher

  • @harisudan6637
    @harisudan6637 7 років тому +15

    Hi navin, whenever u teach any concept could you give a program code example it will useful to understand the concept easily

  • @babithabalija9255
    @babithabalija9255 5 років тому +2

    I cant find the app in play store. Wonderful videos. Crisp and clear explanation

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

    @0:36 When Navin says "mutability is a crime"
    Me: "It's true..Corona should have been a String(immutable)"
    😂🥲
    April: 2021

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

      Funny

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

      its "Navin"

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

      @@anshsarin19 lol ok bigger problems here.. I'll correct that using String buffer 👍

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

      😂

  • @Sumitanad
    @Sumitanad 5 років тому +3

    Creating New Strings Earlier we promised to talk more about the subtle differences between the various methods of creating a String. Let's look at a couple of examples of how a String might be created, and let's further assume that no other String objects exist in the pool:
    String s = "abc"; // creates one String object and one // reference variable In this simple case, "abc" will go in the pool and s will refer to it.
    String s = new String("abc"); // creates two objects, // and one reference variable In this case, because we used the new keyword, Java will create a new String object in normal (nonpool) memory, and s will refer to it. In addition, the literal "abc" will be placed in the pool.

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

      Will a new 'abc' literal be placed in pool after calling new, or the previous 'abc' will be referenced?

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

      Okay, 'abc' will be placed in pool if it doesn't exist. Else the previous 'abc' is referenced

  • @terrificsuper
    @terrificsuper 5 років тому +5

    Good work my dude

  • @aymanmomin432
    @aymanmomin432 4 роки тому +4

    Sir can you please make a video on heap and stack memory along with a separate video on a roadmap for desktop application developers

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

    UHR THE BEST TEACHER EVER

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

    Thank you that makes a lot of sense

  • @muhammadomersaleem4919
    @muhammadomersaleem4919 7 років тому +3

    Hi, what if we do not create str1 object and change str to "Reddy". Will it also create new string in string pool or will it change/replace Navin with Reddy? If first case is true then what will happen with Navin in string pool?

  • @pareshhere
    @pareshhere 4 роки тому +7

    Looking you drawing on board and now all animations... That's mutable... 😁

  • @ankitanand2702
    @ankitanand2702 7 років тому +5

    Due to string immutability you can safely return them from functions.
    If strings were mutable anyone could have changed your return value.
    Thats why serialization is done also.

  • @NavinKumar-ig4xb
    @NavinKumar-ig4xb 4 роки тому

    I also faced name issue. People used to send or write to wrong Naveen. Nice video

  • @Victor-tl4dk
    @Victor-tl4dk 3 роки тому +1

    Thanks for the video!
    Consider getting a better mic!!

  • @shahriarmim4696
    @shahriarmim4696 6 років тому +17

    owwhoo ! Telusko is always been great ! But I don't know how he had mistaken at 4:57 his new String("navin"); will create a new object on heap outside of the String Pool where 'navin' exists and this 'navin' is not that 'navin' from String Pool !

    • @toramihai
      @toramihai 6 років тому +3

      He's a person, he can do a mistake, wright? ;) He learned us a lots of things for free, we should thank him...

    • @shahriarmim4696
      @shahriarmim4696 6 років тому

      Ofcourse. that's beyond dispute ! @toramihai

    • @toramihai
      @toramihai 6 років тому +8

      I've searched a little and I think the stuff goes like that: when you have String a = new String ("abc") it will be two objects created, one that is abc in string pool and one from new keyword in heap, the object from heap will point to the pool object for his value...i hope i understood well

    • @coden3902
      @coden3902 5 років тому +2

      @@toramihai Yes right ....i was also wondering the same ! and if we want to put a into pool we have to use a.intern() method.

    • @sidharthvijayakumar3521
      @sidharthvijayakumar3521 4 роки тому

      True new keyword makes a new object

  • @mrx-qi8th
    @mrx-qi8th 4 роки тому +1

    string s1=new string("navin");
    will this create a s1 variable inside main frame of stack? correct me if i'm wrong.
    what i have in mind is that { we have s1 inside stack filled with the memory location of heap memory
    now "new string" we have 4Bytes in heap memory filled with the address of "navin" in pool string
    am i right?

  • @saravanabalaji1913
    @saravanabalaji1913 4 роки тому +1

    Well explained sir Thank you...!👌✨

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

    something special with 101 i see it many times....

  • @divyaturlapaty7271
    @divyaturlapaty7271 5 років тому +1

    please correct that part sir about new String("Navin") creating a new object..:)

  • @lakshayarora7632
    @lakshayarora7632 7 років тому +1

    Sir I have been listening to your videos "Java Tutorial For Beginners".Will these videos cover the entire core java syllabus?

  • @2rajatkiit
    @2rajatkiit 8 років тому +5

    String constant pool is created in Method Area not heap area. We access it by using intern () method which create object in heap area of that string.

    • @jvsnyc
      @jvsnyc 4 роки тому

      People were saying that was only true until JDK 7 in other videos. I haven't checked yet...

  • @swathikumar3074
    @swathikumar3074 6 років тому +5

    Sorry for saying.this is wrong when ever we create string using new keyword it will never pointing to string pool it will create new string in heap .if u want to put that value into sting pool there is a method called intern()

    • @akshaysaini9740
      @akshaysaini9740 6 років тому +2

      .if u want to put that value into heap than this method is called intern()
      String myString = new String( "old String" );
      String myCache = myString;
      System.out.println( "equal: " + myString.equals( myCache ) );
      System.out.println( "same: " + ( myString == myCache ) );
      output:
      equal: true
      same: true
      String myString = new String( "old String" );
      String myCache = myString.intern();
      System.out.println( "equal: " + myString.equals( myCache ) );
      System.out.println( "same: " + ( myString == myCache ) );
      output:
      equal: true
      same: false

  • @webapplicationguide3798
    @webapplicationguide3798 5 років тому

    Thank you Navin !!

  • @sumitbabel5415
    @sumitbabel5415 4 роки тому

    Amazingly explained

  • @Malone-vq2ft
    @Malone-vq2ft 7 років тому +3

    5:19 What kind of object is that, that have a memory address. I thought only references could hold memory addresses.

    • @bittooaggarwal5776
      @bittooaggarwal5776 4 роки тому

      String s1 = "Shiva";
      String s2 = "Shiva";

      s1 = "Neelkantha";

      String s3 = new String("Shiva");
      String s4 = "Shiva";

      System.out.println(System.identityHashCode(s1) + " : "+System.identityHashCode(s2) + " : " + System.identityHashCode(s3) + " : " +System.identityHashCode(s4));
      System.out.println(s3.equals(s2));
      System.out.println(s3.equals(s4));
      System.out.println(s3 == s4);
      System.out.println(s2 == s4);
      maybe this code can you help you get a bit of clarification, here both s3 has different memory location than s2 and s4 but its value is same.

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

    Hmm good 🙂.. But in different videos, blogs different informations 😶 which confusing me 😐. This video make sense for me a bit more. Goog.

  • @pratikghotekar8664
    @pratikghotekar8664 7 років тому +1

    Hello sir, Can you please tell me wat does synchronization means in terms of stringbuilder and stringbuffer classes? An exmple wud be appricaited.

  • @Malone-vq2ft
    @Malone-vq2ft 6 років тому

    class StringPoolTest1{
    public static void main(String[] args){
    String s0 = "hello ".concat("world");
    }
    }
    "hello " and "world" are located in the String Pool
    is "hello world" located in it as well? If not, where is it? Only in the Heap?
    What happens between the Heap and the String Pool when
    s0.intern();

    • @gaganyadav2448
      @gaganyadav2448 4 роки тому

      "Hello World" will be located in heap as you are using concat which is a runtime operation + both "hello" and "world" will be stored in string pool as well because both of them are constant values

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

    I really really need this answer where did u learn java or string concept....pls reply..

  • @shilpamore1345
    @shilpamore1345 5 років тому +1

    Hello Navin, i come across the sentence that strings being immutable avoids race condition.
    I am not able to visualize this. Can you please explain it?

  • @saadmanahmed860
    @saadmanahmed860 6 років тому

    naveen...sir
    u r a dynamic beak...awesome.

  • @thebunerikhan
    @thebunerikhan 7 років тому

    This man is awesome.

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

    Please create a video on stack and heap memory

  • @kesitkusumo628
    @kesitkusumo628 7 років тому

    Thanks Navin !

  • @avigeek
    @avigeek 5 років тому

    best ever explanation

  • @mehrosenasir3966
    @mehrosenasir3966 5 років тому +1

    If String str="Navin" and let's say it has an address in heap as 100. Now as you said, If I do this like str="Reddy" this will assign a new address to str lets say 101. Now the question is both values are present in the heap memory but how can I now point the old str which has value "Navin"?

    • @mechvishwanath
      @mechvishwanath 5 років тому

      I think it's not possible to point old str as reference updated with new one ...

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

      same doubt to me

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

    Hi Navin, I've one doubt. Is it possible to declare and define methods in java separately like C?

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

    Easy to understand

  • @jagannathrao-cq9wg
    @jagannathrao-cq9wg Місяць тому

    Hi sir,
    Nice explanation, but you have not clearly explained about,
    String ss = "navin";
    ss="java";
    then it will print "java" as string is immutable that all we know. but if we want ss="navin" then how to print because we have modified the ss="java"

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

    Are all primitive data types immutable or only String is immutable?

  • @ArunraajSingh
    @ArunraajSingh 7 років тому

    best explanation dude

  • @UhOohSpaghettiOs
    @UhOohSpaghettiOs 7 років тому +1

    Thanks Naveen

  • @Turnpost2552
    @Turnpost2552 5 років тому

    Nicely done

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

    Thanks Naveen))

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

    Thank you!

  • @RestIess.Gambler
    @RestIess.Gambler Місяць тому

    I'm soo confused. If I can't change the value then, explain:
    string str = "navin";
    string str = "freddy";
    print(str);
    Why does it print "freddy" and not "navin". The value of the first string has been changed from navin to freddy, right? I need someone to clear me up.

  • @sripathivenkatreddy6251
    @sripathivenkatreddy6251 5 років тому +1

    Hello Sir, if i create String s=new String("SVREDDY"); how many objects will create in memory.

    • @unknowncreature5832
      @unknowncreature5832 5 років тому

      2

    • @shankars4281
      @shankars4281 4 роки тому

      2. One in heap and one in string pool. If this string already exists in string pool, it will not create new one.

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

    navin sir are u able to speak telugu language??

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

    Does it mean that if we create String object using 'new' keyword then it doesn't make any entry in Stack memory?
    Please clarify this..

  • @Muthuvlog104
    @Muthuvlog104 4 роки тому

    Hi Navin,
    Can you explain the difference between primitive datatype int and String .
    as i see both works the same way except the fact they hold different content

    • @gavravdhongadi9824
      @gavravdhongadi9824 4 роки тому

      Both are not the same, int is a data type and String is class

    • @Muthuvlog104
      @Muthuvlog104 4 роки тому

      @@gavravdhongadi9824 okay.. but the way they both store seems same.. except the fact one stores in stack and the other in heap.
      So got the qn

    • @titasdey
      @titasdey 4 роки тому

      @@gavravdhongadi9824 int is a struct.

    • @theblindprogrammer
      @theblindprogrammer 4 роки тому

      int does not have methods, you can't find a size of an int primitive for example.
      String, however, has methods.

  • @komalpare2019
    @komalpare2019 4 роки тому +1

    I have some doubts in string immutablity

  • @jackyoga
    @jackyoga 6 років тому

    Hi Navin, first of all thanks for this video but need more explanation on this topic. As string literal and new String both are creating immutable then what's difference , why we really need to use new String if String literal is creating immutable object?

    • @harrypotter-el4lx
      @harrypotter-el4lx 3 роки тому

      I think new string has some additional functionalities which string literal does not have like integer wrapper class has parseInt ect .

  • @akhilsai9533
    @akhilsai9533 5 років тому +2

    there is no app found???
    in play store

  • @harshkumrawat9917
    @harshkumrawat9917 7 років тому

    Sir can u pls make a video on immutable and mutable objects I got this question in interview

  • @RahulKumar-w9j9q
    @RahulKumar-w9j9q 11 місяців тому

    what will happen in the below case
    String s1= "Navi";
    s1+="n";
    String s2 = "Navin";
    Will s1 and s2 be sharing same reference or different. If it is different, does it mean + operator creating new Object in the heap.

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

    great sir

  • @vivekpandey6979
    @vivekpandey6979 5 років тому

    salute you sir...love u

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

    Can we take a string array without initialization nd then give inputs nd then calculate it's length?

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

    okay. reference changed in stack(str 101 to 103) then now str is 103 . 103 is reddy. then it is changed so , how it is immutable in your explanation

  • @vivekpandey6979
    @vivekpandey6979 5 років тому

    what happen to string "navin" is it accssesible or it goes in garbage???

  • @vasukannan.s7423
    @vasukannan.s7423 4 роки тому

    In above video, if i did not create another variable "str1", then i changed the"str = reddy" mean,, how can i access the "navin"

  • @joshi98kishan
    @joshi98kishan 6 років тому

    How string immutability boost the performance of a system?

  • @rakeshanand2008
    @rakeshanand2008 6 років тому

    What is synchronized & non-synchronized in java? For e.g Array List is not synchronized.

    • @prathameshbagekari7966
      @prathameshbagekari7966 5 років тому

      Synchronized basically means thread-safe. A synchronized method or datatype is the one which will function as expected in cases of execution of multiple threads at a time. Now you'll ask that, then why there are non-synchronized methods. So, remember that non synchronized ones are faster than the synchronized ones. So when you know that your program does not involve multithreading, you can be sure to use a non-synchronized method or datatype..

  • @gurudakshin6420
    @gurudakshin6420 5 років тому +1

    Lets say If I hv millions of text values are there. Don't you think it will create an hotspot in memory??

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

    thank you

  • @navyasri5602
    @navyasri5602 6 років тому +1

    How string is secure???

  • @urmilapatil1643
    @urmilapatil1643 4 роки тому +1

    If str1="hello" ;str2="hi";str1=str1+str2;sop(str1);what's the output?

    • @satishkavre7197
      @satishkavre7197 4 роки тому

      Wrong questions Urmila patil mam pls check ur questions first

    • @AbhishekSingh-rc1st
      @AbhishekSingh-rc1st 4 роки тому

      @Satish Kavre why you said question is wrong ,i think output will be hellohi

    • @satishkavre7197
      @satishkavre7197 4 роки тому

      @abhishek singh I think u don't know if value of variables is same but there reference must be different

    • @AbhishekSingh-rc1st
      @AbhishekSingh-rc1st 4 роки тому

      @Satish Kavre bt here in question neither value nor reference are same.str1 and str2 both different references and point to different addresses ,we concatenate both and put the result in str1.
      Try to dry run the code!

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

      @@AbhishekSingh-rc1st I think string is immutable Nd how can the value of str1 be changed? Am I wrong ?

  • @rakeshanand2008
    @rakeshanand2008 6 років тому

    What is the difference between
    main(String args[ ]) , main(String[ ] args) & main(String [args]) ?

    • @theblindprogrammer
      @theblindprogrammer 4 роки тому +1

      There is no difference between this two:
      public static void main(String args[]){....}
      public static void main(String[] args ){....}
      you can even change the name of "args", you can write like this if you want to.
      public static void main(String mike[]){...}
      This is not correct, however: public static void main(String [args]){}

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

    I was looking for a job since last month or
    I had been looking for a job from last two months. Hope that advertising girl in the end doesn't make any grammar mistakes next time.

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

    this is my interview question we cant manipulate string but we can assign a new value

  • @vikrantthakkar4493
    @vikrantthakkar4493 6 років тому

    Please explain that how the system knows or find to duplicate values assign to string in heap memmory

    • @devangikacha1477
      @devangikacha1477 5 років тому

      I searched this... Compiler will create list of all string literals at compile time with their respective address

  • @roadsideHeropanti9589
    @roadsideHeropanti9589 7 років тому

    sir would i like to improve your app...so plz give me Chance... I have 2 plus experience in android....just bcz it's Helpfull for students

  • @maheshpanchakarla5094
    @maheshpanchakarla5094 5 років тому

    Why " String " is not colored in java in eclipse editor....?

    • @Basitify
      @Basitify 5 років тому

      I might be wrong but I don't thing "String" is colored in any IDE because it is a non-primitive data type and a Class and most IDEs either have primitive data types or keywords as colored

  • @satishchadokar
    @satishchadokar 5 років тому +1

    This is not y ans can u give ans of why string is immutable not his benefits

  • @munaswamy6595
    @munaswamy6595 5 років тому

    How new string ("Naveen'); use string pool value explain

  • @srinathk1322
    @srinathk1322 5 років тому +2

    when declaring string like this
    String str="navin";
    whether str is an variable or an object

  • @harithaarumugam1357
    @harithaarumugam1357 4 роки тому

    public class Example {
    public static void main (String[] args) {
    stringMatch("Haritha","Haritha");
    }
    public static int stringMatch(String a, String b) {
    int len = Math.min(a.length(), b.length());
    for (int i=0;i

  • @arveersingh9728
    @arveersingh9728 8 років тому +2

    what is the difference between String str="abc"; and String str=new String("abc"),is it only that the later uses heap memory and the former does not?

    • @ArjunSingh-qt5jn
      @ArjunSingh-qt5jn 8 років тому

      both are same bro , infact both give you a reference variable of type str pointing to the string object that is "abc" both do same work with new or without it.

    • @subrahmanyampenkey1126
      @subrahmanyampenkey1126 8 років тому +7

      Main difference is when you create String str="abc"; it will create "abc" object in the String pool. but when you create String str = new String("abc"); it will create two objects one in String pool as "abc" and one in heap memory as (new String("abc"); this new String("abc") again its refers to the object "abc" in the string pool. that's why output will be the same for both the cases.

    • @1234jackist
      @1234jackist 7 років тому

      First one will be stored in code memory and 2nd one in heap

    • @Malone-vq2ft
      @Malone-vq2ft 7 років тому

      Based on what is explained, is there a difference? String str="abc"; creates an object in String Pool and returns a memory address to a reference. String str=new String("abc") creates an object in the Heap, but what kind of object it is, if it is holding only a memory address from the Heap ? Can you kindly explain? Thank you

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

    I have one doubt please fix it sir
    String s1="super"
    String s2="cat"
    S1=s1+s2
    Is this immutable object

  • @prasadligade353
    @prasadligade353 6 років тому

    it would be better if you structure - I was not sure if you were explaining immutable or mutable.

  • @ramanajeyachandran9622
    @ramanajeyachandran9622 6 років тому

    If I ignore the str1 obj then how will the memory allocation happen

  • @oopsididitagain8572
    @oopsididitagain8572 5 років тому

    thanks

  • @PramodSubramanyam10
    @PramodSubramanyam10 7 років тому

    Sir u forgot to teach about constant pool and non constant pool...

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

    This is incomplete.Why didnt you tell how to make a class immutable?

  • @arunkumar-tz1di
    @arunkumar-tz1di 7 років тому

    string n=new string("arun");
    string n1=new string("arun");
    how many objects is created

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

    still watchin in 2022

  • @ajaykumarpradhan2239
    @ajaykumarpradhan2239 4 роки тому

    Wrong,Sir the new keyword will create object in heap area and String literal not equal or point to the String object

  • @Lucky-uz3je
    @Lucky-uz3je 5 років тому

    Correct explanation, copied from below comment. Please refer this for String object creation with new keyword.
    whenever we create string using new keyword it will never pointing to string pool it will create new string in heap .if u want to put that value into sting pool there is a method called intern().
    Please pin this answer to understand people correctly.
    String myString = new String( "old String" );
    String myCache = myString;
    System.out.println( "equal: " + myString.equals( myCache ) );
    System.out.println( "same: " + ( myString == myCache ) );
    output:
    equal: true
    same: true
    String myString = new String( "old String" );
    String myCache = myString.intern();
    System.out.println( "equal: " + myString.equals( myCache ) );
    System.out.println( "same: " + ( myString == myCache ) );
    output:
    equal: true
    same: false

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

    You don't explain in detail when we create two string with new keyword then why there address are same and equels to return false

  • @sunnylohana645
    @sunnylohana645 8 років тому

    String str="Navin";
    str="Reddy";
    In this case String object (Navin) will be replaced By Reddy Or it will exist?

    • @subrahmanyampenkey1126
      @subrahmanyampenkey1126 8 років тому

      Both the objects "Navin" and "Reddy" exits in the string pool.when ever you assign str = "Reddy" its just map the str reference to "Reddy" object it won't delete "Navin" object from string pool.lets assume if you create a one more new reference variable as str1="Navin". it will not create "Navin" again its just find the "Navin" object in the string pool if its there its simply maps that reference to str1.

    • @ArunraajSingh
      @ArunraajSingh 7 років тому

      Does string object in Heap hold the reference of the object in String pool as navin said?

  • @manishjha2579
    @manishjha2579 5 років тому

    Sir how can I class learn tupple and array?

    • @theblindprogrammer
      @theblindprogrammer 4 роки тому

      // an array
      1)
      String[] names = {"Bob", "John", "Mike"};
      2)
      String[] names = new String[3];
      names[0] = new String("Bob");
      names[1] = new String("John");
      names[2] = new String("Alex");

  • @janossztrapal6948
    @janossztrapal6948 6 років тому +1

    gr8 m8

  • @nomadicbanda
    @nomadicbanda 5 років тому

    String s1 = "Hello";
    String s2 = "Hello";
    String s3 = new String ("Hello Java");
    String s4 = new String("Hello Java");
    How many objects will be created in this lines..?

    • @abhimanyurathore7185
      @abhimanyurathore7185 5 років тому

      Hi, Mahesh Meena
      I am also a beginner.
      But 3 will be my guess.
      //
      sop(a==b); //true
      Sop(a.equals(b));//true
      Sop(a.equals(c));//true
      Sop(a==c);//false
      Sop(c==d);//false
      Sop(c.equals(d));//true

    • @hectorflores1176
      @hectorflores1176 5 років тому

      Try it by your own is simple. Print in console the hashCode of each string.
      System.out.println(s1.hashCode());
      System.out.println(s2.hashCode());
      System.out.println(s3.hashCode());
      System.out.println(s4.hashCode());
      The output is:
      69609650
      69609650
      387417328
      387417328

    • @armpap1
      @armpap1 5 років тому

      The answer is 6, and hash codes will be equal if the values are equal, but it doesnt mean that those stored in the same object, two objects in different places in the heap can have the same value.