ProLesson 3.1Beginner2 min readUpdated 30 October 2026
String basics and immutability
Create and combine Strings, understand why a String can never change, and see what that means for your code.
A String is a piece of text: a name, an email, a whole paragraph. It's the most used class in Java, and one idea explains most String questions in interviews: a String can never change once it's created.
01Creating Strings
StringCreate.java
public class StringCreate {
public static void main(String[] args) {
String first = "Asha"; // string literal (most common)
String last = new String("Rao"); // explicit object (rarely needed)
String full = first + " " + last; // concatenation with +
System.out.println(full);
System.out.println(full.length());
System.out.println("Total: " + 2 + 3); // left to right: "Total: 2" + 3
System.out.println(2 + 3 + " items"); // 5 + " items"
}
}Asha Rao 8 Total: 23 5 items
Loading the rest of the lesson…