Java ThreadLocal: When and How to Use It (With Examples)
Learn when to use Java ThreadLocal, why it leaks in thread pools, how remove() in finally fixes it, and when Java 25 ScopedValue is the better choice.
“Core Java” is Sun’s term, used to refer to Java SE, the standard edition and a set of related technologies, like the Java VM, CORBA, etc. This is mostly to differentiate from others like Java ME or Java EE. “Core Java” is Oracle’s definition and refers to subset of Java SE technologies.
The Core Java technologies and application programming interfaces (APIs) are the foundation of the Java Platform, Standard Edition (Java SE). They are used in all classes of Java programming, from desktop applications to Java EE applications.
Learn when to use Java ThreadLocal, why it leaks in thread pools, how remove() in finally fixes it, and when Java 25 ScopedValue is the better choice.
Use Java UncaughtExceptionHandler to log thread failures, restart threads with a limit, and see why ExecutorService submit() never reaches the handler.
Java servlets tutorial for Jakarta Servlet 6.1 on Tomcat 11 covering the life cycle, URL mapping, requests, responses, filters, listeners and sessions.
Learn PowerMock with JUnit 4 and Mockito for static, final, private and constructor mocks, why it fails on Java 17+, and how Mockito 5 replaces it.
Credit card regex for Java with Visa, Mastercard 2-series, Amex, Discover, Diners and JCB, brand detection with named groups and a Luhn check.
A UK postcode regex for Java that accepts all six Royal Mail formats, a strict variant, input normalization, named groups and the gov.uk regex bug.
Canadian postal code regex for Java that follows the Canada Post letter rules, accepts lowercase and unspaced input, and reads the province.
Validate a US ZIP code regex in Java for 5-digit and ZIP+4 formats, normalize user input, find ZIP codes in text and avoid storing them as numbers.
ISBN regex Java guide for ISBN-10 and ISBN-13, with check digit code, a complete validator, a formatted regex and ISBN-10 to ISBN-13 conversion.
SSN regex for Java that rejects the numbers the SSA never assigns, accepts spaces or no dashes with a backreference, and masks SSNs in logs.
Use a Java regex to limit the number of lines in text with \R and \V, set a minimum and maximum, handle Windows line breaks and text blocks.
Limit the number of words in Java with a bounded regex group, stop slow backtracking with a word boundary, and count words with Unicode-aware rules.
Check regex min and max length in Java with {min,max} and anchors, limit characters too, handle line breaks, lookaheads, emoji and the {,n} trap.
The regex for alphanumeric characters is ^[a-zA-Z0-9]+$. Java examples for length limits, letter plus digit rules, spaces, Unicode letters and cleanup.
Fix IllegalStateException No match found in Java regex by checking matches() or find() before group(), with named group pitfalls and Java 25 examples.
Java date format validation with a regex for the shape and LocalDate with ResolverStyle.STRICT for real dates, with ISO, US and EU formats and traps.
International phone number regex for Java in E.164, E.123 and EPP formats, input normalization, and full validation with libphonenumber.
Validate a US phone number with a Java regex that follows NANP rules and balanced parentheses, then format it with groups or store it as E.164.
Java email validation regex compared from simple to strict, with the HTML5 browser rule, RFC length limits, IDN domains and confirmation emails.
Match Greek characters in a Java regex with \p{IsGreek} for the script or \p{InGreek} and \p{InGreekExtended} for blocks, plus accents and case.
Currency symbol regex for Java with \p{Sc}. Find dollar, euro and rupee signs, extract prices and avoid the two dollar sign traps in Java 25.
Match the trademark symbol U+2122 in a Java regex with \u2122, capture brand names, handle (R) and (C) signs, and convert (TM) and HTML entities.
Match an exact word in Java with \bword\b and find(), find words that contain text, match any or all words, ignore case and quote user input safely.
Learn how the regex word boundary \b works in Java, find words that start or end with given letters, match whole words and avoid common mistakes.
Write a regex for misspelled words in Java with character classes, optional letters and alternation, then find and fix every spelling in one pass.
Create a temp file or folder in Java with Files.createTempFile() and Files.createTempDirectory(). See how the older File.createTempFile() differs, and delete temp files safely with finally, DELETE_ON_CLOSE, deleteOnExit() or JUnit @TempDir.
Java check if file exists with Files.exists(), notExists(), isRegularFile() and isDirectory(), plus symbolic links, the unknown case and the TOCTOU race.
Read file to byte array in Java with Files.readAllBytes, readNBytes for headers, chunked reading for large files, classpath resources and Commons IO.
Read and write UTF-8 files in Java with Files.readString, writeString and readers, the Java 18 UTF-8 default, MalformedInputException and the BOM.
The Java memory model on JDK 25 explained with heap generations, thread stacks, metaspace and code cache, plus their flags, defaults and errors.
OpenCSV 5.12 examples to read and write CSV files in Java as arrays, maps and beans, with quoting, appending, bad rows and large files explained.
Build the HiLo guessing game in Java with RandomGenerator, safe console input and a binary search solver that proves why seven tries are always enough.
Learn to read a properties file in Java with load(), write it with store(), load from the classpath, use defaults, update safely and handle UTF-8.
Read input from console in Java with Scanner, Java 25 IO.readln(), BufferedReader and Console, fix the nextLine() skip and validate numbers safely.
Java FileFilter examples with lambdas and listFiles(), filters by size, date and hidden flag, null-safe listing and the NIO DirectoryStream.Filter option.
Read an XML file in Java with the DOM parser. Get elements, attributes and nested nodes into records, use XPath, block XXE, and compare SAX and StAX.
DOM vs SAX parser in Java with code for each, plus StAX, a comparison of memory, speed and features, a decision guide and secure XXE settings.
Read and write PDF in Java with iText 9 (text, tables, images, passwords, stamping), the AGPL license explained, and OpenPDF as an LGPL option.
Format currency in Java with NumberFormat.getCurrencyInstance(), Locale and BigDecimal. Switch currencies, parse amounts safely and control rounding.
Get the current locale in Java with Locale.getDefault(), the FORMAT category, request.getLocale() and LocaleContextHolder, and pass it to formatters.
PECS (Producer Extends, Consumer Super) tells us when to use extends T> and when to use super T> on a generic parameter. Learn the rule with compile errors, a copy() method and the JDK methods that follow it.
Method overloading vs overriding in Java with rules, overload resolution, @Override, covariant returns and the traps that come up in interviews.
Learn the Java transient keyword with serialization examples, restoring fields in readObject(), static and final transient fields, Jackson, Gson and JPA.
Java generics tutorial for Java 25 with generic classes, records, methods, bounded types, wildcards, type erasure and the restrictions with workarounds.
Compare and swap (CAS) writes a new value only if a variable still holds the value we read. Learn compareAndSet(), CAS loops, VarHandle and the ABA problem in Java 25.
Java reflection examples from real frameworks, with a test runner, CSV export, DI container, plugin loader, dynamic proxy and the Java 17+ module rules.
Java annotations tutorial with built-in and meta-annotations, retention, a custom annotation validator, reading annotations by reflection and processors.
Java Optional guide with examples of of, ofNullable, map, flatMap, orElseThrow, isEmpty, stream and or, plus where not to use Optional.
Convert hex to ASCII in Java and back with HexFormat or a loop, avoid the missing leading zero bug, validate input and handle UTF-8 text.
Learn to split a string in Java with split(), Pattern, splitAsStream(), Java 21 splitWithDelimiters(), lines(), Scanner and StringTokenizer.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.