Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com

Initially we have two java.lang.Strings, or rather, two instances of java.lang.String, that we refer to by struno and strdue .

They're shown first ..

..in our own method showum.

First click, String's toUpperCase method is called. This however does NOT change the string value, as you would expect.

At the second click we store the reference to the NEW String that toUpperCase returns.

Now, the old String that strdue previously referred to, "We perceive time" , still exists, but it is marked to disappear, it is marked for 'garbage collection'.

Clicking again results in both reference variables struno and strdue referring to the same string, "STRING ALONG".

"String along" has been marked to disappear.

=========

NOTES

=========

The term 'garbage collection' is used to describe the process of freeing up memory that's taken by instances to which there are no more references.

This is an automatic background process in Java, that may do its job if it decides to.

=========

To mark objects for garbage collection .

And to request the garbage collector to free up memory. If the request is granted, the program stalls and continues only after garbage collection is finished. Keep it mind that it's a REQUEST, nothing more, no guarantees.

=========

The java.lang import is unnecessary, it's always assumed.

=========

After three clicks the button is disabled.

.