Loading…
Loading…
Language
Articles and problems tagged Java.
Stream terminal operations for the OCP 21 exam: count, min and max with a Comparator, findFirst and findAny, anyMatch, allMatch and noneMatch, forEach, the three reduce signatures, collect with a supplier, accumulator and combiner, toList and toArray, and which ones finish on infinite streams.
Stream pipelines for the OCP 21 exam: source, intermediate and terminal operations, lazy evaluation and single use, creating streams with Stream.of, ofNullable, collection.stream, Arrays.stream, generate and both forms of iterate, plus parallel streams and the late-binding source.
Optional for the OCP 21 exam: creating with of, ofNullable and empty, checking with isPresent and isEmpty, unwrapping with get, orElse, orElseGet and orElseThrow, ifPresent and ifPresentOrElse, and chaining map, filter, flatMap, or and stream.
Generic wildcards for the OCP 21 exam: why List<String> isn't a List<Object>, unbounded ?, upper-bounded ? extends and lower-bounded ? super, what you can read and add through each, PECS, List<?> versus var, and the tricky declarations the exam uses.
Generics for the OCP 21 exam: declaring generic classes, interfaces and records, type parameter naming, type erasure and its limits, overloading and overriding with generic types, generic methods and explicit type arguments, shadowed type parameters, and bounded type parameters.
Java 21 sequenced collections for the OCP exam: getFirst, addLast, removeFirst and reversed on SequencedCollection, SequencedSet and SequencedMap methods, sequenced versus sorted, which classes qualify, unmodifiable views, and a review table of every collection type.
Sorting for the OCP 21 exam: writing compareTo with Comparable, building Comparator objects with lambdas, comparing, thenComparing and reversed, Collections.sort versus List.sort, binarySearch return values, and why TreeSet fails at run time without an order.
Maps for the OCP 21 exam: HashMap, LinkedHashMap and TreeMap ordering, Map.of, ofEntries and copyOf, get, getOrDefault, put, putIfAbsent, replace, replaceAll, forEach and entrySet, plus the exact null rules of merge, compute, computeIfAbsent and computeIfPresent.
Sets, queues and deques for the OCP 21 exam: HashSet, LinkedHashSet and TreeSet ordering, Set.of and Set.copyOf, null and Comparable rules, Queue methods that throw versus return null, Deque methods at both ends, stacks with push, pop and peek, and ArrayDeque versus LinkedList.
Lists for the OCP 21 exam: ArrayList versus LinkedList, Arrays.asList, List.of and List.copyOf, constructors, index-based methods, replaceAll, the overloaded remove trap, indexOf and lastIndexOf, IndexOutOfBoundsException, and converting lists to arrays.
The Java Collections Framework for the OCP 21 exam: List, Set, Queue, Deque and Map, generics with the diamond operator and var, and the Collection methods add, remove, size, isEmpty, clear, contains, removeIf, forEach, iterators, equals and unboxing pitfalls.
Variables and lambdas for the OCP 21 exam: inferring parameter types, var, final and annotations on parameters, consistent parameter formats, locals inside lambda blocks and name clashes, and which instance, static and local variables a lambda body may reference.
Combining functional interfaces for the OCP 21 exam: Predicate and, or, negate and not, Function andThen versus compose, Consumer andThen, identity, then the primitive interfaces for int, long, double and boolean, their renamed methods, and the To and Obj variants.
The core java.util.function interfaces for the OCP 21 exam: Supplier, Consumer, BiConsumer, Predicate, BiPredicate, Function, BiFunction, UnaryOperator and BinaryOperator, their method names, type parameters and return types, how to pick the right one, and common generic mistakes.
Method references for the OCP 21 exam: the :: operator, static, bound and unbound instance method references, constructor and array constructor references, how the target type picks overloads, this:: and super::, ambiguous references, and when a lambda can't be rewritten.
Functional interfaces for the OCP 21 exam: the single abstract method rule, what @FunctionalInterface checks, inherited and merged abstract methods, why default, static and private methods don't count, the Object-method exception, and what can't be a lambda target.
Lambda syntax for the OCP 21 exam: why lambdas replace one-method classes, deferred execution, target typing, the optional parentheses, braces, return and semicolon, valid and invalid forms, var and typed parameters, void-compatible bodies, and why var can't hold a lambda.
Polymorphism for the OCP 21 exam: object type versus reference type, implicit upcasts and explicit downcasts, ClassCastException, casts the compiler rejects (including final, record and sealed types), instanceof patterns, virtual method calls, and hidden fields and static methods.
Local and anonymous classes for the OCP 21 exam: classes inside methods, capturing effectively final locals, outer-instance access, anonymous subclasses and implementations, the trailing semicolon, local records, lambdas versus anonymous classes, and choosing a nested type.
Member-level nested classes for the OCP 21 exam: the four kinds of nested class, inner classes and the outer.new Inner() syntax, Outer.this for shadowed members, static nested classes, nested records, enums and interfaces that are implicitly static, modifiers and generated class files.