How do you avoid deadlock in Java applications?
Deadlock needs a cycle of threads holding locks. Learn lock ordering, tryLock timeouts, concurrent utilities and how to detect deadlocks with jstack.
2,889 posts about Java: questions with answers, tutorials and articles, newest first.
Deadlock needs a cycle of threads holding locks. Learn lock ordering, tryLock timeouts, concurrent utilities and how to detect deadlocks with jstack.
Runnable models a task as one void run() method. See how to use it with threads, executors and virtual threads, and when to prefer Callable.
Learn how to make a Java class thread-safe using immutability, locks, atomic classes and concurrent collections, with tested examples.
Compare Java singleton implementations: eager, lazy, double-checked locking, Bill Pugh holder and enum, with thread safety and serialization notes.
A singleton restricts a class to one instance. Compare eager, holder, double-checked locking and enum implementations, and see how to keep them thread safe.
An anonymous class is a nameless class declared and created in one expression. Learn its syntax, limits and how it compares with lambdas.
Declare a class inside another class, with or without static. This guide covers static nested, inner, local and anonymous classes and when to use each.
Abstract classes share state and code along one inheritance line, while interfaces define capabilities. See the differences with modern Java examples.
Use implements to apply an interface in Java, combine several interfaces, share behaviour with default methods, and restrict implementers with sealed types.
An abstract class in Java is a base class that cannot be instantiated and may declare abstract methods for subclasses to implement. See syntax, rules and examples.
The this keyword refers to the current object in Java. See how to use it for fields, constructor chaining, fluent methods and inner classes.
Learn what super does in Java: calling parent constructors, reusing overridden methods, reading hidden fields and resolving default method conflicts.
Declare a Java constructor with the class name and no return type, then learn default constructors, overloading, chaining with this and super, and records.
Constructor overloading gives a Java class several constructors with different parameter lists. Learn the rules, chaining with this(), and when to use factories.
Method overloading lets a Java class declare several methods with one name and different parameter lists. See the rules, resolution order and common pitfalls.
A practical guide to Java lambdas with collections, covering forEach, removeIf, sort, Map methods and stream pipelines with modern Java 16+ examples.
A Java lambda expression is a short anonymous function written as (parameters) -> body. See the syntax, functional interfaces, streams and capture rules.
A functional interface has exactly one abstract method and is the target for lambdas and method references. Learn the rules, built-in types and composition.
instanceof tests an object's runtime type in Java. See pattern matching since Java 16, null behavior and when to avoid long instanceof chains.
Use getDeclaredConstructor().newInstance() to build objects from a Class at runtime. Covers arguments, private constructors, exceptions and alternatives.