Hi,
I've just started learning Java.
I've been told String is not a primitive data type but actually an object of class String.
OK I can accept this, however, in the OO forum I have been told
and then change its content
You haven't changed the state of the String object, but it's actually created a new object with the new content.
I'm confused. I thought Objects by defenition have a state and always have accessor methods to alter and interigate its state as well as other methods which make up it's protocol.
If this is not what happens with a string, how can it be an object?
I have read that Java is the ONLY true OO language from the ground up , so was wondering if perhaps, this isn't the case with Java.
All help understanding, what a string actualy is if it isn't an object and also what happens to the memory references to the other objects when the string is altered is much appreciated.
Regards,
1DMF.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
I've just started learning Java.
I've been told String is not a primitive data type but actually an object of class String.
OK I can accept this, however, in the OO forum I have been told
So when you create a stringstrings are immutable.
Code:
String myName = "Bob";
and then change its content
Code:
myName = "John";
You haven't changed the state of the String object, but it's actually created a new object with the new content.
I'm confused. I thought Objects by defenition have a state and always have accessor methods to alter and interigate its state as well as other methods which make up it's protocol.
If this is not what happens with a string, how can it be an object?
I have read that Java is the ONLY true OO language from the ground up , so was wondering if perhaps, this isn't the case with Java.
All help understanding, what a string actualy is if it isn't an object and also what happens to the memory references to the other objects when the string is altered is much appreciated.
Regards,
1DMF.
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!