9) Strings & I/O
Goal
Work with strings safely and do basic file input/output.
Strings
String is immutable.
- Prefer
StringBuilder for repeated concatenation in loops.
var sb = new StringBuilder();
for (int i = 0; i < 3; i++) {
sb.append(i).append(",");
}
System.out.println(sb);
Files (NIO.2)
Path path = Path.of("notes.txt");
Files.writeString(path, "Hello\n");
String text = Files.readString(path);
System.out.println(text);
Exercises
- Read a text file and count lines.
- Given a sentence, count word frequency.
- Implement
isPalindrome(String s) ignoring spaces and case.
Table of contents
- Getting Started: Install, run, and your first program
- Java Basics: types, variables, operators, formatting
- Control Flow: if/switch/loops
- Methods: parameters, return values, overloading
- OOP: classes, objects, encapsulation
- Inheritance & Polymorphism (and when not to use them)
- Interfaces, abstract classes, and design basics
- Exceptions and error handling
- Strings, files, and I/O basics
- Collections: List/Set/Map and Big-O intuition
- Generics (the useful parts)
- Lambdas & Streams
- Dates and time (java.time)
- Testing with JUnit 5 (basics)
- Concurrency: threads, executors, futures
- JVM basics: memory, GC, performance habits
- Build tools: Maven essentials (recommended)
- Next steps: projects to build