Loading…
Loading…
Language
Articles and problems tagged Java.
Control what Java serialization saves: transient fields, private writeObject/readObject hooks with defaultWriteObject, serialPersistentFields with PutField/GetField, Externalizable with its public no-arg constructor, and how records are rebuilt through their canonical constructor.
Read a Java serialization stream byte by byte: the AC ED magic number, TC_ type codes, class descriptors with serialVersionUID fingerprints and flags, field type codes, object handles and back-references, null markers, block data, and what ObjectStreamClass reports.
Save and restore object graphs with Java serialization: ObjectOutputStream.writeObject, ObjectInputStream.readObject, the Serializable marker interface, shared references and serial numbers, non-serializable superclasses, NotSerializableException, and when to avoid it.
Coordinate processes that share a file with Java's FileChannel.lock and tryLock: exclusive and shared locks, locking regions, releasing with try-with-resources, a locked read-modify-write update, OverlappingFileLockException, and the platform caveats such as advisory locks on Linux.
Understand Java NIO buffers: ByteBuffer, CharBuffer and the typed buffers, capacity, position, limit and mark, the fill-flip-drain-compact cycle, absolute versus relative access, wrap, slice, duplicate and typed views, direct buffers, charset encoding, and copying between channels.
Map files into memory in Java with FileChannel.map: READ_ONLY, READ_WRITE and PRIVATE modes, MappedByteBuffer access, force, byte order, measured performance against streams and RandomAccessFile, the 2 GB limit, and Java 22's MemorySegment mapping with deterministic unmapping through an Arena.
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.
Copy, move and delete files with java.nio.file.Files: REPLACE_EXISTING, COPY_ATTRIBUTES and ATOMIC_MOVE, copying to and from streams, delete versus deleteIfExists, exists and isRegularFile checks, size, BasicFileAttributes and PosixFileAttributes, timestamps, symbolic links and isSameFile.
Use java.nio.file.Files for everyday file work: readString, readAllLines, lines and readAllBytes, writeString and write with open options such as APPEND and CREATE_NEW, mismatch, probeContentType, buffered readers and writers, createFile, createDirectory, createDirectories and temporary files.
Work with file system paths using java.nio.file.Path: Path.of, absolute and relative paths, resolve and Java 22's multi-argument resolve, resolveSibling, relativize, normalize, toAbsolutePath, taking paths apart, startsWith, URIs and the legacy File class.
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.
Read and write anywhere in a file with Java's RandomAccessFile: the r, rw, rws and rwd modes, the file pointer, seek, getFilePointer, length and setLength, storing fixed-size records, reading records in any order, updating a record in place, and when FileChannel is the better choice.
Write and read binary data in Java with DataOutputStream and DataInputStream: fixed-size big-endian numbers, readFully and EOFException, unsigned reads, why writeUTF's modified UTF-8 isn't real UTF-8, portable length-prefixed strings, and handling little-endian data with ByteBuffer.
Understand how Java turns characters into bytes: how UTF-8 and UTF-16 encode code points, byte order marks, the Charset class and StandardCharsets, mojibake and strict decoders, UTF-8 as the default since Java 18, file.encoding and the stdout, stderr and stdin encodings, and reading code points.
Read and write text in Java: Files.readString, readAllLines and lines, Scanner tokens and the nextLine trap, BufferedReader, Java 25's Reader.readAllLines, PrintWriter with print, println, printf, autoflush and checkError, and saving records in a delimited text format.
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.
Use Java parallel streams correctly: parallelStream and parallel, why shared mutable state causes race conditions, encounter order and unordered(), groupingByConcurrent, when parallelism pays off, the common ForkJoinPool, running in a custom pool, and random numbers in parallel.
Avoid boxing with Java's IntStream, LongStream and DoubleStream. Create them with of, range, chars, codePoints and random generators, convert with mapToInt and boxed, and use sum, average, max, summaryStatistics and OptionalInt, plus the overflow and floating-point details.
Write your own Java stream gatherers: the initializer, integrator, combiner and finisher, pushing elements downstream, Gatherer.of versus ofSequential, greedy versus short-circuiting integrators, finishers that flush state, and the rules for hand-written Gatherer classes.