So these two String instances here now actually to hold the address of two different objects in memory.
OK.
So these are actually pointers.
This my first name here is actually a pointer to this object in say the memory.
Ok this instance doesn't hold this object within it.
This instance only holds the address of this object inside the memory.
OK.
So hopefully that makes sense now.
So now let me actually comment out these lines of code here and I want to actually show you another
way of creating String objects in Java.
OK.
As you saw above that when we tried to assign the same String object to two different literals compiler
only created one object and made both of the literals to point the same object.
OK so now I want to actually show you how we can actually create String objects in an other way.
And in that case the compiler would create two different objects in memory having the same text.
So for example First we need to actually refer to the name of our class Stream.
And the name of our object is for example C Our object one.
And then I need to put in an assignment operator here.
And then I need to put in this key here new.
And then again I need to refer to the name of constraint.
OK.
And then I need to put in a semicolon at the end of my statement.
So as you can see here I created a string object called C R object 1.
OK.
As you can see I can actually assign value to this as an object one inside the practice's here.
OK.
So this is a constructor in string class that allows us to actually assign value to our string instances.
OK so I can actually just type in here.
Hello world.
OK.
And now as you can see I created an object called Hello world.
OK so now I can actually create another object here.
I just need to refer to the name of the class 3.
OK.
And the name of the object is Esti are object to.
OK.
And then I need to put in an assignment operator here and then I put in this key word here new.
And then I again refer to the name of the String class and then I put in Apprentice's here and then
I put in a semicolon at the end of my statement.
And now I can actually assign a value to our it's art object to by using a constructor that is inside
the as three in class.
OK so remember that a string class is a predefined class for us those constructors are pre-defined for
us and we can use them.
So inside the prentices I just need to put in two double quotes and then instead of double quotes again
I can just type in Hello world.
So as you can see here I created two different strange instances with the same value but the this time
the address of these two objects is going to be completely different inside the memory.
OK.
So this object is going to be saved inside the memory in one place and in and this object is going to
be actually saved inside the memory in another place.
OK that's it that's how you can actually create a string object in Java.
And now I want to actually talk more about these string objects in order to make this concept more meaningful
for you.
OK so now if I want to output the value of these string instances to the console I just need to type
in here system that out that princeling and that inside the prentices I can just refer to the name of
the object as the object one.
And then I need to put in a semi-colon at the end of my statement.
So now if I had on my project as you can see this value is output to the counselor OK or I can actually
output the value of this SDR object to the console.
So I just need to type in here sees them that out that print to learn and then inside the parenthesis
I can just refer to the name of my object.
OK.
As the object to and that I need to put in a semicolon at the end of my statement.
And now if I start my project as you can see this value again is output to the console OK.
And remember that these two objects are actually stored in memory in two different places.
OK because we created these string objects by using these new key word here.
OK.
So this is really important.
You can actually create String objects by just using these string literals or you can actually create
string objects by using this new keyboard here.
OK.
So to recap strings are a sequence of characters.
OK.
In Java programming language strings are objects and the Java platform provides string class to create
and manipulate strings.
So in order to create strings the most direct way to create a stream is to actually use the string literals.
OK so for example let me actually comment out these lines of code here and I need to refer to the name
of the string class the name of my object is Esti are one.
And that I put in an assignment operator here.
And then I can actually put into double quotes and here I can.
Just putting a value here.
OK.
Inside the double quotes and then I need to put in a semicolon at the end of my statement.
OK.
So here as you can see this is the most direct way to create a strange.
OK.
Whenever the compiler encounters a string literal in your code it creates a string object with its value.
In this case OK with its value in this case of value.
OK.
As with any other object you can create String objects by using the new keyboard and a constructor which
I actually showed you two examples earlier in this tutorial.
The string class has 11 constructors that allow you to provide the initial value of this string using
different sources.
Distraint class is immutable so that once it is created a string object cannot be changed.
If there is a necessity to make a lot of modifications to strings of characters who can actually use
the string buffer class or the string to be the class OK.
And now I want to actually show you some of the effects of a strange class in order to manipulate these
string objects.
OK.
Methods used to obtain information about an object are known as accessor methods.
OK one access and method that you can use with strings is the length method.
So let me repeat again methods used to obtain information about an object are known as accessor methods.
One access in my faith that you can use with strings is the method which returns the number of characters
contained in these in the string object.
And now I want to actually show you those examples here.
OK so now as you can see here in line 26 I created a string object and the name of my object is a string.
One Esti are one.
OK so now I want to actually create an integer value but in order to actually hold the length of this
string object.
OK so now.
So the data type of my variable is int and the name of my variable is as thrain Len.
OK.
And then I need to put in an assignment operator here.
And then I refer to the name of my object t r want that Len.
As you can see here this little method is an accessible method.
OK so an Access and method means that this method is actually going to obtain information about this
object.
OK.
So the name of this method is Len.
And the return type of this method is int and this method is inside the stream class.
OK so if I choose this method now and I need to put in a semicolon at the end of my method.
So this is Thring less valuable.
Now holds the length of ds s t r one object.
OK.
And now if you want to output this value to the console.
I just need to type in here a system that's out that princeling and an inside the apprentice's I just
need to refer to the name of my valuable as string string length.
OK so now I need to choose this option here.
String length.
And then I need to put in a semi-colon at the end of my statement.
So now if I add on my project as you can see this value is output to the consulate number 7.
So if you actually count the length of this string here as you can see one two three four five six seven.
OK so this value is the value of the string length variable.
Ok so this is the length of our string object.
OK.
And another method that we can use on String objects is.
For example let me actually comment out of this line of code here.