Loading…
Loading…
Language
Articles and problems tagged Java.
How Java's LinkedList and ArrayList work inside, when each one wins, and how to use ListIterator to add, set and remove while you walk a list. Covers fail-fast iterators, ConcurrentModificationException, the get(i) loop trap, and why Vector is obsolete.
A tour of the Java collection interfaces: Collection versus Map, List with random access and the remove(int) trap, Set equality, SortedSet and NavigableSet, the Java 21 SequencedCollection, SequencedSet and SequencedMap, RandomAccess, and an overview of all concrete collection classes.
Start the Java Collections Framework: why interfaces are separate from implementations, the Collection and Iterable interfaces, how iterators work between elements, next, hasNext and remove, forEach, bulk operations, and building your own collection with AbstractCollection.
Learn what reflection can reveal about Java generics despite erasure: the generic Class<T> class, matching Class<T> parameters, the Type interface with TypeVariable, WildcardType, ParameterizedType and GenericArrayType, and type literals (super type tokens) for generic types.
The complete list of Java generics restrictions and their workarounds: no primitives, instanceof only on raw types, no generic arrays, @SafeVarargs, new T() and new T[], static context, generic exceptions, sneaky throws, erasure clashes and record pattern exhaustiveness.
Master Java wildcards: why List<Manager> is not a List<Employee>, how arrays differ, raw-type pitfalls, ? extends for reading, ? super for writing, the PECS rule, Comparable<? super T>, unbounded wildcards and wildcard capture with helper methods.
Understand how Java generics really work: type erasure to raw types and first bounds, the casts the compiler inserts, how generic methods are erased, bridge methods for overriding and covariant returns, calling legacy raw-type code, and generic record patterns.
Learn how to restrict Java type variables with bounds: why <T extends Comparable<T>> lets you call compareTo, why extends is used for interfaces, multiple bounds with &, the class-first rule, bounded generic classes, and the LocalDate surprise.
Learn why Java generics exist and how to use them: type parameters versus Object and casts, defining a generic class like Pair<T>, naming conventions, the diamond operator, generic methods, type inference and how to decode inference errors.
Practical Java debugging tips: useful toString methods, logging proxies, stack traces on demand, capturing stderr, uncaught exception handlers, javac -Xlint, -verbose and -Xlog, and JVM tools like jcmd, jconsole, VisualVM, Java Flight Recorder and Mission Control.
Go deeper into java.util.logging: ConsoleHandler and FileHandler, log file patterns and rotation, handler levels, filters, custom formatters and handlers, the SimpleFormatter format string, LogRecord details, and a practical logging recipe for real applications.
Get started with logging in Java: frontends versus backends, the platform System.Logger API, log levels, lazy messages with suppliers, logging exceptions, MessageFormat placeholders, and configuring java.util.logging with logging.properties and logger hierarchies.
Learn Java assertions: the two forms of the assert statement, enabling them with -ea and -da per class or package, why conditions must have no side effects, when to assert versus throw, preconditions, documenting assumptions, and the ClassLoader assertion API.
Practical Java exception handling best practices: don't use exceptions for control flow, keep try blocks coarse, use precise types, never swallow exceptions, throw early and catch late, validate with Objects methods, and keep stack traces away from users.
Learn how Java's finally clause runs on every path, why return in finally is a trap, how try-with-resources closes AutoCloseable resources in reverse order with suppressed exceptions, and how to read and walk stack traces with StackWalker.
Master catching exceptions in Java: how try/catch changes control flow, when to catch versus propagate, ordering multiple catch clauses, multi-catch with |, unnamed catch variables, and rethrowing, wrapping and chaining exceptions without losing the cause.
Learn how to throw exceptions in Java with the throw statement, pick the right standard exception, write your own checked or unchecked exception classes with the four conventional constructors, and attach extra data and causes.
Start Java exception handling the right way: why exceptions beat error codes, the Throwable hierarchy with Error, Exception and RuntimeException, checked vs unchecked exceptions, declaring exceptions with throws, and the rules for overriding methods that throw.
Learn Java dynamic proxies: when you need classes created at runtime, InvocationHandler and Proxy.newProxyInstance, tracing calls with a proxy, which Object methods are forwarded, invokeDefault for default methods (Java 16), proxy class properties, and real-world uses in frameworks.
Build pluggable Java applications with java.util.ServiceLoader: define a service interface, write providers, register them in META-INF/services or with provides/uses in module-info, iterate lazily, select providers with stream() and Provider.type(), and use findFirst.