In this tutorial, we will learn 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 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.That’s 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 the index ( string index) and we all know that the index starts from zero (0).

========

From the previous tutorial:-

We have discussed in the last tutorial What is string in java and we got some fundamental on the below stuffs.In case you missed out you can watch that in the below link

https://youtu.be/ZOnnNyJrCdQ

so there are two different ways by what we can represent a string in java and they are :

creating a string by using new keyword
creating a string with literal (known as string literals in java)

( by using above two ways we can create a string object in java )

So, string class in java present inside java lang package and comes with some special feature like immutability.In my coming tutorials, we will learn in depth that
why string is immutable in java.

string definition in java can be represented by the statement below :

A sequence of characters or a group of characters is known as string.

We can represent sequence of characters or group of characters by using 4 different ways in java and they are

1.String(java string api)
2.StringBuffer
3.StringBuilder
4.Array

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

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

String Object Creation in Java: Introducing String Constant Pool
1.05 GEEK