BufferedReader br = new BufferedReader(new FileReader("file.txt"));
String line = br.readLine();
// No br.close() – this causes resource leaks!
try (BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
String line = br.readLine();
}
String name = getName(); //could return null
System.out.println(name.toUpperCase()); // NullPointerException
Optional name = getNameOptional();
name.ifPresent(n -> System.out.println(n.toUpperCase()));
List list = new LinkedList<>();
// Doing frequent get(index) – slow with LinkedList
public class Counter {
private int count = 0;
public void increment() {
count++; // Not thread-safe
}
}
private AtomicInteger count = new AtomicInteger(0);
public void increment() {
count.incrementAndGet();
}
May 16, 2025
Java 17 is a long-term support (LTS) release, which means it’s stable and will be supported for years. It introduces some great features that make Java development cleaner and more modern. Here are 5 features that stand out:
May 16, 2025
The Java Collections Framework helps developers manage and organize data. Instead of creating your own data structures, Java provides built-in types like List, Set, Map, etc.