Java Strings and Text Blocks: Quotes, Concatenation and parseInt
A String is a row of characters in double quotes; a char is one character in single quotes. Why "1" + "2" is 12, how Integer.parseInt turns "100" into a number, and multi-line text with triple-quote text blocks.
What you will learn
- Tell a char in single quotes from a String in double quotes
- Predict what + does with text, numbers and a mix of both
- Turn text into a number with Integer.parseInt
- Write multi-line text with a text block
Before you start
- Java primitive types and memory
A String is a sequence of characters: messages, names, file paths, any text at all. You'll use one in nearly every program you write.
One character, or many
package org.studyeasy.s02l05;
public class Ex01_CharAndString {
public static void main(String[] args) {
char grade = 'A';
String course = "StudyEasy";
System.out.println(grade);
System.out.println(course);
}
}
A
StudyEasy
char holds one character in single quotes. String holds text in double quotes. Write char grade = "A"; and javac says a String cannot be converted to char. The quotes matter.
The plus sign has two jobs
+ is an overloaded operator: it does different work depending on what's on each side. Numbers on both sides, it adds. Text on either side, it joins.
package org.studyeasy.s02l05;
public class Ex02_Concat {
public static void main(String[] args) {
String brand = "study" + "easy";
System.out.println(brand);
System.out.println("Score: " + 87);
System.out.println(1 + 2);
System.out.println("1" + "2");
}
}
studyeasy
Score: 87
3
12
"study" + "easy"joins intostudyeasy."Score: " + 87: text plus a number gives text. The 87 is joined on.1 + 2is maths: 3."1" + "2"is text: 12.
Only + works this way. "study" - "easy" doesn't compile: the operator - isn't defined for String.
Turn text into a number
package org.studyeasy.s02l05;
public class Ex03_ParseInt {
public static void main(String[] args) {
int quantity = Integer.parseInt("100");
System.out.println(quantity + 20);
System.out.println("100" + 20);
}
}
120
10020
Integer.parseInt("100") takes the text "100" and gives back the number 100, so quantity + 20 is 120. Without parseInt, "100" is still text, and + 20 just sticks 20 on the end: 10020.
Parse something that isn't a number, like "one hundred", and the program stops with a NumberFormatException. That's the situation you'll handle later with try and catch.
The quotes tell Java what you mean
| You write | Type | Meaning |
|---|---|---|
'A' | char | one character |
"A" | String | text that happens to be one character |
"100" | String | text, not a number yet |
100 | int | a real number you can do maths with |
Multi-line text with a text block
package org.studyeasy.s02l05;
public class Ex04_TextBlock {
public static void main(String[] args) {
String oldWay = "Hi Emma,\n" + "Your order is ready.\n" + "Thanks, Jack";
String message = """
Hi Emma,
Your order is ready.
Thanks, Jack""";
System.out.println(message);
System.out.println(oldWay.equals(message));
}
}
Hi Emma,
Your order is ready.
Thanks, Jack
true
The old way needs a \n (new line) and a + on every line, and it gets messy fast. A text block opens with triple double quotes, and you type the text as it should look. It keeps your lines. equals prints true: both strings hold exactly the same text; the text block is just easier to write.
One detail: here the closing """ sits right after Thanks, Jack. Put it on its own line and the text gains a trailing new line, so equals prints false.
Common mistakes
char c = "A";: double quotes make a String.- Expecting
"100" + 20to be 120. Parse first. - Parsing text that isn't a number:
NumberFormatException. - Writing
stringwith a small s. The class isString.
Recap
| Idea | Example | Result |
|---|---|---|
| char | 'A' | one character |
| String | "StudyEasy" | a row of characters |
| Join text | "1" + "2" | 12 |
| Add numbers | 1 + 2 | 3 |
| Text to number | Integer.parseInt("100") | 100 |
| Text block | """ ... """ | multi-line text as typed |
Strings have more to them: the string pool, StringBuilder and formatting are covered in Java strings as objects.
StudyEasy AI Community
Learn AI engineering, share what you build, and connect with other learners.
Free resources: lesson files, notebooks and code
Ask questions and join engineering discussions
Meet real people learning and building with AI
Related course on Udemy
FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE
Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)Related posts
Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program
Install JDK 25 (Microsoft Build of OpenJDK) with JAVA_HOME, install IntelliJ IDEA, then point a run configuration at the JDK and the main class and run Hello World.
Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA
Open IntelliJ's AI Chat, pick Claude Agent (the agent behind Claude Code) or Copilot and a model, ask in plain words for Main.java to print the date and time, review the change, and run it.
Java Hello World with Maven: What the JDK Does and What Maven Adds
javac compiles HelloWorld.java into bytecode and java runs it on the JVM. Maven adds one pom.xml, the same folders in every project and one build command. Then a real Maven Hello World in IntelliJ.
Java Variables, Keywords and Naming Rules
A variable is a labelled jar that holds one value at a time. Four small programs show declaring, reassigning, the names Java accepts, the keywords it reserves, and why daysUntilLaunch beats d.
