When any string will be created with new key word like - new String("Java"), then the object will be created in Heap memory not in String Constant Pool.
thanks man, and what happends when you make a System.out.println("var"); where is the "var" created? and what happen when I.E. String c="var"; System.out.println("var"==c); why does it return false?
Scp is used to improve performance suppose we already have a string object with same content then it'll retrieve from scp quickly that's why creating strings with literals i.e String str="hello"; is preferred
-- You need to use intern() of String class. -- using intern() method with String object created using "new" keyword, will return the reference of the exact String object created in SCP area. public class TwoObjectsCreatedProof { public static void main(String[] args) { String s1= new String("Hello"); // 2 objects are created "Heap' and "SCP" area. String s2=s1.intern(); // returns the reference from the SCP area and assigns it to 's2'. System.out.println(s2); // prints "Hello" from SCP area System.out.println(s1==s2); // false } }
How does the Intern method works if creating a string using new creates two objects one in the heap and one in scp. Isn't the whole purpose of intern is to create a copy in scp
Best exaplaintion after watching 10 different videos. Great job man 👏
Cool. Easy to learn java string and string constant pool
Great teaching, concept is very clear,keep doing more
Awesome.. Great teaching Sir 👏👏👏we understand the concept in ur teaching so soon..
Avilash you are great teachers. I am watching all of your video's. The way you explain things direct goes into brain.
Great
Nice explanation bhaiya.you are doing a great job.your english is mind blowing.keep it up.
Perfect practical explanation ! Keep on ...
thanks for making me understand so precisely😊
Super experience
Super , Thankyou
bro can u please do vedeos on java8 features full tutorial mainly java8 streams
super
When any string will be created with new key word like - new String("Java"), then the object will be created in Heap memory not in String Constant Pool.
thanks man, and what happends when you make a System.out.println("var"); where is the "var" created? and what happen when I.E.
String c="var";
System.out.println("var"==c);
why does it return false?
true it will return
@ 17:19 | S1 and S2 are not objects but just data types, Although good explanation.
not data type it reference variable right?
Nice
Thank you abhilash I got the concept clear
In case of String s= new String ("java")- since object is Stored in heap as well, then what role does java in String constant pool play?
Scp is used to improve performance suppose we already have a string object with same content then it'll retrieve from scp quickly that's why creating strings with literals i.e String str="hello"; is preferred
How can you prove that 2 objects will get created (in heap & in Scotland) when we create a String object using new?
-- You need to use intern() of String class.
-- using intern() method with String object created using "new" keyword, will return the reference of the exact String object created in SCP area.
public class TwoObjectsCreatedProof
{
public static void main(String[] args)
{
String s1= new String("Hello"); // 2 objects are created "Heap' and "SCP" area.
String s2=s1.intern();
// returns the reference from the SCP area and assigns it to 's2'.
System.out.println(s2); // prints "Hello" from SCP area
System.out.println(s1==s2); // false
}
}
sen harikasın
String s=new String("java"); here, "java" will not go into string constant pool unless we say intern
can you please explain what is differ b/w final and immutable
if the String pool becomes full -- how JVM will delete or flash the strings from Constant Pooling
How does the Intern method works if creating a string using new creates two objects one in the heap and one in scp. Isn't the whole purpose of intern is to create a copy in scp
if i go for s1.equals(s2) in IF statement then it will gives the output of if statement..how..this possible..?
Because equals method compare content in string class
where is the scp area located in jvm ?
Heap
please remove the background music its irritating and distracting
Sure.. Will keep that in mind. Thanks for letting me know Parikshit.