This project demonstrates how Java handles String variables and references. It explores the concept of object assignment and string immutability by creating a copy of a variable and modifying it independently.
Create a copy of the project name to make changes to it.
- Declare a
StringvariableprojectNamewith the value"Java". - Declare another
StringvariablenewProjectNameand assign it the value ofprojectName. - Change the value of
newProjectNameto"Java Programming". - Output both variables to verify if the original
projectNameremains unchanged.
In Java, String objects are immutable.
- When
newProjectNameis assigned the value ofprojectName, both variables point to the same object in the String Pool. - However, when
newProjectNameis updated to"Java Programming", Java creates a new String object. - The original
projectNamevariable continues to point to the original"Java"object, ensuring data integrity.
- Language: Java 23
- IDE: IntelliJ IDEA
- Concepts: String Pool, Immutability, Variable References.
The code follows Java naming conventions and clean code principles:
package com.yurii.pavlenko;
public class Task_6_App {
public static void main(String[] args) {
String projectName = "Java";
String newProjectName = projectName;
newProjectName = "Java Programming";
System.out.println("Original Project Name: " + projectName);
System.out.println("New Project Name: " + newProjectName);
}
}This project is licensed under the MIT License.
Copyright (c) 2026 Yurii Pavlenko
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files...
License: MIT