String object creation behind the scenes || string constant pool || java.lang.String

preview_player
Показать описание
In this tutorial, we will cover how many objects are created using new string and how many objects are created in string using “ “ in java with a complete working example.

So in java string concept,
if we are creating string in java by using “ “ then only object will be get created inside the string pool and if we try to create more than one object with the same content then no other object will be created inside the string constant pool and no objects will be created inside java heap area as we are not doing any runtime stuff while creating string literal.

So only one object is created using ”” and that is in string constant pool and your string object reference will pointing to that object.(which is inside java string pool )

But when we creating string in java by using new String(),

==============

THIS IS THE LINK TO THE PREVIOUS TUTORIAL : -

In the previous tutorial, we have learned,

how many objects get created when created in string constant pool and in heap area,
when we create a string using new keyword or by using “ “ and also we will see, where the string objects get created in the memory

So let's understand the concept of string memory allocation in java -

So in the first case which is by using the new keyword to create a string in java :

reason for this is, first the string literal will get created inside the string constant pool and then it will be created inside the heap area as we are
using the new keyword.Thats because by using new keyword we are creating objects in java which is a runtime operation.

but while we try creating string in java by using string literal only one object got created and that is inside string pool.No object got created inside
heap area as no runtime things is happening.

while creating string object in java ,the objects stored in index ( string index) and we all know that the index starts from zero (0).

IF YOU WANT TO UNDERSTAND IT IN MORE DETAILS THEN PLEASE WATCH THIS TUTORIAL BY CLICKING ON THE LINK ABOVE.

=============================

follow us on facebook:

Music :
-----------
credits : -

Creative Commons — Attribution 3.0 Unported— CC BY 3.0

-----

intro template :
Рекомендации по теме
Комментарии
Автор

Cool. Easy to learn java string and string constant pool

hemantvc
Автор

Best exaplaintion after watching 10 different videos. Great job man 👏

aricaacharya
Автор

Great teaching, concept is very clear, keep doing more

giridatta
Автор

This is late, but really good job explaining this.

michaelhall
Автор

Awesome.. Great teaching Sir 👏👏👏we understand the concept in ur teaching so soon..

abdulshaik
Автор

Avilash you are great teachers. I am watching all of your video's. The way you explain things direct goes into brain.

pujabansal
Автор

Nice explanation bhaiya.you are doing a great job.your english is mind blowing.keep it up.

nainatiwari
Автор

Perfect practical explanation ! Keep on ...

vladanulardzic
Автор

thanks for making me understand so precisely😊

rishitamathur
Автор

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.

swagatkumarsahu
Автор

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?

AlfonsoMonroyIV
Автор

@ 17:19 | S1 and S2 are not objects but just data types, Although good explanation.

annusunny
Автор

How can you prove that 2 objects will get created (in heap & in Scotland) when we create a String object using new?

subbub
Автор

bro can u please do vedeos on java8 features full tutorial mainly java8 streams

hariindia
Автор

if the String pool becomes full -- how JVM will delete or flash the strings from Constant Pooling

JohnWick-zcli
Автор

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?

asthagarg
Автор

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

bipinesh
Автор

String s=new String("java"); here, "java" will not go into string constant pool unless we say intern

nar
Автор

if i go for s1.equals(s2) in IF statement then it will gives the output of if statement..how..this possible..?

nareshbarik
Автор

Thank you abhilash I got the concept clear

ashishbarik
welcome to shbcf.ru