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(),
total three objects are getting created,2 in the heap area and one inside the string pool.and each string reference will point to their individual object which is inside java heap area.

we will learn more about it as go ahead with this tutorial.This is one of the most asked string interview questions when the topic comes to java.lang.string.You might also except some questions like “explain string constant pool vs heap in java “.So let’s learn string constant pool memory location in depth with this tutorial.

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

THIS IS THE LINK TO THE PREVIOUS TUTORIAL : -

https://youtu.be/WQfCYBJU2gg

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 :

two string objects are created.one in the heap memory one in the string pool or inside the string constant pool.
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:
https://www.facebook.com/seleniumexpress/

Music :

credits : -

Adventures by A Himitsu https://soundcloud.com/a-himitsu
Creative Commons — Attribution 3.0 Unported— CC BY 3.0
http://creativecommons.org/licenses/b
Music released by Argofox https://youtu.be/8BXNwnxaVQE
Music provided by Audio Library https://youtu.be/MkNeIUgNPQ8


intro template :
wwww.youtube.com/Alexbau01

#java.lang.string #java

String Object Creation Behind The Scenes || String Constant Pool  ||  Java.lang.String
1.15 GEEK