Bifalgorithm post · Computer science one · Basics

How are String variables declared and reassigned in Java?

How are String variables declared and reassigned in Java? (Computer science one · Basics) — "We can declare String variables and assign them values using the r…

Ideas in this flowchart

  • String variables can be declared, assigned, and reassigned.
  • String variables receive values using the regular assignment operator.
  • Initial string assignments
  • String firstName = "Thomas";
  • String lastName = "Waits";
  • A variable can be assigned a new string value.
  • firstName = "Tom";
  • Reassignment does not change the original string.
  • The variable firstName points to a new string.
  • If no other references point to the old string
  • The old string becomes eligible for garbage collection.
  • The JVM takes care of garbage collection.
Feed/

How are String variables declared and reassigned in Java?

No cover

Channel

Computer science one

1 page

"We can declare String variables and assign them values using the regular assignment operator.\n\n1 String firstName = \"Thomas\";\n\n2 String lastName = \"Waits\";\n\n3 4 //we can also reassign values\n\n5 firstName = \"Tom\";\n\nNote that the reassignment in the last line in the example does not change the original string. It just makes the variable firstName point to a new string. If there are no other references to the old string, it becomes eligible for garbage collection and the JVM takes care of it."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.