Thursday, June 01, 2006

String Basics

String title = “Java”;
title = “Java Foundations”;

Remember, whenever Java “sees” a new string literal, it creates a new object. What is really happening in the previous two lines of code is as follows:
1. The variable title is declared a String.
2. The new String object “Java” is created in memory.
3. This new String object’s reference is stored in the title variable.
4. The new String object “Java Foundations” is created in memory.
5. The reference to this new String object is stored in the title variable.

0 Comments:

Post a Comment

<< Home