Loading…
Loading…
Topic
Articles and problems tagged Streams and Functional Java.
Reading and writing files for the OCP 21 exam: read and write loops that return -1, buffers and the read count, flush, BufferedReader.readLine, PrintWriter, append mode, Files.readString, readAllBytes, readAllLines versus lines, newBufferedReader and open options.
The java.io stream family for the OCP 21 exam: byte versus character streams, character encodings and Charset, input versus output, low-level versus high-level streams and wrapping, the four abstract base classes, legal and illegal combinations, and decoding class names.
Parallel streams for the OCP 21 exam: parallel() and parallelStream(), the common fork/join pool, forEach versus forEachOrdered, findAny and findFirst, reduce rules for identity and associativity, concurrent collectors, stateful lambdas and ThreadLocalRandom.
The Collectors class for the OCP 21 exam: joining, averaging, summing, counting, toCollection, toList versus Stream.toList, toMap with merge functions and duplicate keys, groupingBy, partitioningBy, mapping, filtering, teeing, plus Spliterator and how a stream sees later changes to its source.
Primitive streams for the OCP 21 exam: IntStream, LongStream and DoubleStream, range and rangeClosed, sum, average, min and max, OptionalInt, OptionalLong and OptionalDouble, mapping between every stream type and the functional interfaces involved, boxed, and summaryStatistics.
Stream intermediate operations for the OCP 21 exam: filter, distinct, limit, skip, map, flatMap, concat, sorted with and without a Comparator, peek, takeWhile and dropWhile, how chained operations run, why sorted hangs on infinite streams, side effects, and checked exceptions in lambdas.
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.
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.
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.
Encrypting data with javax.crypto.Cipher: AES, why ECB and unauthenticated modes are dangerous, PKCS #5 padding, AES-GCM with nonces and associated data, ChaCha20-Poly1305, generating and wrapping keys, SecureRandom, and encrypting files with cipher streams.
Process large XML documents without building a tree: SAX callbacks with DefaultHandler, startElement, characters and endElement, StAX pull parsing with XMLStreamReader and XMLEventReader, getElementText, skipping subtrees, filters, factory properties and safe settings.
Visit directory contents in Java: Files.list for direct children, Files.walk and find for whole trees, glob and regex patterns with PathMatcher, filtered DirectoryStreams, walkFileTree with SimpleFileVisitor, and recipes for copying and deleting directory trees safely.
Read and write ZIP and JAR archives in Java: ZipInputStream and ZipOutputStream entry by entry, STORED entries with CRC32, random access with ZipFile, the ZIP file system provider that makes an archive look like a directory, JarOutputStream manifests, and protecting extraction against zip slip.
Combine Java I/O stream filters: why FileInputStream and DataInputStream have separate jobs, layering DataInputStream over BufferedInputStream over FileInputStream, what buffering saves, PushbackInputStream, append mode, compression filters and writing your own filter.
Start with Java I/O: InputStream and OutputStream, read returning -1, readAllBytes, readNBytes, skipNBytes, transferTo, mark and reset, closing and flushing with try-with-resources, the byte and character class hierarchies, and the Closeable, Flushable, Readable and Appendable interfaces.